import random from otree.api import * doc = """ treatment2_DBM """ class C(BaseConstants): NAME_IN_URL = 'treatment2_DBM' PLAYERS_PER_GROUP = None TASKS = ['inflation', 'income', 'Bayesian', 'quantity', 'unemployment'] NUM_ROUNDS = len(TASKS) DBM100 = __name__ + '/DBM100.html' BONUS = 3 economics = [ dict(name='Inflation', label="U.S. inflation rate"), dict(name='Unemployment', label="U.S. unemployment rate"), dict(name='Income', label="Income of 30-year-old and full time workers"), dict(name='Edu', label="Educational attainment"), dict(name='No', label="None of above"), ] class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): # record the submission for each task num_failed_attempts = models.FloatField(initial=0) failed_more_than1 = models.BooleanField(initial=False) # How is your bonus determined when you are selected to get paid based on your guess? Ans: 2 CC_Q1 = models.IntegerField( label='', choices=[ [1, 'There are 5 tasks in total, and my submitted guess in every one of them will get paid. Thus, I can strategize across tasks to hedge.'], [2, 'There are 5 tasks in total. The computer will randomly select one of them, and my bonus will depend on my submitted guess to this one task. Thus, there is no point for me in strategizing across tasks.'], ], widget=widgets.RadioSelect ) # What would happen if you choose one range of numbers? Ans: 1 CC_Q2 = models.IntegerField( label='', choices=[ [1, 'The computer will further zoom in the range you chose and ask you to refine your guess by choosing between two narrower ranges of numbers with an “EXIT” button'], [2, 'The computer will submit the range for me as my guess to that question.'] ], widget=widgets.RadioSelect ) # What would happen if you click on the "EXIT" button? Ans: 1 CC_Q3 = models.IntegerField( label='', choices=[ [1, 'The computer will randomly choose a number from the last range I chose (or the entire range if I never chose any range) and submit it as my guess in this task for me.'], [2, 'The computer will always choose the midpoint of the last range I chose (or of the entire range if I never chose any range) and submit it as my guess in this task for me.'] ], widget=widgets.RadioSelect ) # Vincent Ans: 5 CC_Q4 = models.IntegerField( label='', choices=[ [1, 'Randomly select a number to submit'], [2, 'Always submit 0'], [3, 'Always submit the number in the middle of the slider bar'], [4, 'Always submit the maximum number of the slider bar'], [5, 'Submit the best guess he can make, i.e., exiting with the range between 94 and 100.'], ], widget=widgets.RadioSelect ) # Familiar with statistics statistics = models.IntegerField( label='', choices=[ [1, 'Yes'], [2, 'No'] ], widget=widgets.RadioSelect ) # Familiar with economic variables # Familiar with economic variables Inflation = models.BooleanField(blank=True) Unemployment = models.BooleanField(blank=True) Income = models.BooleanField(blank=True) Edu = models.BooleanField(blank=True) No = models.BooleanField(blank=True) feedbackIR = models.LongStringField( blank=True, label='' ) feedbackBB = models.LongStringField( blank=True, label='' ) complexity = models.LongStringField( blank=True, label='' ) comments = models.LongStringField( blank=True, label='' ) # DBM Practice CC_Q5L = models.IntegerField() CC_Q5R = models.IntegerField() # record the decision making process Task1list = models.LongStringField() Task2list = models.LongStringField() Task3list = models.LongStringField() Task4list = models.LongStringField() Task5list = models.LongStringField() # record final submission for each task Task1_left_b = models.IntegerField() Task1_right_b = models.IntegerField() Task2_left_b = models.IntegerField() Task2_right_b = models.IntegerField() Task3_left_b = models.IntegerField() Task3_right_b = models.IntegerField() Task4_left_b = models.IntegerField() Task4_right_b = models.IntegerField() Task5_left_b = models.IntegerField() Task5_right_b = models.IntegerField() # record the random draw number as the answer for each task DBM_Task1 = models.IntegerField() DBM_Task2 = models.IntegerField() DBM_Task3 = models.IntegerField() DBM_Task4 = models.IntegerField() DBM_Task5 = models.IntegerField() # record the order of each task Task1_order = models.IntegerField() Task2_order = models.IntegerField() Task3_order = models.IntegerField() Task4_order = models.IntegerField() Task5_order = models.IntegerField() # record the parameter for each task inflation_index = models.IntegerField() income_index = models.IntegerField() Bayesian_index = models.IntegerField() quantity_index = models.IntegerField() unemployment_index = models.IntegerField() # record the correct answer for each task Task1_answer = models.IntegerField() Task2_answer = models.IntegerField() Task3_answer = models.IntegerField() Task4_answer = models.IntegerField() Task5_answer = models.IntegerField() # 1 for inflation rate # 2 for income # 3 for Bayesian # 4 for quantity # 5 for unemployment # FUNCTIONS # creating session gets executed for each round independently def creating_session(subsession: Subsession): # set the payoff round if subsession.round_number == 1: subsession.session.payoff_round = random.randint(1, 5) # random draw a number between 1 and 5 as the payment round print('payoff_round (in treatment2 round 1):', subsession.session.payoff_round) # randomize the order of tasks for p in subsession.get_players(): round_numbers = list(range(1, C.NUM_ROUNDS+1)) random.shuffle(round_numbers) print('task_number for treatment2:', round_numbers) task_rounds = dict(zip(C.TASKS, round_numbers)) p.participant.task_rounds_treatment2 = task_rounds print('inflation order:', p.participant.task_rounds_treatment2['inflation']) print('income order:', p.participant.task_rounds_treatment2['income']) print('Bayesian order:', p.participant.task_rounds_treatment2['Bayesian']) print('quantity order:', p.participant.task_rounds_treatment2['quantity']) print('unemployment order:', p.participant.task_rounds_treatment2['unemployment']) # PAGES class Intro1(Page): @staticmethod def is_displayed(player: Player): return player.round_number == player.participant.task_rounds_treatment2['inflation'] @staticmethod def before_next_page(player, timeout_happened): player.inflation_index = random.randint(1, 3) # random draw a number between 1 and 3 to determine the parameter print("Inflation parameter:", player.inflation_index) print("round number:", player.round_number) print("task_rounds_treatment2[inflation]:", player.participant.task_rounds_treatment2['inflation']) class Inflation1(Page): form_model = 'player' form_fields = ['Task1_left_b', 'Task1_right_b', 'Task1list'] @staticmethod def is_displayed(player: Player): return player.round_number == player.participant.task_rounds_treatment2['inflation'] and player.inflation_index == 1 @staticmethod def before_next_page(player, timeout_happened): # determine the result for payoff calculation result = random.randint(player.Task1_left_b, player.Task1_right_b) player.DBM_Task1 = result if player.session.payoff_round == player.round_number: # determine the result for payoff calculation result = player.DBM_Task1 print("Task1 result:", result) # the Bayesian answer Bayesian = 56 # the truth is either above the Bayesian or below the Bayesian truth = 0 # if below and equal to the Bayesian # determine the truth num0 = random.randint(1, 100) print("Task1 num0:", num0) if num0 > Bayesian: truth = 1 print("Task1 truth:", truth) # determine the payoff based on the truth num1 = random.randint(0, 100) num2 = random.randint(0, 100) print("Task1 num1:", num1) print("Task1 num2:", num2) if truth == 0: if result > num1 or result > num2: player.payoff = C.BONUS else: player.payoff = 0 if truth == 1: if result < num1 or result < num2: player.payoff = C.BONUS else: player.payoff = 0 print("Task1 payoff:", player.payoff) # save the parameters player.Task1_answer = 56 player.Task1_order = player.round_number class Inflation2(Page): form_model = 'player' form_fields = ['Task1_left_b', 'Task1_right_b', 'Task1list'] @staticmethod def is_displayed(player: Player): return player.round_number == player.participant.task_rounds_treatment2['inflation'] and player.inflation_index == 2 @staticmethod def before_next_page(player, timeout_happened): # determine the result for payoff calculation result = random.randint(player.Task1_left_b, player.Task1_right_b) player.DBM_Task1 = result if player.session.payoff_round == player.round_number: # determine the result for payoff calculation result = player.DBM_Task1 print("Task1 result:", result) # the Bayesian answer Bayesian = 77 # the truth is either above the Bayesian or below the Bayesian truth = 0 # if below and equal to the Bayesian # determine the truth num0 = random.randint(1, 100) print("Task1 num0:", num0) if num0 > Bayesian: truth = 1 print("Task1 truth:", truth) # determine the payoff based on the truth num1 = random.randint(0, 100) num2 = random.randint(0, 100) print("Task1 num1:", num1) print("Task1 num2:", num2) if truth == 0: if result > num1 or result > num2: player.payoff = C.BONUS else: player.payoff = 0 if truth == 1: if result < num1 or result < num2: player.payoff = C.BONUS else: player.payoff = 0 print("Task1 payoff:", player.payoff) # save the parameters player.Task1_answer = 77 player.Task1_order = player.round_number class Inflation3(Page): form_model = 'player' form_fields = ['Task1_left_b', 'Task1_right_b', 'Task1list'] @staticmethod def is_displayed(player: Player): return player.round_number == player.participant.task_rounds_treatment2['inflation'] and player.inflation_index == 3 @staticmethod def before_next_page(player, timeout_happened): # determine the result for payoff calculation result = random.randint(player.Task1_left_b, player.Task1_right_b) player.DBM_Task1 = result if player.session.payoff_round == player.round_number: # determine the result for payoff calculation result = player.DBM_Task1 print("Task1 result:", result) # the Bayesian answer Bayesian = 92 # the truth is either above the Bayesian or below the Bayesian truth = 0 # if below and equal to the Bayesian # determine the truth num0 = random.randint(1, 100) print("Task1 num0:", num0) if num0 > Bayesian: truth = 1 print("Task1 truth:", truth) # determine the payoff based on the truth num1 = random.randint(0, 100) num2 = random.randint(0, 100) print("Task1 num1:", num1) print("Task1 num2:", num2) if truth == 0: if result > num1 or result > num2: player.payoff = C.BONUS else: player.payoff = 0 if truth == 1: if result < num1 or result < num2: player.payoff = C.BONUS else: player.payoff = 0 print("Task1 payoff:", player.payoff) # save the parameters player.Task1_answer = 92 player.Task1_order = player.round_number class Intro2(Page): @staticmethod def is_displayed(player: Player): return player.round_number == player.participant.task_rounds_treatment2['income'] @staticmethod def before_next_page(player, timeout_happened): player.income_index = random.randint(1, 3) # random draw a number between 1 and 3 to determine the parameter print("Income parameter:", player.income_index) print("round number:", player.round_number) print("task_rounds_treatment2[income]:", player.participant.task_rounds_treatment2['income']) class Income1(Page): form_model = 'player' form_fields = ['Task2_left_b', 'Task2_right_b', 'Task2list'] @staticmethod def is_displayed(player: Player): return player.round_number == player.participant.task_rounds_treatment2['income'] and player.income_index == 1 @staticmethod def before_next_page(player, timeout_happened): # determine the result for payoff calculation result = random.randint(player.Task2_left_b, player.Task2_right_b) player.DBM_Task2 = result if player.session.payoff_round == player.round_number: # determine the result for payoff calculation result = player.DBM_Task2 print("Task2 result:", result) # the Bayesian answer Bayesian = 7 # the truth is either above the Bayesian or below the Bayesian truth = 0 # if below and equal to the Bayesian # determine the truth num0 = random.randint(1, 100) print("Task2 num0:", num0) if num0 > Bayesian: truth = 1 print("Task2 truth:", truth) # determine the payoff based on the truth num1 = random.randint(0, 100) num2 = random.randint(0, 100) print("Task2 num1:", num1) print("Task2 num2:", num2) if truth == 0: if result > num1 or result > num2: player.payoff = C.BONUS else: player.payoff = 0 if truth == 1: if result < num1 or result < num2: player.payoff = C.BONUS else: player.payoff = 0 print("Task2 payoff:", player.payoff) # save parameters player.Task2_answer = 7 player.Task2_order = player.round_number class Income2(Page): form_model = 'player' form_fields = ['Task2_left_b', 'Task2_right_b', 'Task2list'] @staticmethod def is_displayed(player: Player): return player.round_number == player.participant.task_rounds_treatment2['income'] and player.income_index == 2 @staticmethod def before_next_page(player, timeout_happened): # determine the result for payoff calculation result = random.randint(player.Task2_left_b, player.Task2_right_b) player.DBM_Task2 = result if player.session.payoff_round == player.round_number: # determine the result for payoff calculation result = player.DBM_Task2 print("Task2 result:", result) # the Bayesian answer Bayesian = 30 # the truth is either above the Bayesian or below the Bayesian truth = 0 # if below and equal to the Bayesian # determine the truth num0 = random.randint(1, 100) print("Task2 num0:", num0) if num0 > Bayesian: truth = 1 print("Task2 truth:", truth) # determine the payoff based on the truth num1 = random.randint(0, 100) num2 = random.randint(0, 100) print("Task2 num1:", num1) print("Task2 num2:", num2) if truth == 0: if result > num1 or result > num2: player.payoff = C.BONUS else: player.payoff = 0 if truth == 1: if result < num1 or result < num2: player.payoff = C.BONUS else: player.payoff = 0 print("Task2 payoff:", player.payoff) # save parameters player.Task2_answer = 30 player.Task2_order = player.round_number class Income3(Page): form_model = 'player' form_fields = ['Task2_left_b', 'Task2_right_b', 'Task2list'] @staticmethod def is_displayed(player: Player): return player.round_number == player.participant.task_rounds_treatment2['income'] and player.income_index == 3 @staticmethod def before_next_page(player, timeout_happened): # determine the result for payoff calculation result = random.randint(player.Task2_left_b, player.Task2_right_b) player.DBM_Task2 = result if player.session.payoff_round == player.round_number: # determine the result for payoff calculation result = player.DBM_Task2 print("Task2 result:", result) # the Bayesian answer Bayesian = 45 # the truth is either above the Bayesian or below the Bayesian truth = 0 # if below and equal to the Bayesian # determine the truth num0 = random.randint(1, 100) print("Task2 num0:", num0) if num0 > Bayesian: truth = 1 print("Task2 truth:", truth) # determine the payoff based on the truth num1 = random.randint(0, 100) num2 = random.randint(0, 100) print("Task2 num1:", num1) print("Task2 num2:", num2) if truth == 0: if result > num1 or result > num2: player.payoff = C.BONUS else: player.payoff = 0 if truth == 1: if result < num1 or result < num2: player.payoff = C.BONUS else: player.payoff = 0 print("Task2 payoff:", player.payoff) # save parameters player.Task2_answer = 45 player.Task2_order = player.round_number class Intro3(Page): @staticmethod def is_displayed(player: Player): return player.round_number == player.participant.task_rounds_treatment2['Bayesian'] @staticmethod def before_next_page(player, timeout_happened): player.Bayesian_index = random.randint(1, 3) # random draw a number between 1 and 3 to determine the parameter print("Bayesian parameter:", player.Bayesian_index) print("round number:", player.round_number) print("task_rounds_treatment1[Bayesian]:", player.participant.task_rounds_treatment2['Bayesian']) class Bayesian1(Page): form_model = 'player' form_fields = ['Task3_left_b', 'Task3_right_b', 'Task3list'] @staticmethod def is_displayed(player: Player): return player.round_number == player.participant.task_rounds_treatment2['Bayesian'] and player.Bayesian_index == 1 @staticmethod def before_next_page(player, timeout_happened): # determine the result for payoff calculation result = random.randint(player.Task3_left_b, player.Task3_right_b) player.DBM_Task3 = result if player.session.payoff_round == player.round_number: # determine the result for payoff calculation result = player.DBM_Task3 print("Task3 result:", result) # the Bayesian answer Bayesian = 6 # the truth is either above the Bayesian or below the Bayesian truth = 0 # if below and equal to the Bayesian # determine the truth num0 = random.randint(1, 100) print("Task3 num0:", num0) if num0 > Bayesian: truth = 1 print("Task3 truth:", truth) # determine the payoff based on the truth num1 = random.randint(0, 100) num2 = random.randint(0, 100) print("Task3 num1:", num1) print("Task3 num2:", num2) if truth == 0: if result > num1 or result > num2: player.payoff = C.BONUS else: player.payoff = 0 if truth == 1: if result < num1 or result < num2: player.payoff = C.BONUS else: player.payoff = 0 print("Task3 payoff:", player.payoff) # save parameters player.Task3_answer = 6 player.Task3_order = player.round_number class Bayesian2(Page): form_model = 'player' form_fields = ['Task3_left_b', 'Task3_right_b', 'Task3list'] @staticmethod def is_displayed(player: Player): return player.round_number == player.participant.task_rounds_treatment2['Bayesian'] and player.Bayesian_index == 2 @staticmethod def before_next_page(player, timeout_happened): # determine the result for payoff calculation result = random.randint(player.Task3_left_b, player.Task3_right_b) player.DBM_Task3 = result if player.session.payoff_round == player.round_number: # determine the result for payoff calculation result = player.DBM_Task3 print("Task3 result:", result) # the Bayesian answer Bayesian = 47 # the truth is either above the Bayesian or below the Bayesian truth = 0 # if below and equal to the Bayesian # determine the truth num0 = random.randint(1, 100) print("Task3 num0:", num0) if num0 > Bayesian: truth = 1 print("Task3 truth:", truth) # determine the payoff based on the truth num1 = random.randint(0, 100) num2 = random.randint(0, 100) print("Task3 num1:", num1) print("Task3 num2:", num2) if truth == 0: if result > num1 or result > num2: player.payoff = C.BONUS else: player.payoff = 0 if truth == 1: if result < num1 or result < num2: player.payoff = C.BONUS else: player.payoff = 0 print("Task3 payoff:", player.payoff) # save parameters player.Task3_answer = 47 player.Task3_order = player.round_number class Bayesian3(Page): form_model = 'player' form_fields = ['Task3_left_b', 'Task3_right_b', 'Task3list'] @staticmethod def is_displayed(player: Player): return player.round_number == player.participant.task_rounds_treatment2['Bayesian'] and player.Bayesian_index == 3 @staticmethod def before_next_page(player, timeout_happened): # determine the result for payoff calculation result = random.randint(player.Task3_left_b, player.Task3_right_b) player.DBM_Task3 = result if player.session.payoff_round == player.round_number: # determine the result for payoff calculation result = player.DBM_Task3 print("Task3 result:", result) # the Bayesian answer Bayesian = 33 # the truth is either above the Bayesian or below the Bayesian truth = 0 # if below and equal to the Bayesian # determine the truth num0 = random.randint(1, 100) print("Task3 num0:", num0) if num0 > Bayesian: truth = 1 print("Task3 truth:", truth) # determine the payoff based on the truth num1 = random.randint(0, 100) num2 = random.randint(0, 100) print("Task3 num1:", num1) print("Task3 num2:", num2) if truth == 0: if result > num1 or result > num2: player.payoff = C.BONUS else: player.payoff = 0 if truth == 1: if result < num1 or result < num2: player.payoff = C.BONUS else: player.payoff = 0 print("Task3 payoff:", player.payoff) # save parameters player.Task3_answer = 33 player.Task3_order = player.round_number class Intro4(Page): @staticmethod def is_displayed(player: Player): return player.round_number == player.participant.task_rounds_treatment2['quantity'] @staticmethod def before_next_page(player, timeout_happened): player.quantity_index = random.randint(1, 3) # random draw a number between 1 and 3 to determine the parameter print("Quantity parameter:", player.quantity_index) print("round number:", player.round_number) print("task_rounds_treatment2[quantity]:", player.participant.task_rounds_treatment2['quantity']) class Quantity1(Page): form_model = 'player' form_fields = ['Task4_left_b', 'Task4_right_b', 'Task4list'] @staticmethod def is_displayed(player: Player): return player.round_number == player.participant.task_rounds_treatment2['quantity'] and player.quantity_index == 1 @staticmethod def before_next_page(player, timeout_happened): # determine the result for payoff calculation result = random.randint(player.Task4_left_b, player.Task4_right_b) player.DBM_Task4 = result if player.session.payoff_round == player.round_number: # determine the result for payoff calculation result = player.DBM_Task4 print("Task4 result:", result) # the Bayesian answer Bayesian = 3 # the truth is either above the Bayesian or below the Bayesian truth = 0 # if below and equal to the Bayesian # determine the truth num0 = random.randint(1, 100) print("Task4 num0:", num0) if num0 > Bayesian: truth = 1 print("Task4 truth:", truth) # determine the payoff based on the truth num1 = random.randint(0, 100) num2 = random.randint(0, 100) print("Task4 num1:", num1) print("Task4 num2:", num2) if truth == 0: if result > num1 or result > num2: player.payoff = C.BONUS else: player.payoff = 0 if truth == 1: if result < num1 or result < num2: player.payoff = C.BONUS else: player.payoff = 0 print("Task4 payoff:", player.payoff) # save parameters player.Task4_answer = 3 player.Task4_order = player.round_number class Quantity2(Page): form_model = 'player' form_fields = ['Task4_left_b', 'Task4_right_b', 'Task4list'] @staticmethod def is_displayed(player: Player): return player.round_number == player.participant.task_rounds_treatment2['quantity'] and player.quantity_index == 2 @staticmethod def before_next_page(player, timeout_happened): # determine the result for payoff calculation result = random.randint(player.Task4_left_b, player.Task4_right_b) player.DBM_Task4 = result if player.session.payoff_round == player.round_number: # determine the result for payoff calculation result = player.DBM_Task4 print("Task4 result:", result) # the Bayesian answer Bayesian = 12 # the truth is either above the Bayesian or below the Bayesian truth = 0 # if below and equal to the Bayesian # determine the truth num0 = random.randint(1, 100) print("Task4 num0:", num0) if num0 > Bayesian: truth = 1 print("Task4 truth:", truth) # determine the payoff based on the truth num1 = random.randint(0, 100) num2 = random.randint(0, 100) print("Task4 num1:", num1) print("Task4 num2:", num2) if truth == 0: if result > num1 or result > num2: player.payoff = C.BONUS else: player.payoff = 0 if truth == 1: if result < num1 or result < num2: player.payoff = C.BONUS else: player.payoff = 0 print("Task4 payoff:", player.payoff) # save parameters player.Task4_answer = 12 player.Task4_order = player.round_number class Quantity3(Page): form_model = 'player' form_fields = ['Task4_left_b', 'Task4_right_b', 'Task4list'] @staticmethod def is_displayed(player: Player): return player.round_number == player.participant.task_rounds_treatment2['quantity'] and player.quantity_index == 3 @staticmethod def before_next_page(player, timeout_happened): # determine the result for payoff calculation result = random.randint(player.Task4_left_b, player.Task4_right_b) player.DBM_Task4 = result if player.session.payoff_round == player.round_number: # determine the result for payoff calculation result = player.DBM_Task4 print("Task4 result:", result) # the Bayesian answer Bayesian = 49 # the truth is either above the Bayesian or below the Bayesian truth = 0 # if below and equal to the Bayesian # determine the truth num0 = random.randint(1, 100) print("Task4 num0:", num0) if num0 > Bayesian: truth = 1 print("Task4 truth:", truth) # determine the payoff based on the truth num1 = random.randint(0, 100) num2 = random.randint(0, 100) print("Task4 num1:", num1) print("Task4 num2:", num2) if truth == 0: if result > num1 or result > num2: player.payoff = C.BONUS else: player.payoff = 0 if truth == 1: if result < num1 or result < num2: player.payoff = C.BONUS else: player.payoff = 0 print("Task4 payoff:", player.payoff) # save parameters player.Task4_answer = 49 player.Task4_order = player.round_number class Intro5(Page): @staticmethod def is_displayed(player: Player): return player.round_number == player.participant.task_rounds_treatment2['unemployment'] @staticmethod def before_next_page(player, timeout_happened): player.unemployment_index = random.randint(1, 3) # random draw a number between 1 and 3 to determine the parameter print("Unemployment parameter:", player.unemployment_index) print("round number:", player.round_number) print("task_rounds_treatment2[unemployment]:", player.participant.task_rounds_treatment2['unemployment']) class Unemployment1(Page): form_model = 'player' form_fields = ['Task5_left_b', 'Task5_right_b', 'Task5list'] @staticmethod def is_displayed(player: Player): return player.round_number == player.participant.task_rounds_treatment2['unemployment'] and player.unemployment_index == 1 @staticmethod def before_next_page(player, timeout_happened): # determine the result for payoff calculation result = random.randint(player.Task5_left_b, player.Task5_right_b) player.DBM_Task5 = result if player.session.payoff_round == player.round_number: # determine the result for payoff calculation result = player.DBM_Task5 print("Task5 result:", result) # the Bayesian answer Bayesian = 56 # the truth is either above the Bayesian or below the Bayesian truth = 0 # if below and equal to the Bayesian # determine the truth num0 = random.randint(1, 100) print("Task5 num0:", num0) if num0 > Bayesian: truth = 1 print("Task5 truth:", truth) # determine the payoff based on the truth num1 = random.randint(0, 100) num2 = random.randint(0, 100) print("Task5 num1:", num1) print("Task5 num2:", num2) if truth == 0: if result > num1 or result > num2: player.payoff = C.BONUS else: player.payoff = 0 if truth == 1: if result < num1 or result < num2: player.payoff = C.BONUS else: player.payoff = 0 print("Task5 payoff:", player.payoff) # save parameters player.Task5_answer = 56 player.Task5_order = player.round_number class Unemployment2(Page): form_model = 'player' form_fields = ['Task5_left_b', 'Task5_right_b', 'Task5list'] @staticmethod def is_displayed(player: Player): return player.round_number == player.participant.task_rounds_treatment2['unemployment'] and player.unemployment_index == 2 @staticmethod def before_next_page(player, timeout_happened): # determine the result for payoff calculation result = random.randint(player.Task5_left_b, player.Task5_right_b) player.DBM_Task5 = result if player.session.payoff_round == player.round_number: # determine the result for payoff calculation result = player.DBM_Task5 print("Task5 result:", result) # the Bayesian answer Bayesian = 84 # the truth is either above the Bayesian or below the Bayesian truth = 0 # if below and equal to the Bayesian # determine the truth num0 = random.randint(1, 100) print("Task5 num0:", num0) if num0 > Bayesian: truth = 1 print("Task5 truth:", truth) # determine the payoff based on the truth num1 = random.randint(0, 100) num2 = random.randint(0, 100) print("Task5 num1:", num1) print("Task5 num2:", num2) if truth == 0: if result > num1 or result > num2: player.payoff = C.BONUS else: player.payoff = 0 if truth == 1: if result < num1 or result < num2: player.payoff = C.BONUS else: player.payoff = 0 print("Task5 payoff:", player.payoff) # save parameters player.Task5_answer = 84 player.Task5_order = player.round_number class Unemployment3(Page): form_model = 'player' form_fields = ['Task5_left_b', 'Task5_right_b', 'Task5list'] @staticmethod def is_displayed(player: Player): return player.round_number == player.participant.task_rounds_treatment2['unemployment'] and player.unemployment_index == 3 @staticmethod def before_next_page(player, timeout_happened): # determine the result for payoff calculation result = random.randint(player.Task5_left_b, player.Task5_right_b) player.DBM_Task5 = result if player.session.payoff_round == player.round_number: # determine the result for payoff calculation result = player.DBM_Task5 print("Task5 result:", result) # the Bayesian answer Bayesian = 98 # the truth is either above the Bayesian or below the Bayesian truth = 0 # if below and equal to the Bayesian # determine the truth num0 = random.randint(1, 100) print("Task5 num0:", num0) if num0 > Bayesian: truth = 1 print("Task5 truth:", truth) # determine the payoff based on the truth num1 = random.randint(0, 100) num2 = random.randint(0, 100) print("Task5 num1:", num1) print("Task5 num2:", num2) if truth == 0: if result > num1 or result > num2: player.payoff = C.BONUS else: player.payoff = 0 if truth == 1: if result < num1 or result < num2: player.payoff = C.BONUS else: player.payoff = 0 print("Task5 payoff:", player.payoff) # save parameters player.Task5_answer = 98 player.Task5_order = player.round_number class InstructionDBM(Page): @staticmethod def is_displayed(player: Player): return player.round_number == 1 class ComprehensionCheckDBM(Page): form_model = 'player' form_fields = ['CC_Q1', 'CC_Q2', 'CC_Q3', 'CC_Q4'] @staticmethod def is_displayed(player: Player): return player.round_number == 1 @staticmethod def error_message(player: Player, values): # define error messages for each question error_messages = dict( CC_Q1='Incorrect answer! Hint: Because we only pay you based on a single guess of yours, there is no point for you to strategize across tasks.', CC_Q2='Incorrect answer! Hint: If you choose one range of numbers, the computer will further zoom in the range you chose and ask you to refine your guess by choosing between two narrower ranges of numbers with an “EXIT” button.', CC_Q3='Incorrect answer! Hint: If you choose to exit by clicking the “EXIT” button, the computer will randomly choose a number from the last range you chose (or the entire range if you never chose any range) and submit it as your guess in this task for you.', CC_Q4='Incorrect answer! Hint: We designed the bonus rule to make sure that you can secure the largest chance of winning the prize by reporting your best guess. Therefore, in each task, to maximize your chance of receiving the bonus, you should simply always submit your best guess.', # CC_Q5L='Incorrect answer! Hint: 1/2*1/2 = 1/4 = 25%; the left bound of the range should be 25; the correct answer should contain 25 only', #CC_Q5R='Incorrect answer! Hint: 1/2*1/2 = 1/4 = 25%; the right bound of the range should be 25; the correct answer should contain 25 only', ) # define the correct solutions for each question solutions14 = dict( CC_Q1=2, CC_Q2=1, CC_Q3=1, CC_Q4=5, ) # solution5 = dict( # CC_Q5L=25, # CC_Q5R=25 # ) # initialize an empty dictionary for errors errors = dict() # check each question and add an error message if the answer is incorrect for field_name in solutions14: if values[field_name] != solutions14[field_name]: errors[field_name] = error_messages[field_name] player.num_failed_attempts += 1 # for field_name in solution5: # if values[field_name] != solution5[field_name]: # errors[field_name] = error_messages[field_name] # player.num_failed_attempts += 0.5 if errors: if player.num_failed_attempts > 1: player.failed_more_than1 = True else: return errors @staticmethod def before_next_page(player: Player, timeout_happened): session = player.session participant = player.participant if player.failed_more_than1 == False: session.completions_by_treatment[participant.color] += 1 else: session.completions_by_treatment[participant.color] += 0 class survey(Page): form_model = 'player' form_fields = ['statistics', 'feedbackIR', 'feedbackBB', 'complexity', 'comments', 'Inflation', 'Unemployment', 'Income', 'Edu', 'No'] @staticmethod def is_displayed(player: Player): return player.round_number == 5 class End(Page): @staticmethod def is_displayed(player: Player): return player.round_number == 5 @staticmethod def before_next_page(player, timeout_happened): player.participant.finished = True class Failed(Page): @staticmethod def is_displayed(player: Player): return player.failed_more_than1 page_sequence = [InstructionDBM, ComprehensionCheckDBM, Failed, Intro1, Inflation1, Inflation2, Inflation3, Intro2, Income1, Income2, Income3, Intro3, Bayesian1, Bayesian2, Bayesian3, Intro4, Quantity1, Quantity2, Quantity3, Intro5, Unemployment1, Unemployment2, Unemployment3, survey, End ]