from otree.api import * c = cu doc = 'Mixed Grouping room for 3 Players' class Constants(BaseConstants): name_in_url = 'GroupingRoomMix_3P' players_per_group = 3 num_rounds = 1 class Subsession(BaseSubsession): pass def acquire_partyid(group): for p in group.get_players(): p.partyid = p.participant.vars['partyid'] class Group(BaseGroup): acquire_partyid = acquire_partyid class Player(BasePlayer): consent = models.BooleanField(choices=[[True, 'Yes'], [False, 'No']], label='I have read and understand the explanations. I am over 18 years of age, and I agree to participate in this study.', widget=widgets.RadioSelect) partyid = models.StringField() class GroupingPage(WaitPage): group_by_arrival_time = True title_text = 'Waiting Room' body_text = "Please just hang tight, we're waiting for other players to join the game. Don't close this browser as you might have issues rejoining. Grouping typically takes a few minutes, anything longer than this is likely off-peak times." class Obtaining_Parties(WaitPage): after_all_players_arrive = 'acquire_partyid' body_text = 'Acquiring Answers to Party Question' class AppSelection(Page): form_model = 'player' timeout_seconds = 60 @staticmethod def vars_for_template(player): group = player.group d = 0 r = 0 for p in player.get_others_in_group(): if p.partyid == "Democrat": d += 1 else: r += 1 return dict(dems = d, reps = r) @staticmethod def app_after_this_page(player, upcoming_apps): session = player.session subsession = player.subsession group = player.group numid = group.id_in_subsession while(numid > 2): numid -= 2 if(numid == 1): nextapp = upcoming_apps[0] elif(numid == 2): nextapp = upcoming_apps[1] return (nextapp) page_sequence = [GroupingPage, Obtaining_Parties, AppSelection]