import random from otree.api import * doc = """ Your app description """ class C(BaseConstants): NAME_IN_URL = 'Task1' PLAYERS_PER_GROUP = None TASKS = ['10u', '10d', '11u', '11d','12u', '12d','13u', '13d','14u', '14d','15u', '15d','16u', '16d','17u', '17d','18u', '18d','19u', '19d'] NUM_ROUNDS = len(TASKS) TIMER_TEXT = " " class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): treat = models.IntegerField() task1_q1 = models.BooleanField( label="1. I need to predict the data in this task.", widget=widgets.RadioSelect ) task1_q2 = models.IntegerField( label="2. I can get $___ for 10 correct predictions. ", ) task1_q3 = models.BooleanField( label="3. I will know the correct number of robot’s predictions at the end of the experiment.", widget=widgets.RadioSelect ) Task1_predict=models.IntegerField(min=0,max=20) treatment_task1=models.IntegerField() # FUNCTIONS def creating_session(subsession: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) player.treat = treatment[0] print('player treat1 is', player.treat) if player.treat<=16 : player.treatment_task1 = 0 else: player.treatment_task1 = 1 participant=player.participant participant.treatment_task1 = player.treatment_task1 if subsession.round_number == 1: for p in subsession.get_players(): round_numbers = list(range(1, C.NUM_ROUNDS+1)) random.shuffle(round_numbers) task_rounds = dict(zip(C.TASKS, round_numbers)) print('player', p.id_in_subsession) print('task_rounds is', task_rounds) p.participant.task_rounds = task_rounds def get_timeout_seconds1(player: Player): participant = player.participant import time return participant.expiry - time.time() #def is_displayed1(player: Player): # """only returns True if there is time left.""" # return get_timeout_seconds1(player) > 0 class Instructions(Page): form_model = 'player' form_fields = ['task1_q1', 'task1_q2', 'task1_q3'] @staticmethod def error_message(player: Player, values): if player.treat<=16: solutions = dict(task1_q1=False, task1_q2=1, task1_q3=True) else: solutions = dict(task1_q1=False, task1_q2=1, task1_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: return 'Wrong answer. Please read the Instructions and answer the understanding questions again.' @staticmethod def is_displayed(player: Player): return player.round_number == 1 @staticmethod def before_next_page(player: Player, timeout_happened): participant = player.participant import time participant.expiry = time.time() + 60*5 class Task10u(Page): get_timeout_seconds = get_timeout_seconds1 timer_text = C.TIMER_TEXT @staticmethod def is_displayed(player: Player): participant = player.participant return player.round_number == participant.task_rounds['10u'] and get_timeout_seconds1(player) > 0 @staticmethod def vars_for_template(player): a = player.round_number return dict( a=a, ) class Task10d(Page): get_timeout_seconds = get_timeout_seconds1 timer_text = C.TIMER_TEXT @staticmethod def is_displayed(player: Player): participant = player.participant return player.round_number == participant.task_rounds['10d']and get_timeout_seconds1(player) > 0 @staticmethod def vars_for_template(player): a = player.round_number return dict( a=a, ) class Task11u(Page): get_timeout_seconds = get_timeout_seconds1 timer_text = C.TIMER_TEXT @staticmethod def is_displayed(player: Player): participant = player.participant return player.round_number == participant.task_rounds['11u']and get_timeout_seconds1(player) > 0 @staticmethod def vars_for_template(player): a = player.round_number return dict( a=a, ) class Task11d(Page): get_timeout_seconds = get_timeout_seconds1 timer_text = C.TIMER_TEXT @staticmethod def is_displayed(player: Player): participant = player.participant return player.round_number == participant.task_rounds['11d']and get_timeout_seconds1(player) > 0 @staticmethod def vars_for_template(player): a = player.round_number return dict( a=a, ) class Task12u(Page): get_timeout_seconds = get_timeout_seconds1 timer_text = C.TIMER_TEXT @staticmethod def is_displayed(player: Player): participant = player.participant return player.round_number == participant.task_rounds['12u']and get_timeout_seconds1(player) > 0 @staticmethod def vars_for_template(player): a = player.round_number return dict( a=a, ) class Task12d(Page): get_timeout_seconds = get_timeout_seconds1 timer_text = C.TIMER_TEXT @staticmethod def is_displayed(player: Player): participant = player.participant return player.round_number == participant.task_rounds['12d']and get_timeout_seconds1(player) > 0 @staticmethod def vars_for_template(player): a = player.round_number return dict( a=a, ) class Task13u(Page): get_timeout_seconds = get_timeout_seconds1 timer_text = C.TIMER_TEXT @staticmethod def is_displayed(player: Player): participant = player.participant return player.round_number == participant.task_rounds['13u']and get_timeout_seconds1(player) > 0 @staticmethod def vars_for_template(player): a = player.round_number return dict( a=a, ) class Task13d(Page): get_timeout_seconds = get_timeout_seconds1 timer_text = C.TIMER_TEXT @staticmethod def is_displayed(player: Player): participant = player.participant return player.round_number == participant.task_rounds['13d']and get_timeout_seconds1(player) > 0 @staticmethod def vars_for_template(player): a = player.round_number return dict( a=a, ) class Task14u(Page): get_timeout_seconds = get_timeout_seconds1 timer_text = C.TIMER_TEXT @staticmethod def is_displayed(player: Player): participant = player.participant return player.round_number == participant.task_rounds['14u']and get_timeout_seconds1(player) > 0 @staticmethod def vars_for_template(player): a = player.round_number return dict( a=a, ) class Task14d(Page): get_timeout_seconds = get_timeout_seconds1 timer_text = C.TIMER_TEXT @staticmethod def is_displayed(player: Player): participant = player.participant return player.round_number == participant.task_rounds['14d']and get_timeout_seconds1(player) > 0 @staticmethod def vars_for_template(player): a = player.round_number return dict( a=a, ) class Task15u(Page): get_timeout_seconds = get_timeout_seconds1 timer_text = C.TIMER_TEXT @staticmethod def is_displayed(player: Player): participant = player.participant return player.round_number == participant.task_rounds['15u']and get_timeout_seconds1(player) > 0 @staticmethod def vars_for_template(player): a = player.round_number return dict( a=a, ) class Task15d(Page): get_timeout_seconds = get_timeout_seconds1 timer_text = C.TIMER_TEXT @staticmethod def is_displayed(player: Player): participant = player.participant return player.round_number == participant.task_rounds['15d']and get_timeout_seconds1(player) > 0 @staticmethod def vars_for_template(player): a = player.round_number return dict( a=a, ) class Task16u(Page): get_timeout_seconds = get_timeout_seconds1 timer_text = C.TIMER_TEXT @staticmethod def is_displayed(player: Player): participant = player.participant return player.round_number == participant.task_rounds['16u']and get_timeout_seconds1(player) > 0 @staticmethod def vars_for_template(player): a = player.round_number return dict( a=a, ) class Task16d(Page): get_timeout_seconds = get_timeout_seconds1 timer_text = C.TIMER_TEXT @staticmethod def is_displayed(player: Player): participant = player.participant return player.round_number == participant.task_rounds['16d']and get_timeout_seconds1(player) > 0 @staticmethod def vars_for_template(player): a = player.round_number return dict( a=a, ) class Task17u(Page): get_timeout_seconds = get_timeout_seconds1 timer_text = C.TIMER_TEXT @staticmethod def is_displayed(player: Player): participant = player.participant return player.round_number == participant.task_rounds['17u']and get_timeout_seconds1(player) > 0 @staticmethod def vars_for_template(player): a = player.round_number return dict( a=a, ) class Task17d(Page): get_timeout_seconds = get_timeout_seconds1 timer_text = C.TIMER_TEXT @staticmethod def is_displayed(player: Player): participant = player.participant return player.round_number == participant.task_rounds['17d']and get_timeout_seconds1(player) > 0 @staticmethod def vars_for_template(player): a = player.round_number return dict( a=a, ) class Task18u(Page): get_timeout_seconds = get_timeout_seconds1 timer_text = C.TIMER_TEXT @staticmethod def is_displayed(player: Player): participant = player.participant return player.round_number == participant.task_rounds['18u']and get_timeout_seconds1(player) > 0 @staticmethod def vars_for_template(player): a = player.round_number return dict( a=a, ) class Task18d(Page): get_timeout_seconds = get_timeout_seconds1 timer_text = C.TIMER_TEXT @staticmethod def is_displayed(player: Player): participant = player.participant return player.round_number == participant.task_rounds['18d']and get_timeout_seconds1(player) > 0 @staticmethod def vars_for_template(player): a = player.round_number return dict( a=a, ) class Task19u(Page): get_timeout_seconds = get_timeout_seconds1 timer_text = C.TIMER_TEXT @staticmethod def is_displayed(player: Player): participant = player.participant return player.round_number == participant.task_rounds['19u']and get_timeout_seconds1(player) > 0 @staticmethod def vars_for_template(player): a = player.round_number return dict( a=a, ) class Task19d(Page): get_timeout_seconds = get_timeout_seconds1 timer_text = C.TIMER_TEXT @staticmethod def is_displayed(player: Player): participant = player.participant return player.round_number == participant.task_rounds['19d']and get_timeout_seconds1(player) > 0 @staticmethod def vars_for_template(player): a = player.round_number return dict( a=a, ) class Task1_predict(Page): form_model = 'player' form_fields = ['Task1_predict'] @staticmethod def is_displayed(player: Player): return player.round_number == 20 @staticmethod def app_after_this_page(player, upcoming_apps): print('upcoming_apps is', upcoming_apps) return "Task2" # @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 = [Instructions,Task10u,Task10d,Task11u,Task11d,Task12u,Task12d,Task13u,Task13d,Task14u,Task14d,Task15u,Task15d,Task16u,Task16d,Task17u,Task17d,Task18u,Task18d,Task19u,Task19d,Task1_predict] #page_sequence = [verbalInstructions, verbal_prac_instructions, verbal_prac, verbal_pr_instructions, verbal_pr_predict, verbal_pr, verbal_t_instructions,verbal_t_predict, verbal_t,verbal_choice, # mathInstructions, math_prac_instructions, math_prac, math_pr_instructions,math_pr_predict, # math_pr, math_t_instructions, math_t_predict, math_t, final_predict, math_choice, Investment_Choice, survey1, survey2, survey3, Results] # page_sequence = [survey4, survey4_result]