from otree.api import * import random doc = """ Part 2 of Choice Matching experiment. Survey on the complexity of study instructions. Order: (1) Ancillary (2) QSR/FR (3) FR/QSR 2023.07.18 """ class C(BaseConstants): NAME_IN_URL = 'CM_instructions_AQ' PLAYERS_PER_GROUP = None NUM_ROUNDS = 1 payoff_fr = 4 level1 = 4 level2 = 4.5 level3 = 5 level4 = 5.5 level5 = 6 # Examples total_players = 12 # make sure it corresponds to the actual group size example = total_players - 1 choices = 9 # NUMERICAL EXAMPLES input1 = example - 7 # Example 1 table 4 (main example) input2 = example - input1 - 3 # Example table 4 (main example) input3 = example - input1 - input2 # Example table 4 (main example) input1_similar = 4 # Example 1 table 4 (main example) input2_similar = 3 # Example table 4 (main example) input3_similar = 2 # Example table 4 (main example) input1_diff = 1 # Example 1 table 4 (main example) input2_diff = 1 # Example table 4 (main example) input3_diff = 7 # Example table 4 (main example) input1_2 = 1 # Example table 4 (extra example) input2_2 = total_players - 2 # Example table 4 (extra example) input3_2 = 0 # Example table 4 (extra example) quadratic_score_A = 2 quadratic_score_B = 2 # Bonus table 4 main example bonus1 = round(quadratic_score_A + quadratic_score_B * (2 * (input1 / example) - ((input1 / example) * (input1 / example) + ( input2 / example) * (input2 / example) + ( input3 / example) * (input3 / example))), 2) bonus2 = round(quadratic_score_A + quadratic_score_B * (2 * (input2 / example) - ((input1 / example) * (input1 / example) + ( input2 / example) * (input2 / example) + ( input3 / example) * (input3 / example))), 2) bonus3 = round(quadratic_score_A + quadratic_score_B * (2 * (input3 / example) - ((input1 / example) * (input1 / example) + ( input2 / example) * (input2 / example) + ( input3 / example) * (input3 / example))), 2) bonus1_similar = round(quadratic_score_A + quadratic_score_B * (2 * (input1_similar / example) - ((input1_similar / example) * ( input1_similar / example) + ( input2_similar / example) * ( input2_similar / example) + ( input3_similar / example) * ( input3_similar / example))), 2) bonus2_similar = round(quadratic_score_A + quadratic_score_B * (2 * (input2_similar / example) - ((input1_similar / example) * ( input1_similar / example) + ( input2_similar / example) * ( input2_similar / example) + ( input3_similar / example) * ( input3_similar / example))), 2) bonus3_similar = round(quadratic_score_A + quadratic_score_B * (2 * (input3_similar / example) - ((input1_similar / example) * ( input1_similar / example) + ( input2_similar / example) * ( input2_similar / example) + ( input3_similar / example) * ( input3_similar / example))), 2) bonus1_diff = round(quadratic_score_A + quadratic_score_B * (2 * (input1_diff / example) - ((input1_diff / example) * (input1_diff / example) + ( input2_diff / example) * ( input2_diff / example) + ( input3_diff / example) * ( input3_diff / example))), 2) bonus2_diff = round(quadratic_score_A + quadratic_score_B * (2 * (input2_diff / example) - ((input1_diff / example) * (input1_diff / example) + ( input2_diff / example) * ( input2_diff / example) + ( input3_diff / example) * ( input3_diff / example))), 2) bonus3_diff = round(quadratic_score_A + quadratic_score_B * (2 * (input3_diff / example) - ((input1_diff / example) * (input1_diff / example) + ( input2_diff / example) * ( input2_diff / example) + ( input3_diff / example) * ( input3_diff / example))), 2) # Bonus table 4 main example when making wrong decisions bonus1_2 = round(quadratic_score_A + quadratic_score_B * (2 * (input1_2 / example) - ((input1 / example) * (input1 / example) + ( input2 / example) * (input2 / example) + ( input3 / example) * (input3 / example))), 2) bonus2_2 = round(quadratic_score_A + quadratic_score_B * (2 * (input2_2 / example) - ((input1 / example) * (input1 / example) + ( input2 / example) * (input2 / example) + ( input3 / example) * (input3 / example))), 2) bonus3_2 = round(quadratic_score_A + quadratic_score_B * (2 * (input3_2 / example) - ((input1 / example) * (input1 / example) + ( input2 / example) * (input2 / example) + ( input3 / example) * (input3 / example))), 2) # Frequency method bonus freq_bonus = 4 # Price levels level1_cost = 4 level2_cost = 4.5 level3_cost = 5 level4_cost = 5.5 level5_cost = 6 # Probabilities prob_l = 60 prob_m = 75 prob_h = 90 budget = 6 budget_T2 = 6 resto1 = budget - level1 resto1_T2 = budget_T2 - level1 resto2 = budget - level2 resto2_T2 = budget_T2 - level2 # Group size for example group_size = 12 # Quadratic scoring rules quadratic_score_A = 2 quadratic_score_B = 2 prob_replace_l = 60 prob_replace_m = 75 prob_replace_h = 90 prob_not_replace_l = 100 - prob_replace_l prob_not_replace_m = 100 - prob_replace_m prob_not_replace_h = 100 - prob_replace_h class Subsession(BaseSubsession): pass def creating_session(subsession): if subsession.round_number == 1: for p in subsession.get_players(): participant = p.participant participant.treatment_p = subsession.session.config['TREATMENT'] random_num = random.random() if p.participant.treatment_p == 3 or p.participant.treatment_p == 6: if random_num <= (C.prob_replace_l * 0.01): replace_pred = 1 else: replace_pred = 0 else: if p.participant.treatment_p == 4 or p.participant.treatment_p == 7 or p.participant.treatment_p == 9: if random_num <= (C.prob_replace_m * 0.01): replace_pred = 1 else: replace_pred = 0 else: if random_num <= (C.prob_replace_h * 0.01): replace_pred = 1 else: replace_pred = 0 p.participant.replace_predictions_practice = replace_pred random_num_fr = random.random() if random_num_fr <= (C.prob_replace_m * 0.01): replace_pred_fr = 1 else: replace_pred_fr = 0 p.replace_predictions_practice_fr = replace_pred_fr random_num_aq = random.random() if random_num_aq <= (C.prob_replace_m * 0.01): replace_pred_aq = 1 else: replace_pred_aq = 0 p.replace_predictions_practice_aq = replace_pred_aq class Group(BaseGroup): pass class Player(BasePlayer): prolific_ID = models.StringField(label="Prolific ID:") CM_instr_A_1 = models.IntegerField() CM_instr_B_1 = models.IntegerField() CM_instr_C_1 = models.IntegerField() # Choices in each choice situation CE_choice_practice = models.IntegerField( choices=[[1, "A"], [2, "B"], [3, "Nessun"]], label="Practice Choice situation", widget=widgets.RadioSelect, blank=False, ) CE_choice_practice_2 = models.IntegerField( choices=[[1, "A"], [2, "B"], [3, "Nessun"]], label="Practice Choice situation", widget=widgets.RadioSelect, blank=False, ) CE_choice_practice_3 = models.IntegerField( choices=[[1, "A"], [2, "B"], [3, "Nessun"]], label="Practice Choice situation", widget=widgets.RadioSelect, blank=False, ) CE_choice_practice_pred_A = models.IntegerField() CE_choice_practice_pred_B = models.IntegerField() CE_choice_practice_pred_C = models.IntegerField() payoff_practice_A = models.CurrencyField() payoff_practice_B = models.CurrencyField() payoff_practice_C = models.CurrencyField() list_choices_A_practice = models.StringField(initial='') list_choices_B_practice = models.StringField(initial='') list_choices_C_practice = models.StringField(initial='') rand_A = models.IntegerField() rand_B = models.IntegerField() rand_C = models.IntegerField() A_choices = models.IntegerField() B_choices = models.IntegerField() C_choices = models.IntegerField() payoff_instr_1_A = models.CurrencyField() payoff_instr_1_B = models.CurrencyField() payoff_instr_1_C = models.CurrencyField() frequency_prediction = models.BooleanField() opinion_qsr_1 = models.IntegerField(choices=[[1, "1"], [2, "2"], [3, "3"], [4, "4"], [5, "5"], [6, "6"], [7, "7"]], widget=widgets.RadioSelectHorizontal) opinion_qsr_2 = models.IntegerField(choices=[[1, "1"], [2, "2"], [3, "3"], [4, "4"], [5, "5"], [6, "6"], [7, "7"]], widget=widgets.RadioSelectHorizontal) attention_qsr_1 = models.IntegerField(choices=[[1, "Vero"], [2, "Falso"], [3, "Non ricordo"]], widget=widgets.RadioSelectHorizontal, label="Alla fine del compito si compra una tazza:") attention_qsr_2 = models.IntegerField(choices=[[1, "Vero"], [2, "Falso"], [3, "Non ricordo"]], widget=widgets.RadioSelectHorizontal, label="La tazza che ho scelto nella fase 1 sarà necessariamente sostituita con una tazza scelta da un'altra persona:") comment_qsr_1 = models.LongStringField(blank=True, label="Hai qualche commento sulle istruzioni per questo compito?") opinion_fr_1 = models.IntegerField(choices=[[1, "1"], [2, "2"], [3, "3"], [4, "4"], [5, "5"], [6, "6"], [7, "7"]], widget=widgets.RadioSelectHorizontal) opinion_fr_2 = models.IntegerField(choices=[[1, "1"], [2, "2"], [3, "3"], [4, "4"], [5, "5"], [6, "6"], [7, "7"]], widget=widgets.RadioSelectHorizontal) attention_fr_1 = models.IntegerField(choices=[[1, "Vero"], [2, "Falso"], [3, "Non ricordo"]], widget=widgets.RadioSelectHorizontal, label="Alla fine del compito si compra una tazza:") attention_fr_2 = models.IntegerField(choices=[[1, "Vero"], [2, "Falso"], [3, "Non ricordo"]], widget=widgets.RadioSelectHorizontal, label="La tazza che ho scelto nella fase 1 sarà necessariamente sostituita con una tazza scelta da un'altra persona:") comment_fr_1 = models.LongStringField(blank=True, label="Hai qualche commento sulle istruzioni per questo compito?") opinion_aq_1 = models.IntegerField(choices=[[1, "1"], [2, "2"], [3, "3"], [4, "4"], [5, "5"], [6, "6"], [7, "7"]], widget=widgets.RadioSelectHorizontal) opinion_aq_2 = models.IntegerField(choices=[[1, "1"], [2, "2"], [3, "3"], [4, "4"], [5, "5"], [6, "6"], [7, "7"]], widget=widgets.RadioSelectHorizontal) attention_aq_1 = models.IntegerField(choices=[[1, "Vero"], [2, "Falso"], [3, "Non ricordo"]], widget=widgets.RadioSelectHorizontal, label="Alla fine del compito si compra una tazza:") attention_aq_2 = models.IntegerField(choices=[[1, "Vero"], [2, "Falso"], [3, "Non ricordo"]], widget=widgets.RadioSelectHorizontal, label="La tazza che ho scelto nella fase 1 sarà necessariamente sostituita con una tazza scelta da un'altra persona:") comment_aq_1 = models.LongStringField(blank=True, label="Hai qualche commento sulle istruzioni per questo compito?") CE_choice_practice_aux = models.IntegerField( choices=[[1, "A"], [2, "B"], [3, "Nessun"]], label="Practice Choice situation", widget=widgets.RadioSelect, blank=False, ) replace_predictions_practice_fr = models.IntegerField() replace_predictions_practice_aq = models.IntegerField() rank_option1 = models.IntegerField( choices=[ ('', 'Seleziona la classifica'), (1, 'Facile'), (2, 'Medio'), (3, 'Difficile'), ], label="Seleziona la classifica" ) rank_option2 = models.IntegerField( choices=[ ('', 'Seleziona la classifica'), (1, 'Facile'), (2, 'Medio'), (3, 'Difficile'), ], label="Select rank" ) rank_option3 = models.IntegerField( choices=[ ('', 'Seleziona la classifica'), (1, 'Facile'), (2, 'Medio'), (3, 'Difficile'), ], label="Seleziona la classifica" ) task1 = models.IntegerField( choices=[ (1, 'Facile'), (2, 'Medio'), (3, 'Difficile'), ] ) task2 = models.IntegerField( choices=[ (1, 'Facile'), (2, 'Medio'), (3, 'Difficile'), ] ) task3 = models.IntegerField( choices=[ (1, 'Facile'), (2, 'Medio'), (3, 'Difficile'), ] ) task_order = models.IntegerField() # PAGES class Start(Page): pass class Prolific_ID(Page): form_model = 'player' form_fields = ['prolific_ID'] class Study_overview(Page): pass class Task_1(Page): pass class Part_1(Page): @staticmethod def vars_for_template(player: Player): if player.participant.treatment_p == 1: progress = 99 else: if player.participant.treatment_p == 2: progress = 50 else: if player.participant.treatment_p == 3 or player.participant.treatment_p == 4 or player.participant.treatment_p == 5: progress = 14 else: if player.participant.treatment_p == 6 or player.participant.treatment_p == 7 or player.participant.treatment_p == 8: progress = 17 else: progress = 18 return dict(progress=progress) class Part_2_1a(Page): @staticmethod def vars_for_template(player: Player): if player.participant.treatment_p == 3 or player.participant.treatment_p == 4 or player.participant.treatment_p == 5: progress = 21 else: if player.participant.treatment_p == 6 or player.participant.treatment_p == 7 or player.participant.treatment_p == 8: progress = 25 else: progress = 30 return dict(progress=progress) class Part_2_1b(Page): def is_displayed(player: Player): return player.participant.treatment_p == 7 form_model = 'player' form_fields = ['CM_instr_A_1', 'CM_instr_B_1', 'CM_instr_C_1'] @staticmethod def live_method(player: Player, data): if data['clicked_button'] == 1: a = float(data['fieldA']) / C.example b = float(data['fieldB']) / C.example c = float(data['fieldC']) / C.example factor1 = a * a + b * b + c * c payoff_a = round(C.quadratic_score_A + C.quadratic_score_B * (2 * a - factor1), 2) payoff_b = round(C.quadratic_score_A + C.quadratic_score_B * (2 * b - factor1), 2) payoff_c = round(C.quadratic_score_A + C.quadratic_score_B * (2 * c - factor1), 2) response = dict(payoff_a=payoff_a, payoff_b=payoff_b, payoff_c=payoff_c, ) player.payoff_instr_1_A = payoff_a player.payoff_instr_1_B = payoff_b player.payoff_instr_1_C = payoff_c return {player.id_in_group: response} # Passing data from Python to JavaScript (js_vars) @staticmethod def js_vars(player): return dict(number_players=C.total_players, tempA=0, tempB=0, tempC=0) @staticmethod def error_message(player, values): if values['CM_instr_A_1'] + values['CM_instr_B_1'] + values['CM_instr_C_1'] != C.example: return 'La somma delle predizioni deve essere uguale a ' + str(C.example) @staticmethod def vars_for_template(player): cost_2 = str(C.level2) cost_1 = str(C.level1) if player.participant.treatment_p > 2 or player.participant.treatment_p < 6: progress = 28 return dict(costs1=cost_1, costs2=cost_2, group_size=C.example, progress=progress) class Part_2_1d(Page): def is_displayed(player: Player): return player.participant.treatment_p == 3 or player.participant.treatment_p == 4 or \ player.participant.treatment_p == 5 or player.participant.treatment_p == 6 or \ player.participant.treatment_p == 7 or player.participant.treatment_p == 8 @staticmethod def vars_for_template(player: Player): if player.participant.treatment_p == 3 or player.participant.treatment_p == 4 or player.participant.treatment_p == 5: progress = 35 else: if player.participant.treatment_p == 6 or player.participant.treatment_p == 7 or player.participant.treatment_p == 8: progress = 42 else: progress = 10 return dict(progress=progress) class Part_2_1d_2(Page): @staticmethod def vars_for_template(player: Player): return dict(progress=35) class Part_2_2(Page): def is_displayed(player: Player): return player.participant.treatment_p == 6 or player.participant.treatment_p == 7 or player.participant.treatment_p == 8 def vars_for_template(player: Player): return dict(group_size=C.example, progress=33) class Payment_1_2a(Page): def is_displayed(player: Player): return player.participant.treatment_p == 3 or player.participant.treatment_p == 4 \ or player.participant.treatment_p == 5 or player.participant.treatment_p == 6 \ or player.participant.treatment_p == 7 or player.participant.treatment_p == 8 @staticmethod def vars_for_template(player: Player): if player.participant.treatment_p == 3 or player.participant.treatment_p == 4 or player.participant.treatment_p == 5: progress = 42 else: if player.participant.treatment_p == 6 or player.participant.treatment_p == 7 or player.participant.treatment_p == 8: progress = 50 else: progress = 10 return dict(progress=progress) class Payment_1_2a_2(Page): @staticmethod def vars_for_template(player: Player): return dict(progress=42) class Payment_1_2b(Page): def is_displayed(player: Player): return player.participant.treatment_p == 3 or player.participant.treatment_p == 4 \ or player.participant.treatment_p == 5 or player.participant.treatment_p == 6 \ or player.participant.treatment_p == 7 or player.participant.treatment_p == 8 @staticmethod def vars_for_template(player: Player): if player.participant.treatment_p == 3 or player.participant.treatment_p == 4 or player.participant.treatment_p == 5: progress = 49 else: if player.participant.treatment_p == 6 or player.participant.treatment_p == 7 or player.participant.treatment_p == 8: progress = 58 else: progress = 10 return dict(progress=progress) class Payment_1_2b_2(Page): @staticmethod def vars_for_template(player: Player): return dict(progress=49) class Payment_2_1a(Page): @staticmethod def vars_for_template(player: Player): return dict(progress=56) class Payment_2_1b(Page): @staticmethod def vars_for_template(player: Player): return dict(progress=63) class Payment_3_1a_a(Page): # Fase 3 (Page 1) def is_displayed(player: Player): return player.participant.treatment_p == 3 or player.participant.treatment_p == 4 \ or player.participant.treatment_p == 5 or player.participant.treatment_p == 6 \ or player.participant.treatment_p == 7 or player.participant.treatment_p == 8 @staticmethod def vars_for_template(player: Player): if player.participant.treatment_p == 3 or player.participant.treatment_p == 4 or player.participant.treatment_p == 5: progress = 70 else: if player.participant.treatment_p == 6 or player.participant.treatment_p == 7 or player.participant.treatment_p == 8: progress = 67 else: progress = 10 return dict(progress=progress) class Payment_3_1a_a_2(Page): # Fase 3 (Page 1) @staticmethod def vars_for_template(player: Player): return dict(progress=70) class Payment_3_1a_b(Page): # Fase 3 (Fortune wheel)_ def is_displayed(player: Player): return player.participant.treatment_p == 3 or player.participant.treatment_p == 4 \ or player.participant.treatment_p == 5 or player.participant.treatment_p == 6 \ or player.participant.treatment_p == 7 or player.participant.treatment_p == 8 @staticmethod def vars_for_template(player: Player): if player.participant.treatment_p == 3 or player.participant.treatment_p == 4 or player.participant.treatment_p == 5: progress = 77 else: if player.participant.treatment_p == 6 or player.participant.treatment_p == 7 or player.participant.treatment_p == 8: progress = 75 else: progress = 10 return dict(progress=progress) class Payment_3_1a_b_fr(Page): # Fase 3 (Fortune wheel)_ def is_displayed(player: Player): return player.participant.treatment_p == 3 or player.participant.treatment_p == 4 \ or player.participant.treatment_p == 5 or player.participant.treatment_p == 6 \ or player.participant.treatment_p == 7 or player.participant.treatment_p == 8 @staticmethod def vars_for_template(player: Player): return dict(progress=77) class Payment_3_1a_b_2(Page): # Fase 3 (Fortune wheel)_ def is_displayed(player: Player): return player.participant.treatment_p == 3 or player.participant.treatment_p == 4 \ or player.participant.treatment_p == 5 or player.participant.treatment_p == 6 \ or player.participant.treatment_p == 7 or player.participant.treatment_p == 8 @staticmethod def vars_for_template(player: Player): if player.participant.treatment_p == 3 or player.participant.treatment_p == 4 or player.participant.treatment_p == 5: progress = 84 else: if player.participant.treatment_p == 6 or player.participant.treatment_p == 7 or player.participant.treatment_p == 8: progress = 83 else: progress = 10 return dict(progress=progress) class Payment_3_1a_b_2_fr(Page): # Fase 3 (Fortune wheel)_ @staticmethod def vars_for_template(player: Player): return dict(progress=84) class Payment_3_1a_c(Page): # Fase 3 (Fortune wheel - 2 cases) def is_displayed(player: Player): return player.participant.treatment_p == 3 or player.participant.treatment_p == 4 \ or player.participant.treatment_p == 5 or player.participant.treatment_p == 6 \ or player.participant.treatment_p == 7 or player.participant.treatment_p == 8 @staticmethod def vars_for_template(player: Player): if player.participant.treatment_p == 3 or player.participant.treatment_p == 4 or player.participant.treatment_p == 5: progress = 91 else: if player.participant.treatment_p == 6 or player.participant.treatment_p == 7 or player.participant.treatment_p == 8: progress = 92 else: progress = 10 return dict(progress=progress) class Payment_3_1a_c_fr(Page): # Fase 3 (Fortune wheel - 2 cases) @staticmethod def vars_for_template(player: Player): return dict(progress=91) class Payment_3_1a_d(Page): # Fase 3 (Fortune wheel - 2 cases) def is_displayed(player: Player): return player.participant.treatment_p == 3 or player.participant.treatment_p == 4 \ or player.participant.treatment_p == 5 or player.participant.treatment_p == 6 \ or player.participant.treatment_p == 7 or player.participant.treatment_p == 8 @staticmethod def vars_for_template(player: Player): if player.participant.treatment_p == 3 or player.participant.treatment_p == 4 or player.participant.treatment_p == 5: progress = 98 else: if player.participant.treatment_p == 6 or player.participant.treatment_p == 7 or player.participant.treatment_p == 8: progress = 99 else: progress = 10 return dict(progress=progress) class Payment_3_1a_d_fr(Page): # Fase 3 (Fortune wheel - 2 cases) @staticmethod def vars_for_template(player: Player): return dict(progress=98) class Trial_1(Page): def is_displayed(player: Player): return player.participant.treatment_p > 2 class Trial_2(Page): form_model = 'player' form_fields = ['CE_choice_practice'] class Trial_3(Page): form_model = 'player' form_fields = ['CE_choice_practice_pred_A', 'CE_choice_practice_pred_B', 'CE_choice_practice_pred_C'] @staticmethod def live_method(player: Player, data): if data['clicked_button'] == 1: a = float(data['fieldA']) / (C.group_size - 1) b = float(data['fieldB']) / (C.group_size - 1) c = float(data['fieldC']) / (C.group_size - 1) factor1 = a * a + b * b + c * c payoff_a = round(C.quadratic_score_A + C.quadratic_score_B * (2 * a - factor1), 2) payoff_b = round(C.quadratic_score_A + C.quadratic_score_B * (2 * b - factor1), 2) payoff_c = round(C.quadratic_score_A + C.quadratic_score_B * (2 * c - factor1), 2) response = dict(payoff_a=payoff_a, payoff_b=payoff_b, payoff_c=payoff_c) player.payoff_practice_A = payoff_a player.payoff_practice_B = payoff_b player.payoff_practice_C = payoff_c return {player.id_in_group: response} # Passing data from Python to JavaScript (js_vars) @staticmethod def js_vars(player): return dict(number_players=C.group_size, tempA=0, tempB=0, tempC=0) @staticmethod def error_message(player, values): if values['CE_choice_practice_pred_A'] + values['CE_choice_practice_pred_B'] + values[ 'CE_choice_practice_pred_C'] != ( C.group_size - 1): return 'La somma delle predizioni deve essere uguale a ' + str(C.group_size - 1) @staticmethod def vars_for_template(player): cost_2 = str(C.level2) cost_1 = str(C.level1) return dict(costs1=cost_1, costs2=cost_2, group_size=C.group_size - 1) @staticmethod def before_next_page(player: Player, timeout_happened): # Random draw numb_1 = round(((C.group_size - 1) / 3)) - 1 numb_2 = round(((C.group_size - 1 - numb_1) / 2)) numb_3 = C.group_size - 1 - numb_1 - numb_2 random_selection = [numb_1, numb_2, numb_3] random_selection.sort(reverse=True) if player.CE_choice_practice == 1: A_choices = random_selection[0] B_choices = random_selection[1] C_choices = random_selection[2] else: if player.CE_choice_practice == 2: A_choices = random_selection[1] B_choices = random_selection[0] C_choices = random_selection[2] else: A_choices = random_selection[2] B_choices = random_selection[1] C_choices = random_selection[0] player.A_choices = A_choices player.B_choices = B_choices player.C_choices = C_choices class fortune_wheel(Page): def is_displayed(player: Player): return player.participant.treatment_p == 3 or player.participant.treatment_p == 4 \ or player.participant.treatment_p == 5 or player.participant.treatment_p == 6 \ or player.participant.treatment_p == 7 or player.participant.treatment_p == 8 \ or player.participant.treatment_p == 9 @staticmethod def js_vars(player): return dict(replace=player.participant.replace_predictions_practice, treatment=player.participant.treatment_p) class fortune_wheel_fr(Page): @staticmethod def js_vars(player): return dict(replace=player.replace_predictions_practice_fr, treatment=player.participant.treatment_p) class fortune_wheel_aq(Page): @staticmethod def js_vars(player): return dict(replace=player.replace_predictions_practice_aq, treatment=player.participant.treatment_p) class Trial_results_no_replace(Page): def is_displayed(player: Player): return player.participant.replace_predictions_practice == 0 and player.participant.treatment_p == 3 \ or player.participant.replace_predictions_practice == 0 and player.participant.treatment_p == 4 \ or player.participant.replace_predictions_practice == 0 and player.participant.treatment_p == 5 @staticmethod def js_vars(player): return dict(replace=player.participant.replace_predictions_practice) @staticmethod def vars_for_template(player): cost_1 = str(C.level1) cost_2 = str(C.level2) return dict(costs1=cost_1, costs2=cost_2, num_participants=C.group_size - 1, payoff_a=player.payoff_practice_A, payoff_b=player.payoff_practice_B, payoff_c=player.payoff_practice_C) class Trial_results_replace(Page): def is_displayed(player: Player): return player.participant.replace_predictions_practice == 1 and player.participant.treatment_p == 3 \ or player.participant.replace_predictions_practice == 1 and player.participant.treatment_p == 4 \ or player.participant.replace_predictions_practice == 1 and player.participant.treatment_p == 5 \ or player.participant.replace_predictions_practice == 1 and player.participant.treatment_p == 6 \ or player.participant.replace_predictions_practice == 1 and player.participant.treatment_p == 7 \ or player.participant.replace_predictions_practice == 1 and player.participant.treatment_p == 8 \ \ @ staticmethod def js_vars(player): return dict(replace=player.participant.replace_predictions_practice) @staticmethod def vars_for_template(player): cost_2 = str(C.level2) cost_1 = str(C.level1) # Pre-determined choices of "others" in the trial round numb_1 = round(((C.group_size - 1) / 3)) - 1 numb_2 = round(((C.group_size - 1 - numb_1) / 2)) numb_3 = C.group_size - 1 - numb_1 - numb_2 random_selection = [numb_1, numb_2, numb_3] random_selection.sort(reverse=True) if player.CE_choice_practice == 1: replaced_A = random_selection[0] replaced_B = random_selection[1] replaced_C = random_selection[2] else: if player.CE_choice_practice == 2: replaced_A = random_selection[1] replaced_B = random_selection[0] replaced_C = random_selection[2] else: replaced_A = random_selection[2] replaced_B = random_selection[1] replaced_C = random_selection[0] player.rand_A = replaced_A player.rand_B = replaced_B player.rand_C = replaced_C Pred_A = replaced_A / (C.group_size - 1) Pred_B = replaced_B / (C.group_size - 1) Pred_C = replaced_C / (C.group_size - 1) factor1 = Pred_A * Pred_A + Pred_B * Pred_B + Pred_C * Pred_C payoff_a = round(C.quadratic_score_A + C.quadratic_score_B * (2 * Pred_A - factor1), 2) payoff_b = round(C.quadratic_score_A + C.quadratic_score_B * (2 * Pred_B - factor1), 2) payoff_c = round(C.quadratic_score_A + C.quadratic_score_B * (2 * Pred_C - factor1), 2) if player.participant.treatment_p == 6 or player.participant.treatment_p == 7 \ or player.participant.treatment_p == 8: nr_other_choice_A = player.A_choices nr_other_choice_B = player.B_choices nr_other_choice_C = player.C_choices if replaced_A == nr_other_choice_A and replaced_B == nr_other_choice_B and replaced_C == nr_other_choice_C: player.frequency_prediction = 1 else: player.frequency_prediction = 0 else: player.frequency_prediction = 0 nr_pred_A = player.A_choices nr_pred_B = player.B_choices nr_pred_C = player.C_choices # cont = list(range(0, leng)) return dict(replaced_A=replaced_A, replaced_B=replaced_B, replaced_C=replaced_C, costs1=cost_1, costs2=cost_2, num_participants=C.group_size - 1, payoff_a=payoff_a, payoff_b=payoff_b, payoff_c=payoff_c, frequency_prediction=player.frequency_prediction, nr_pred_A=nr_pred_A, nr_pred_B=nr_pred_B, nr_pred_C=nr_pred_C) class Trial_results_replace_fr(Page): def is_displayed(player: Player): return player.replace_predictions_practice_fr == 1 @staticmethod def js_vars(player): return dict(replace=player.replace_predictions_practice_fr) @staticmethod def vars_for_template(player): cost_2 = str(C.level2) cost_1 = str(C.level1) # Pre-determined choices of "others" in the trial round numb_1 = round(((C.group_size - 1) / 3)) - 1 numb_2 = round(((C.group_size - 1 - numb_1) / 2)) numb_3 = C.group_size - 1 - numb_1 - numb_2 random_selection = [numb_1, numb_2, numb_3] random_selection.sort(reverse=True) if player.CE_choice_practice_2 == 1: replaced_A = random_selection[0] replaced_B = random_selection[1] replaced_C = random_selection[2] else: if player.CE_choice_practice_2 == 2: replaced_A = random_selection[1] replaced_B = random_selection[0] replaced_C = random_selection[2] else: replaced_A = random_selection[2] replaced_B = random_selection[1] replaced_C = random_selection[0] player.rand_A = replaced_A player.rand_B = replaced_B player.rand_C = replaced_C Pred_A = replaced_A / (C.group_size - 1) Pred_B = replaced_B / (C.group_size - 1) Pred_C = replaced_C / (C.group_size - 1) factor1 = Pred_A * Pred_A + Pred_B * Pred_B + Pred_C * Pred_C payoff_a = round(C.quadratic_score_A + C.quadratic_score_B * (2 * Pred_A - factor1), 2) payoff_b = round(C.quadratic_score_A + C.quadratic_score_B * (2 * Pred_B - factor1), 2) payoff_c = round(C.quadratic_score_A + C.quadratic_score_B * (2 * Pred_C - factor1), 2) nr_other_choice_A = player.A_choices nr_other_choice_B = player.B_choices nr_other_choice_C = player.C_choices if replaced_A == nr_other_choice_A and replaced_B == nr_other_choice_B and replaced_C == nr_other_choice_C: player.frequency_prediction = 1 else: player.frequency_prediction = 0 nr_pred_A = player.A_choices nr_pred_B = player.B_choices nr_pred_C = player.C_choices # cont = list(range(0, leng)) return dict(replaced_A=replaced_A, replaced_B=replaced_B, replaced_C=replaced_C, costs1=cost_1, costs2=cost_2, num_participants=C.group_size - 1, payoff_a=payoff_a, payoff_b=payoff_b, payoff_c=payoff_c, frequency_prediction=player.frequency_prediction, nr_pred_A=nr_pred_A, nr_pred_B=nr_pred_B, nr_pred_C=nr_pred_C) class Trial_binding_alt_payoff(Page): @staticmethod def js_vars(player): return dict(random_choice=player.participant.random_choice_practice) @staticmethod def vars_for_template(player): cost_2 = str(C.level2) cost_1 = str(C.level1) number_A = [1] * player.A_choices number_B = [2] * player.B_choices number_C = [3] * player.C_choices list_choices = number_A + number_B + number_C player.participant.random_choice_practice = random.choice(list_choices) # print('random choice is', player.participant.random_choice_practice, 'from the list', list_choices) return dict(costs1=cost_1, costs2=cost_2, num_participants=C.group_size - 1, listA=number_A, listB=number_B, listC=number_C, random_prediction_A=player.A_choices, random_prediction_B=player.B_choices, random_prediction_C=player.C_choices) class Trial_payoff_no_replace(Page): @staticmethod def vars_for_template(player): cost_2 = str(C.level2) cost_1 = str(C.level1) return dict(costs1=cost_1, costs2=cost_2, num_participants=C.group_size - 1, random_choice_practice=player.participant.random_choice_practice) class Trial_payoff_replace(Page): @staticmethod def vars_for_template(player): cost_2 = str(C.level2) cost_1 = str(C.level1) replaced_A = player.rand_A replaced_B = player.rand_B replaced_C = player.rand_C Pred_A = replaced_A / (C.group_size - 1) Pred_B = replaced_B / (C.group_size - 1) Pred_C = replaced_C / (C.group_size - 1) factor1 = Pred_A * Pred_A + Pred_B * Pred_B + Pred_C * Pred_C payoff_a = round(C.quadratic_score_A + C.quadratic_score_B * (2 * Pred_A - factor1), 2) payoff_b = round(C.quadratic_score_A + C.quadratic_score_B * (2 * Pred_B - factor1), 2) payoff_c = round(C.quadratic_score_A + C.quadratic_score_B * (2 * Pred_C - factor1), 2) return dict(costs1=cost_1, costs2=cost_2, selectedA=replaced_A, selectedB=replaced_B, selectedC=replaced_C, num_participants=C.group_size - 1, payoff_a=payoff_a, payoff_b=payoff_b, payoff_c=payoff_c, random_choice_practice=player.participant.random_choice_practice) class Questionnaire_1(Page): form_model = 'player' form_fields = ['opinion_qsr_1', 'opinion_qsr_2'] class Questionnaire_2(Page): form_model = 'player' form_fields = ['attention_qsr_1', 'attention_qsr_2'] class Questionnaire_3(Page): form_model = 'player' form_fields = ['comment_qsr_1'] class Task_2(Page): pass class Task_2_introduction(Page): form_model = 'player' form_fields = ['CM_instr_A_1', 'CM_instr_B_1', 'CM_instr_C_1'] @staticmethod def live_method(player: Player, data): if data['clicked_button'] == 1: a = float(data['fieldA']) / C.example b = float(data['fieldB']) / C.example c = float(data['fieldC']) / C.example factor1 = a * a + b * b + c * c payoff_a = round(C.quadratic_score_A + C.quadratic_score_B * (2 * a - factor1), 2) payoff_b = round(C.quadratic_score_A + C.quadratic_score_B * (2 * b - factor1), 2) payoff_c = round(C.quadratic_score_A + C.quadratic_score_B * (2 * c - factor1), 2) response = dict(payoff_a=payoff_a, payoff_b=payoff_b, payoff_c=payoff_c, ) player.payoff_instr_1_A = payoff_a player.payoff_instr_1_B = payoff_b player.payoff_instr_1_C = payoff_c return {player.id_in_group: response} # Passing data from Python to JavaScript (js_vars) @staticmethod def js_vars(player): return dict(number_players=C.total_players, tempA=0, tempB=0, tempC=0) @staticmethod def error_message(player, values): if values['CM_instr_A_1'] + values['CM_instr_B_1'] + values['CM_instr_C_1'] != C.example: return 'La somma delle predizioni deve essere uguale a ' + str(C.example) @staticmethod def vars_for_template(player): cost_2 = str(C.level2) cost_1 = str(C.level1) if player.participant.treatment_p > 2 or player.participant.treatment_p < 6: progress = 28 return dict(costs1=cost_1, costs2=cost_2, group_size=C.example, progress=progress) class Trial_2_fr(Page): form_model = 'player' form_fields = ['CE_choice_practice_2'] class Trial_3_fr(Page): def is_displayed(player: Player): return player.participant.treatment_p == 7 form_model = 'player' form_fields = ['CE_choice_practice_pred_A', 'CE_choice_practice_pred_B', 'CE_choice_practice_pred_C'] # Passing data from Python to JavaScript (js_vars) @staticmethod def js_vars(player): return dict(number_players=C.group_size, tempA=0, tempB=0, tempC=0) @staticmethod def error_message(player, values): if values['CE_choice_practice_pred_A'] + values['CE_choice_practice_pred_B'] + values[ 'CE_choice_practice_pred_C'] != ( C.group_size - 1): return 'La somma delle predizioni deve essere uguale a ' + str(C.group_size - 1) @staticmethod def vars_for_template(player): cost_2 = str(C.level2) cost_1 = str(C.level1) return dict(costs1=cost_1, costs2=cost_2, group_size=C.group_size - 1) @staticmethod def before_next_page(player: Player, timeout_happened): # Random draw numb_1 = round(((C.group_size - 1) / 3)) - 1 numb_2 = round(((C.group_size - 1 - numb_1) / 2)) numb_3 = C.group_size - 1 - numb_1 - numb_2 random_selection = [numb_1, numb_2, numb_3] random.shuffle(random_selection) A_choices = random_selection[0] B_choices = random_selection[1] C_choices = random_selection[2] player.A_choices = A_choices player.B_choices = B_choices player.C_choices = C_choices class Trial_results_no_replace_fr(Page): def is_displayed(player: Player): return player.replace_predictions_practice_fr == 0 @staticmethod def js_vars(player): return dict(replace=player.replace_predictions_practice_fr) @staticmethod def vars_for_template(player): cost_1 = str(C.level1) cost_2 = str(C.level2) nr_pred_A = player.A_choices nr_pred_B = player.B_choices nr_pred_C = player.C_choices nr_other_choice_A = player.A_choices nr_other_choice_B = player.B_choices nr_other_choice_C = player.C_choices if player.CE_choice_practice_pred_A == nr_other_choice_A and player.CE_choice_practice_pred_B == nr_other_choice_B and player.CE_choice_practice_pred_C == nr_other_choice_C: player.frequency_prediction = 1 else: player.frequency_prediction = 0 return dict(costs1=cost_1, costs2=cost_2, num_participants=C.group_size - 1, frequency_prediction=player.frequency_prediction, nr_pred_A=nr_pred_A, nr_pred_B=nr_pred_B, nr_pred_C=nr_pred_C) class Questionnaire_1_fr(Page): form_model = 'player' form_fields = ['opinion_fr_1', 'opinion_fr_2'] class Questionnaire_2_fr(Page): form_model = 'player' form_fields = ['attention_fr_1', 'attention_fr_2'] class Questionnaire_3_fr(Page): form_model = 'player' form_fields = ['comment_fr_1'] class Task_3(Page): pass class Task_3_introduction(Page): pass class Part_2_3a(Page): @staticmethod def vars_for_template(player: Player): return dict(progress=27) class Part_2_3b(Page): @staticmethod def vars_for_template(player: Player): return dict(progress=36) class Payment_1_3a(Page): @staticmethod def vars_for_template(player: Player): return dict(progress=45) class Payment_1_3b(Page): @staticmethod def vars_for_template(player: Player): return dict(progress=54) class Payment_3_2a_a(Page): @staticmethod def vars_for_template(player: Player): return dict(progress=63) class Payment_3_2a_b(Page): @staticmethod def vars_for_template(player: Player): return dict(progress=72) class Payment_3_2a_c(Page): @staticmethod def vars_for_template(player: Player): return dict(progress=90) class Payment_3_2b_a(Page): @staticmethod def vars_for_template(player: Player): return dict(progress=99) class Payment_3_2a_b_2(Page): @staticmethod def vars_for_template(player: Player): return dict(progress=81) class Payment_3_2c_a(Page): pass class Payment_3_2c_b(Page): pass class Payment_3_2d_a(Page): pass class Payment_3_2d_b(Page): pass class Trial_1_aq(Page): pass class Trial_2_aq(Page): form_model = 'player' form_fields = ['CE_choice_practice_3'] class Trial_3_aux(Page): form_model = 'player' form_fields = ['CE_choice_practice_aux'] # # def before_next_page(player: Player, timeout_happened): @staticmethod def before_next_page(player: Player, timeout_happened): player.participant.random_choice_practice = random.randint(1, 3) # Random draw A_choices = random.randint(0, 1) if A_choices == 1: B_choices = 0 C_choices = 0 else: B_choices = random.randint(0, 1) if B_choices == 1: C_choices = 0 else: C_choices = 1 player.A_choices = A_choices player.B_choices = B_choices player.C_choices = C_choices class Trial_results_no_replace_aux(Page): def is_displayed(player: Player): return player.replace_predictions_practice_aq == 0 @staticmethod def js_vars(player): return dict(replace=player.replace_predictions_practice_aq) @staticmethod def vars_for_template(player): print(player.CE_choice_practice_aux) cost_2 = str(C.level2) cost_1 = str(C.level1) if player.CE_choice_practice_aux == 1: payoff = C.budget - C.level1 else: if player.CE_choice_practice_aux == 2: payoff = C.budget - C.level2 else: payoff = C.budget return dict(costs1=cost_1, costs2=cost_2, random_choice_practice=player.CE_choice_practice_aux, payoff=payoff ) class Trial_payoff_replace_aux(Page): def is_displayed(player: Player): return player.replace_predictions_practice_aq == 1 @staticmethod def vars_for_template(player): cost_2 = str(C.level2) cost_1 = str(C.level1) if player.participant.random_choice_practice == 1: payoff = C.budget - C.level1 else: if player.participant.random_choice_practice == 2: payoff = C.budget - C.level2 else: payoff = C.budget return dict(costs1=cost_1, costs2=cost_2, random_choice_practice=player.participant.random_choice_practice, payoff=payoff ) class Questionnaire_1_aq(Page): form_model = 'player' form_fields = ['opinion_aq_1', 'opinion_aq_2'] class Questionnaire_2_aq(Page): form_model = 'player' form_fields = ['attention_aq_1', 'attention_aq_2'] class Questionnaire_3_aq(Page): form_model = 'player' form_fields = ['comment_aq_1'] class Ranking(Page): form_model = "player" form_fields = ['task1', 'task2', 'task3'] def error_message(player: Player, values): if values['task1'] + values['task2'] + values['task3'] != 6: return "Si prega di selezionare una classifica unica" class Final(Page): pass page_sequence = [ Start, Prolific_ID, Study_overview, Task_1, Part_1, Part_2_3a, Part_2_3b, Payment_1_3a, Payment_1_3b, Payment_3_2a_a, # T9 Payment_3_2a_b, # T9 Payment_3_2a_b_2, # T9 Payment_3_2a_c, # T9 Payment_3_2b_a, # T9 Trial_1_aq, Trial_2_aq, Trial_3_aux, fortune_wheel_aq, Trial_results_no_replace_aux, # Trial_payoff_no_replace, Trial_payoff_replace_aux, Task_2, Part_2_1b, # Task 2 instructions Part_1, Part_2_1a, Part_2_2, Part_2_1d, Payment_1_2a, Payment_1_2b, # Payment_2_1a, # Payment_2_1b, Payment_3_1a_a, # T3-T6 Payment_3_1a_b, # T3-T8 Payment_3_1a_b_2, Payment_3_1a_c, # T3-T6 Payment_3_1a_d, # T3-T6 Trial_1, Trial_2_fr, Trial_3_fr, fortune_wheel_fr, Trial_results_replace_fr, Trial_results_no_replace_fr, Questionnaire_1_fr, Questionnaire_2_fr, Questionnaire_3_fr, Task_2, Part_2_1b, # Task 2 instructions Part_2_1d_2, Payment_1_2a_2, Payment_1_2b_2, Payment_2_1a, Payment_2_1b, Payment_3_1a_a_2, Payment_3_1a_b_fr, Payment_3_1a_b_2_fr, Payment_3_1a_c_fr, Payment_3_1a_d_fr, Trial_1, Trial_2, Trial_3, fortune_wheel, Trial_results_no_replace, Trial_results_replace, Trial_binding_alt_payoff, Trial_payoff_no_replace, Trial_payoff_replace, Questionnaire_1, Questionnaire_2, Questionnaire_3, Task_3, Task_3_introduction, Questionnaire_1_aq, Questionnaire_2_aq, Questionnaire_3_aq, Ranking, Final ]