from otree.api import * doc = """ Your app description """ class C(BaseConstants): NAME_IN_URL = 'welcome' PLAYERS_PER_GROUP = None NUM_ROUNDS = 1 class Subsession(BaseSubsession): pass def creating_session(subsession): import itertools treatments = itertools.cycle( itertools.product([17 , 14 , 1 , 6 , 26 , 12 , 27 , 30 , 3 , 2 , 9 , 10 , 22 , 19 , 4 , 16 , 20 , 28 , 13 , 18 , 8 , 21 , 7 , 32 , 29 , 23 , 11 , 25 , 31 , 5 , 15 , 24 , ]) ) for player in subsession.get_players(): treatment = next(treatments) # print('treatment is', treatment) player.treat = treatment[0] class Group(BaseGroup): pass class Player(BasePlayer): treat = models.IntegerField() # is_mobile = models.BooleanField() # prolific_id = models.StringField(label="Your Prolific ID:") q1 = models.IntegerField( choices=[ [1, 'One'], [2, 'Two '], [3, 'Three'], ], label="1. The experiment contains 3 tasks. ___ task(s) will be randomly selected to determine my payment.", widget=widgets.RadioSelect, ) q2 = models.BooleanField( label="2. My performance and decisions in the survey will also determine my payment.", widget=widgets.RadioSelect ) q3 = models.BooleanField( label="3. I will receive the payment in the task and survey respectively.", widget=widgets.RadioSelect ) num_failed_attempts = models.IntegerField(initial=0) failed_too_many = models.BooleanField(initial=False) class welcome(Page): form_model = 'player' # form_fields = ['is_mobile','prolific_id'] form_fields = ['q1','q2','q3'] @staticmethod def error_message(player: Player, values): #if values['is_mobile']: # return "Sorry, this experiment does not allow mobile browsers." solutions = dict(q1=1, q2=True, q3=False) # error_message can return a dict whose keys are field names and whose # values are error messages errors = {name: 'Wrong' for name in solutions if values[name] != solutions[name]} print('errors is', errors) if errors: player.num_failed_attempts += 1 if player.num_failed_attempts >= 3: player.failed_too_many = True # we don't return any error here; just let the user proceed to the # next page, but the next page is the 'failed' page that boots them # from the experiment. else: return 'Wrong answer. Please read the Instructions and answer the understanding questions again.' class Failed(Page): @staticmethod def is_displayed(player: Player): return player.failed_too_many class Results(Page): pass #@staticmethod #def app_after_this_page(player, upcoming_apps): # print('upcoming_apps is', upcoming_apps) # if player.treat <=16: # return "Task1" # else: # return "Task2" page_sequence = [welcome,Failed,Results]