from otree.api import * doc = """ Your app description """ def timer(player, seconds): """Return seconds if timers are enabled, else None.""" return seconds if player.session.config.get('enable_timers', False) else None class C(BaseConstants): NAME_IN_URL = 'Instructions' PLAYERS_PER_GROUP = None NUM_ROUNDS = 1 TREATMENT_AI_AGENT = "AI Agent" TREATMENT_AI_DELEGATION = "AI Delegation" # correct options (the values of the radio choices) Q1_CORRECT = 120 # round length is 120 seconds Q2_CORRECT = 10 # agreement holds for 10 seconds class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): prolificID = models.StringField() # two multiple choice questions q1 = models.IntegerField( label="How many seconds does a round last at most?", choices=[ [60, "60 seconds"], [90, "90 seconds"], [120, "120 seconds"], ], widget=widgets.RadioSelect, ) q2 = models.IntegerField( label="For how long must an agreement hold to finalize?", choices=[ [5, "5 seconds"], [10, "10 seconds"], [20, "20 seconds"], ], widget=widgets.RadioSelect, ) fail_count = models.IntegerField(initial=0) # PAGES class Instructions(Page): form_model = "player" form_fields = ['q1', 'q2', 'fail_count'] @staticmethod def vars_for_template(player: Player): factor = player.session.config.get("points_to_gbp") delegation = player.participant.vars.get('delegation') return dict( factor=factor, delegationh=delegation, is_ai_agent=(delegation == C.TREATMENT_AI_AGENT), is_ai_delegation=(delegation == C.TREATMENT_AI_DELEGATION), ) @staticmethod def get_timeout_seconds(player): return timer(player, 600) @staticmethod def before_next_page(player, timeout_happened): import time player.participant.wait_page_arrival = time.time() # kick out after 2 failed attempts if (player.fail_count or 0) >= 2: player.participant.dropout = True if timeout_happened: player.participant.dropout = True @staticmethod def app_after_this_page(player, timeout_happened): if player.participant.dropout: return "End_Page" # All the pages of this app page_sequence = [Instructions]