from otree.api import * c = cu doc = '\nStart' class C(BaseConstants): NAME_IN_URL = 'start' PLAYERS_PER_GROUP = 4 NUM_ROUNDS = 1 class Subsession(BaseSubsession): def group_by_arrival_time_method(subsession, waiting_players): session = subsession.session for p in waiting_players: player_id = int(p.id_in_subsession) session.ids_ready.add(player_id) if len(session.ids_ready) >= 4: all_players = subsession.get_players() players_ready = [p for p in all_players if p.id_in_subsession in session.ids_ready] # the participants with the lowest 3 IDs will get grouped, so they have to be removed from the set ids_finished ids_grouped = sorted(session.ids_ready)[:4] session.ids_ready.difference_update(ids_grouped) return[players_ready[0], players_ready[1], players_ready[2], players_ready[3]] def creating_session(subsession: Subsession): session = subsession.session session.ids_ready = set() class Group(BaseGroup): pass class Player(BasePlayer): pass class GroupWaitPage(WaitPage): group_by_arrival_time = True class Start(Page): @staticmethod def vars_for_template(player: Player): return dict( roomnr = player.group.id_in_subsession, label = player.participant.label ) page_sequence = [GroupWaitPage, Start]