from otree.api import * import random doc = """ CM experiment. Choice matching task """ class C(BaseConstants): NAME_IN_URL = 'CM_CM_2' PLAYERS_PER_GROUP = 2 NUM_ROUNDS = 1 # Price levels (check how to put them in list and draw from it) level1 = 4 level2 = 4.5 level3 = 5 level4 = 5.5 level5 = 6 # Probabilities prob_l = 60 prob_m = 75 prob_h = 90 # Quadratic scoring rules quadratic_score_A = 5 quadratic_score_B = 5 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 max_num_try = 5 # Maximum number of tries practice test # Number of task tasks = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10'] num_CE = len(tasks) # payoff frequency method payoff_fr = 4 exchange_pounds = 0.87 frequency_pounds = payoff_fr * exchange_pounds # Experimental budget budget = 6 class Subsession(BaseSubsession): pass def creating_session(subsession: Subsession): if subsession.round_number == 1: # CHECK IF YOU NEED PLAYERS_PER_GROUP OR SUBSESSION.SESSION.NUM_PARTICIPANTS (as in the original) subsession.session.other_part = subsession.session.num_participants - 1 subsession.session.random_prediction_A = random.randint(0, subsession.session.num_participants - 1) # Are these used anywhere? if subsession.session.random_prediction_A < (subsession.session.num_participants - 1): subsession.session.random_prediction_B = \ random.randint(0, subsession.session.num_participants - 1 - subsession.session.random_prediction_A) else: subsession.session.random_prediction_B = 0 subsession.session.random_prediction_C = \ subsession.session.num_participants - 1 - subsession.session.random_prediction_A - \ subsession.session.random_prediction_B subsession.session.random_prediction_A_2 = \ random.randint(int(round((subsession.session.num_participants - 1) * 0.2, 0)), int(round((subsession.session.num_participants - 1) * 0.4, 0))) subsession.session.random_prediction_B_2 = \ random.randint(int(round((subsession.session.num_participants - 1) * 0.2, 0)), (int(round((subsession.session.num_participants - 1) * 0.4, 0)))) subsession.session.random_prediction_C_2 = \ subsession.session.num_participants - 1 - subsession.session.random_prediction_A_2 - \ subsession.session.random_prediction_B_2 if subsession.session.random_prediction_C_2 < 0: subsession.session.random_prediction_C_2 = 0 list_choices_A_temp = " ".join(['A'] * subsession.session.random_prediction_A_2) list_choices_B_temp = " ".join(['B'] * subsession.session.random_prediction_B_2) list_choices_C_temp = " ".join(['C'] * subsession.session.random_prediction_C_2) # DEBUG CHECK # print(subsession.session.random_prediction_A_2, list_choices_A_temp, # subsession.session.random_prediction_B_2, list_choices_B_temp, # subsession.session.random_prediction_C_2, list_choices_C_temp) choices_str = list_choices_A_temp + ' ' + list_choices_B_temp + ' ' + list_choices_C_temp list_choices = choices_str.split() # Random draw from list of randomly drawn choices subsession.session.chosen_letter_2 = random.choice(list_choices) listA_2 = [] # List of matches rnd = random.sample(list(range(1, subsession.session.num_participants)), subsession.session.num_participants - 1) example_prediction_selected_A = [] example_prediction_selected_B = [] example_prediction_selected_C = [] for i in range(0, subsession.session.num_participants - 1): n_t = int(rnd[i]) if i == subsession.session.random_prediction_A_2 - 1: n = str(n_t) + "." else: n = str(n_t) + "," listA_2.append(n) example_prediction_selected_A_temp = random.randint( int(round((subsession.session.num_participants - 1) * 0.2, 0)), int(round((subsession.session.num_participants - 1) * 0.7, 0))) example_prediction_selected_B_temp = random.randint( int(round((subsession.session.num_participants - 1) * 0.2, 0)), int(round((subsession.session.num_participants - 1) * 0.7, 0))) if example_prediction_selected_A_temp + \ example_prediction_selected_B_temp >= subsession.session.num_participants - 1: example_prediction_selected_B_temp = \ subsession.session.num_participants - 1 - example_prediction_selected_A_temp example_prediction_selected_C_temp = 0 else: example_prediction_selected_C_temp = \ subsession.session.num_participants - 1 - example_prediction_selected_A_temp - \ example_prediction_selected_B_temp example_prediction_selected_A.append(example_prediction_selected_A_temp) example_prediction_selected_B.append(example_prediction_selected_B_temp) example_prediction_selected_C.append(example_prediction_selected_C_temp) # indent changed from here subsession.session.example_prediction_selected_A = example_prediction_selected_A subsession.session.example_prediction_selected_B = example_prediction_selected_B subsession.session.example_prediction_selected_C = example_prediction_selected_C subsession.session.listA_2 = listA_2 example_prediction_selected_A_temp = random.randint( int(round((subsession.session.num_participants - 1) * 0.2, 0)), int(round((subsession.session.num_participants - 1) * 0.7, 0))) example_prediction_selected_B_temp = random.randint( int(round((subsession.session.num_participants - 1) * 0.2, 0)), (int(round((subsession.session.num_participants - 1) * 0.7, 0)))) if example_prediction_selected_B_temp + example_prediction_selected_A_temp >= \ subsession.session.num_participants - 1: example_prediction_selected_B_temp = subsession.session.num_participants - 1 - \ example_prediction_selected_A_temp example_prediction_selected_C_temp = 0 else: example_prediction_selected_C_temp = \ subsession.session.num_participants - 1 - example_prediction_selected_A_temp - \ example_prediction_selected_B_temp example_prediction_selected_A.append(example_prediction_selected_A_temp) example_prediction_selected_B.append(example_prediction_selected_B_temp) example_prediction_selected_C.append(example_prediction_selected_C_temp) subsession.session.example_prediction_A = random.randint( int(round((subsession.session.num_participants - 1) * 0.2, 0)), int(round((subsession.session.num_participants - 1) * 0.7, 0))) subsession.session.example_prediction_B = random.randint( int(round((subsession.session.num_participants - 1) * 0.2, 0)), (int(round((subsession.session.num_participants - 1) * 0.7, 0)))) if subsession.session.example_prediction_B + subsession.session.example_prediction_A >= \ subsession.session.num_participants - 1: subsession.session.example_prediction_B = subsession.session.num_participants - 1 - \ subsession.session.example_prediction_A subsession.session.example_prediction_C = 0 else: subsession.session.example_prediction_C = \ subsession.session.num_participants - 1 - subsession.session.example_prediction_A - \ subsession.session.example_prediction_B Pred_A_temp = subsession.session.example_prediction_A / (subsession.session.num_participants - 1) Pred_B_temp = subsession.session.example_prediction_B / (subsession.session.num_participants - 1) Pred_C_temp = subsession.session.example_prediction_C / (subsession.session.num_participants - 1) factor1_temp = Pred_A_temp * Pred_A_temp + Pred_B_temp * Pred_B_temp + Pred_C_temp * Pred_C_temp subsession.session.example_prediction_payoff_A = round( C.quadratic_score_A + C.quadratic_score_B * (2 * Pred_A_temp - factor1_temp), 1) subsession.session.example_prediction_payoff_B = round( C.quadratic_score_A + C.quadratic_score_B * (2 * Pred_B_temp - factor1_temp), 1) subsession.session.example_prediction_payoff_C = round( C.quadratic_score_A + C.quadratic_score_B * (2 * Pred_C_temp - factor1_temp), 1) subsession.session.player_temp_AB_ = [1] * (C.num_CE + 1) subsession.session.player_temp_AB_[0] = random.randint(1, 2) for i in range(0, (C.num_CE + 1)): subsession.session.player_temp_AB_[i] = random.randint(1, 2) for p in subsession.get_players(): # what is contador? p.participant.contador = 1 p.participant.player_temp_AB = subsession.session.player_temp_AB_ # CHANGED FROM ORIGINAL p.participant.num_players = C.PLAYERS_PER_GROUP p.participant.group_pre_A = 0 p.participant.group_pre_B = 0 p.participant.group_pre_C = 0 p.participant.group_elec = 0 p.participant.random_choice = 0 p.participant.Test_choices_A = \ random.randint(0, subsession.session.other_part) p.participant.Test_choices_B = \ random.randint(0, subsession.session.other_part - p.participant.Test_choices_A) p.participant.Test_choices_C = \ subsession.session.other_part - p.participant.Test_choices_B - p.participant.Test_choices_A p.participant.Test_choices_A_pred = \ round(random.random() * subsession.session.other_part, 1) p.participant.Test_choices_B_pred = \ round(random.random() * (subsession.session.other_part - p.participant.Test_choices_A_pred), 1) p.participant.Test_choices_C_pred = \ subsession.session.other_part - p.participant.Test_choices_A_pred - p.participant.Test_choices_B_pred Pred_A = p.participant.Test_choices_A_pred / subsession.session.other_part Pred_B = p.participant.Test_choices_B_pred / subsession.session.other_part Pred_C = p.participant.Test_choices_C_pred / subsession.session.other_part factor1 = Pred_A * Pred_A + Pred_B * Pred_B + Pred_C * Pred_C p.participant.Test_payoff_a_pred = round(C.quadratic_score_A + C.quadratic_score_B * (2 * Pred_A - factor1), 1) p.participant.Test_payoff_b_pred = round(C.quadratic_score_A + C.quadratic_score_B * (2 * Pred_B - factor1), 1) p.participant.Test_payoff_c_pred = round(C.quadratic_score_A + C.quadratic_score_B * (2 * Pred_C - factor1), 1) p.participant.num_prob_replace = 1 p.participant.num_prob_not_replace = 1 p.participant.num_Test_choices_A_prob = 1 p.participant.num_Test_choices_B_prob = 1 p.participant.num_Test_choices_C_prob = 1 p.participant.num_payoff_A_guess = 1 p.participant.num_payoff_B_guess = 1 p.participant.num_payoff_C_guess = 1 p.participant.num_Test_choices_A_pred = 1 p.participant.num_Test_choices_B_pred = 1 p.participant.num_Test_choices_C_pred = 1 p.participant.num_Test_payoff_a_pred = 1 p.participant.num_Test_payoff_b_pred = 1 p.participant.num_Test_payoff_c_pred = 1 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 = replace_pred for w in subsession.get_groups(): w.binding_sit = random.randint(1, subsession.session.num_participants) class Group(BaseGroup): binding_sit = models.IntegerField(initial=0) sum_binding_sit_1 = models.IntegerField(initial=0) sum_binding_sit_2 = models.IntegerField(initial=0) sum_binding_sit_3 = models.IntegerField(initial=0) id_player_groupA = models.StringField(initial='') id_player_groupB = models.StringField(initial='') id_player_groupC = models.StringField(initial='') list_pred_A_A = models.StringField(initial='') list_pred_A_B = models.StringField(initial='') list_pred_A_C = models.StringField(initial='') list_pred_B_A = models.StringField(initial='') list_pred_B_B = models.StringField(initial='') list_pred_B_C = models.StringField(initial='') list_pred_C_A = models.StringField(initial='') list_pred_C_B = models.StringField(initial='') list_pred_C_C = models.StringField(initial='') list_aux_A_A = models.StringField(initial='') list_aux_A_B = models.StringField(initial='') list_aux_A_C = models.StringField(initial='') list_aux_B_A = models.StringField(initial='') list_aux_B_B = models.StringField(initial='') list_aux_B_C = models.StringField(initial='') list_aux_C_A = models.StringField(initial='') list_aux_C_B = models.StringField(initial='') list_aux_C_C = models.StringField(initial='') def choice_binding(player, group): if group.binding_sit == 1: return player.participant.CE_choice_1 if group.binding_sit == 2: return player.participant.CE_choice_2 if group.binding_sit == 3: return player.participant.CE_choice_3 if group.binding_sit == 4: return player.participant.CE_choice_4 if group.binding_sit == 5: return player.participant.CE_choice_5 if group.binding_sit == 6: return player.participant.CE_choice_6 if group.binding_sit == 7: return player.participant.CE_choice_7 if group.binding_sit == 8: return player.participant.CE_choice_8 if group.binding_sit == 9: return player.participant.CE_choice_9 def group_pre_A_(player): if player.group.binding_sit == 1: return player.CE1_pred_A if player.group.binding_sit == 2: return player.CE2_pred_A if player.group.binding_sit == 3: return player.CE3_pred_A if player.group.binding_sit == 4: return player.CE4_pred_A if player.group.binding_sit == 5: return player.CE5_pred_A if player.group.binding_sit == 5: return player.CE5_pred_A if player.group.binding_sit == 6: return player.CE6_pred_A if player.group.binding_sit == 7: return player.CE7_pred_A if player.group.binding_sit == 8: return player.CE8_pred_A if player.group.binding_sit == 9: return player.CE9_pred_A def group_pre_B_(player): if player.group.binding_sit == 1: return player.CE1_pred_B if player.group.binding_sit == 2: return player.CE2_pred_B if player.group.binding_sit == 3: return player.CE3_pred_B if player.group.binding_sit == 4: return player.CE4_pred_B if player.group.binding_sit == 5: return player.CE5_pred_B if player.group.binding_sit == 6: return player.CE6_pred_B if player.group.binding_sit == 7: return player.CE7_pred_B if player.group.binding_sit == 8: return player.CE8_pred_B if player.group.binding_sit == 9: return player.CE9_pred_B def group_pre_C_(player): if player.group.binding_sit == 1: return player.CE1_pred_C if player.group.binding_sit == 2: return player.CE2_pred_C if player.group.binding_sit == 3: return player.CE3_pred_C if player.group.binding_sit == 4: return player.CE4_pred_C if player.group.binding_sit == 5: return player.CE5_pred_C if player.group.binding_sit == 6: return player.CE6_pred_C if player.group.binding_sit == 7: return player.CE7_pred_C if player.group.binding_sit == 8: return player.CE8_pred_C if player.group.binding_sit == 9: return player.CE9_pred_C def make_field_prediction(label): return models.IntegerField( label=label, min=0, default=0, ) def make_field(label): return models.IntegerField( choices=[[1, "A"], [2, "B"], [3, "Nessun"]], label=label, widget=widgets.RadioSelect, blank=False, ) class Player(BasePlayer): # Choices in each choice situation CE_choice = models.IntegerField( choices=[[1, "A"], [2, "B"], [3, "Nessun"]], label="DCE Choice situation", widget=widgets.RadioSelect, blank=False, ) # Bottle choice CE_choice_aux = models.IntegerField( choices=[[1, "A"], [2, "B"], [3, "Nessun"]], label="Auxilliary Choice situation", widget=widgets.RadioSelect, blank=False, ) ##Prediction of each Choice situtation #CE1 CE1_pred_A = make_field_prediction('CE1_A') CE1_pred_B = make_field_prediction("CE1_B") CE1_pred_C = make_field_prediction("CE1_C") #CE2 CE2_pred_A = make_field_prediction("CE2_A") CE2_pred_B = make_field_prediction("CE2_B") CE2_pred_C = make_field_prediction("CE2_C") #CE3 CE3_pred_A = make_field_prediction("CE3_A") CE3_pred_B = make_field_prediction("CE3_B") CE3_pred_C = make_field_prediction("CE3_C") # CE3 CE4_pred_A = make_field_prediction("CE4_A") CE4_pred_B = make_field_prediction("CE4_B") CE4_pred_C = make_field_prediction("CE4_C") # CE3 CE5_pred_A = make_field_prediction("CE5_A") CE5_pred_B = make_field_prediction("CE5_B") CE5_pred_C = make_field_prediction("CE5_C") # CE3 CE6_pred_A = make_field_prediction("CE6_A") CE6_pred_B = make_field_prediction("CE6_B") CE6_pred_C = make_field_prediction("CE6_C") # CE6 CE7_pred_A = make_field_prediction("CE7_A") CE7_pred_B = make_field_prediction("CE7_B") CE7_pred_C = make_field_prediction("CE7_C") # CE8 CE8_pred_A = make_field_prediction("CE8_A") CE8_pred_B = make_field_prediction("CE8_B") CE8_pred_C = make_field_prediction("CE8_C") # CE9 CE9_pred_A = make_field_prediction("CE9_A") CE9_pred_B = make_field_prediction("CE9_B") CE9_pred_C = make_field_prediction("CE9_C") # CE10 CE10_pred_A = make_field_prediction("CE9_A") CE10_pred_B = make_field_prediction("CE9_B") CE10_pred_C = make_field_prediction("CE9_C") # Payoffs payoff1_a = models.CurrencyField() payoff1_b = models.CurrencyField() payoff1_c = models.CurrencyField() payoff2_a = models.CurrencyField() payoff2_b = models.CurrencyField() payoff2_c = models.CurrencyField() payoff3_a = models.CurrencyField() payoff3_b = models.CurrencyField() payoff3_c = models.CurrencyField() payoff4_a = models.CurrencyField() payoff4_b = models.CurrencyField() payoff4_c = models.CurrencyField() payoff5_a = models.CurrencyField() payoff5_b = models.CurrencyField() payoff5_c = models.CurrencyField() payoff6_a = models.CurrencyField() payoff6_b = models.CurrencyField() payoff6_c = models.CurrencyField() payoff7_a = models.CurrencyField() payoff7_b = models.CurrencyField() payoff7_c = models.CurrencyField() payoff8_a = models.CurrencyField() payoff8_b = models.CurrencyField() payoff8_c = models.CurrencyField() payoff9_a = models.CurrencyField() payoff9_b = models.CurrencyField() payoff9_c = models.CurrencyField() payoff10_a = models.CurrencyField() payoff10_b = models.CurrencyField() payoff10_c = models.CurrencyField() # Choices list list_choices_A = models.StringField(initial='') list_choices_B = models.StringField(initial='') list_choices_C = models.StringField(initial='') frequency_prediction = models.BooleanField() # frequency_prediction_2 = models.BooleanField() # frequency_prediction_3 = models.BooleanField() # frequency_prediction_4 = models.BooleanField() # frequency_prediction_5 = models.BooleanField() # frequency_prediction_6 = models.BooleanField() # frequency_prediction_7 = models.BooleanField() # frequency_prediction_8 = models.BooleanField() # frequency_prediction_9 = models.BooleanField() # frequency_prediction_10 = models.BooleanField() #Auxilliary questions CE_choice_1_aux = make_field('Scelta') CE_choice_2_aux = make_field('Scelta') CE_choice_3_aux = make_field('Scelta') CE_choice_4_aux = make_field('Scelta') CE_choice_5_aux = make_field('Scelta') CE_choice_6_aux = make_field('Scelta') CE_choice_7_aux = make_field('Scelta') CE_choice_8_aux = make_field('Scelta') CE_choice_9_aux = make_field('Scelta') CE_choice_10_aux = make_field('Scelta') group_elec = models.IntegerField() beliefs = models.IntegerField( choices=[[1, "1"], [2, "2"], [3, "3"], [4, "4"], [5, "5"]], widget=widgets.RadioSelectHorizontal) risk_1 = models.IntegerField(widget=widgets.RadioSelectHorizontal, choices=[[1, "Decisamente no"], [2, '2'], [3, '3'], [4, '4'], [5, "Decisamente sì"]]) risk_2 = models.IntegerField(widget=widgets.RadioSelectHorizontal, choices=[[1, "Decisamente no"], [2, '2'], [3, '3'], [4, '4'], [5, "Decisamente sì"]]) age = models.IntegerField(min=1900, max=2004) gender = models.StringField(widget=widgets.RadioSelect, choices=['Maschio', 'Femmina', 'Transgender', 'Non binario/non conforme', 'Preferisco non rispondere']) student = models.BooleanField(widget=widgets.RadioSelect, choices=['Sì','No']) study_area = models.StringField(label='Campo di studio') income = models.IntegerField(label='Reddito') payoff_bonus = models.CurrencyField() pounds = models.CurrencyField() ##################################### PAGES #################################################### class InstrWaitPage(WaitPage): group_by_arrival_time = True @staticmethod def is_displayed(player): return player.round_number == 1 title_text = "Ti chiediamo gentilmente di attenderre" body_text = "Attendi che si formi un gruppo di giocatori" class CM_1(Page): @staticmethod def is_displayed(player: Player): return player.participant.treatment_p < 9 form_model = 'player' form_fields = ['CE1_pred_A', 'CE1_pred_B', 'CE1_pred_C'] @staticmethod def live_method(player: Player, data): if data['clicked_button'] == 1: a = float(data['fieldA']) / (C.PLAYERS_PER_GROUP - 1) b = float(data['fieldB']) / (C.PLAYERS_PER_GROUP - 1) c = float(data['fieldC']) / (C.PLAYERS_PER_GROUP - 1) factor1 = a * a + b * b + c * c payoff_a = round(C.quadratic_score_A + C.quadratic_score_B * (2 * a - factor1), 1) payoff_b = round(C.quadratic_score_A + C.quadratic_score_B * (2 * b - factor1), 1) payoff_c = round(C.quadratic_score_A + C.quadratic_score_B * (2 * c - factor1), 1) response = dict(payoff_a=payoff_a, payoff_b=payoff_b, payoff_c=payoff_c) player.payoff1_a = payoff_a player.payoff1_b = payoff_b player.payoff1_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.PLAYERS_PER_GROUP, tempA=0, tempB=0, tempC=0) @staticmethod def error_message(player, values): if values['CE1_pred_A'] + values['CE1_pred_B'] + values[ 'CE1_pred_C'] != ( C.PLAYERS_PER_GROUP - 1): return 'La somma delle predizioni deve essere uguale a ' + str(C.PLAYERS_PER_GROUP - 1) def vars_for_template(player: Player): price_pair = player.participant.price_list[0] level1 = price_pair[0] level2 = price_pair[1] return dict(level1=level1, level2=level2, group_size=C.PLAYERS_PER_GROUP - 1) # # For dropouts # @staticmethod # def get_timeout_seconds(player): # participant = player.participant # # if participant.is_dropout: # return 1 # instant timeout, 1 second # else: # return 5*60 # # @staticmethod # def before_next_page(player, timeout_happened): # participant = player.participant # # if timeout_happened: # player.CE1_pred_A = 9 # player.CE1_pred_B = 9 # player.CE1_pred_C = 9 # participant.is_dropout = True class CM_1_aux(Page): @staticmethod def is_displayed(player: Player): return player.participant.treatment_p == 9 form_model = 'player' form_fields = ['CE_choice_1_aux'] def vars_for_template(player: Player): price_pair = player.participant.price_list_aux[0] level1 = price_pair[0] level2 = price_pair[1] return dict(level1=level1, level2=level2) class CM_2(Page): @staticmethod def is_displayed(player: Player): return player.participant.treatment_p < 9 form_model = 'player' form_fields = ['CE2_pred_A', 'CE2_pred_B', 'CE2_pred_C'] @staticmethod def live_method(player: Player, data): if data['clicked_button'] == 1: a = float(data['fieldA']) / (C.PLAYERS_PER_GROUP - 1) b = float(data['fieldB']) / (C.PLAYERS_PER_GROUP - 1) c = float(data['fieldC']) / (C.PLAYERS_PER_GROUP - 1) factor1 = a * a + b * b + c * c payoff_a = round(C.quadratic_score_A + C.quadratic_score_B * (2 * a - factor1), 1) payoff_b = round(C.quadratic_score_A + C.quadratic_score_B * (2 * b - factor1), 1) payoff_c = round(C.quadratic_score_A + C.quadratic_score_B * (2 * c - factor1), 1) response = dict(payoff_a=payoff_a, payoff_b=payoff_b, payoff_c=payoff_c) player.payoff2_a = payoff_a player.payoff2_b = payoff_b player.payoff2_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.PLAYERS_PER_GROUP, tempA=0, tempB=0, tempC=0) @staticmethod def error_message(player, values): if values['CE2_pred_A'] + values['CE2_pred_B'] + values[ 'CE2_pred_C'] != ( C.PLAYERS_PER_GROUP - 1): return 'La somma delle predizioni deve essere uguale a ' + str(C.PLAYERS_PER_GROUP - 1) def vars_for_template(player: Player): price_pair = player.participant.price_list[1] level1 = price_pair[0] level2 = price_pair[1] return dict(level1=level1, level2=level2, group_size=C.PLAYERS_PER_GROUP - 1) class CM_2_aux(Page): @staticmethod def is_displayed(player: Player): return player.participant.treatment_p == 9 form_model = 'player' form_fields = ['CE_choice_2_aux'] def vars_for_template(player: Player): price_pair = player.participant.price_list_aux[1] level1 = price_pair[0] level2 = price_pair[1] return dict(level1=level1, level2=level2) class CM_3(Page): @staticmethod def is_displayed(player: Player): return player.participant.treatment_p < 9 form_model = 'player' form_fields = ['CE3_pred_A', 'CE3_pred_B', 'CE3_pred_C'] @staticmethod def live_method(player: Player, data): if data['clicked_button'] == 1: a = float(data['fieldA']) / (C.PLAYERS_PER_GROUP - 1) b = float(data['fieldB']) / (C.PLAYERS_PER_GROUP - 1) c = float(data['fieldC']) / (C.PLAYERS_PER_GROUP - 1) factor1 = a * a + b * b + c * c payoff_a = round(C.quadratic_score_A + C.quadratic_score_B * (2 * a - factor1), 1) payoff_b = round(C.quadratic_score_A + C.quadratic_score_B * (2 * b - factor1), 1) payoff_c = round(C.quadratic_score_A + C.quadratic_score_B * (2 * c - factor1), 1) response = dict(payoff_a=payoff_a, payoff_b=payoff_b, payoff_c=payoff_c) player.payoff3_a = payoff_a player.payoff3_b = payoff_b player.payoff3_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.PLAYERS_PER_GROUP, tempA=0, tempB=0, tempC=0) @staticmethod def error_message(player, values): if values['CE3_pred_A'] + values['CE3_pred_B'] + values[ 'CE3_pred_C'] != ( C.PLAYERS_PER_GROUP - 1): return 'La somma delle predizioni deve essere uguale a ' + str(C.PLAYERS_PER_GROUP - 1) def vars_for_template(player: Player): price_pair = player.participant.price_list[2] level1 = price_pair[0] level2 = price_pair[1] return dict(level1=level1, level2=level2, group_size=C.PLAYERS_PER_GROUP - 1) class CM_3_aux(Page): @staticmethod def is_displayed(player: Player): return player.participant.treatment_p == 9 form_model = 'player' form_fields = ['CE_choice_3_aux'] def vars_for_template(player: Player): price_pair = player.participant.price_list_aux[2] level1 = price_pair[0] level2 = price_pair[1] return dict(level1=level1, level2=level2) class CM_4(Page): @staticmethod def is_displayed(player: Player): return player.participant.treatment_p < 9 form_model = 'player' form_fields = ['CE4_pred_A', 'CE4_pred_B', 'CE4_pred_C'] @staticmethod def live_method(player: Player, data): if data['clicked_button'] == 1: a = float(data['fieldA']) / (C.PLAYERS_PER_GROUP - 1) b = float(data['fieldB']) / (C.PLAYERS_PER_GROUP - 1) c = float(data['fieldC']) / (C.PLAYERS_PER_GROUP - 1) factor1 = a * a + b * b + c * c payoff_a = round(C.quadratic_score_A + C.quadratic_score_B * (2 * a - factor1), 1) payoff_b = round(C.quadratic_score_A + C.quadratic_score_B * (2 * b - factor1), 1) payoff_c = round(C.quadratic_score_A + C.quadratic_score_B * (2 * c - factor1), 1) response = dict(payoff_a=payoff_a, payoff_b=payoff_b, payoff_c=payoff_c) player.payoff4_a = payoff_a player.payoff4_b = payoff_b player.payoff4_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.PLAYERS_PER_GROUP, tempA=0, tempB=0, tempC=0) @staticmethod def error_message(player, values): if values['CE4_pred_A'] + values['CE4_pred_B'] + values[ 'CE4_pred_C'] != ( C.PLAYERS_PER_GROUP - 1): return 'La somma delle predizioni deve essere uguale a ' + str(C.PLAYERS_PER_GROUP - 1) def vars_for_template(player: Player): price_pair = player.participant.price_list[3] level1 = price_pair[0] level2 = price_pair[1] return dict(level1=level1, level2=level2, group_size=C.PLAYERS_PER_GROUP - 1) class CM_4_aux(Page): @staticmethod def is_displayed(player: Player): return player.participant.treatment_p == 9 form_model = 'player' form_fields = ['CE_choice_4_aux'] def vars_for_template(player: Player): price_pair = player.participant.price_list_aux[3] level1 = price_pair[0] level2 = price_pair[1] return dict(level1=level1, level2=level2) class CM_5(Page): @staticmethod def is_displayed(player: Player): return player.participant.treatment_p < 9 form_model = 'player' form_fields = ['CE5_pred_A', 'CE5_pred_B', 'CE5_pred_C'] @staticmethod def live_method(player: Player, data): if data['clicked_button'] == 1: a = float(data['fieldA']) / (C.PLAYERS_PER_GROUP - 1) b = float(data['fieldB']) / (C.PLAYERS_PER_GROUP - 1) c = float(data['fieldC']) / (C.PLAYERS_PER_GROUP - 1) factor1 = a * a + b * b + c * c payoff_a = round(C.quadratic_score_A + C.quadratic_score_B * (2 * a - factor1), 1) payoff_b = round(C.quadratic_score_A + C.quadratic_score_B * (2 * b - factor1), 1) payoff_c = round(C.quadratic_score_A + C.quadratic_score_B * (2 * c - factor1), 1) response = dict(payoff_a=payoff_a, payoff_b=payoff_b, payoff_c=payoff_c) player.payoff5_a = payoff_a player.payoff5_b = payoff_b player.payoff5_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.PLAYERS_PER_GROUP, tempA=0, tempB=0, tempC=0) @staticmethod def error_message(player, values): if values['CE5_pred_A'] + values['CE5_pred_B'] + values[ 'CE5_pred_C'] != ( C.PLAYERS_PER_GROUP - 1): return 'La somma delle predizioni deve essere uguale a ' + str(C.PLAYERS_PER_GROUP - 1) def vars_for_template(player: Player): price_pair = player.participant.price_list[4] level1 = price_pair[0] level2 = price_pair[1] return dict(level1=level1, level2=level2, group_size=C.PLAYERS_PER_GROUP - 1) class CM_5_aux(Page): @staticmethod def is_displayed(player: Player): return player.participant.treatment_p == 9 form_model = 'player' form_fields = ['CE_choice_5_aux'] def vars_for_template(player: Player): price_pair = player.participant.price_list_aux[4] level1 = price_pair[0] level2 = price_pair[1] return dict(level1=level1, level2=level2) class CM_6(Page): @staticmethod def is_displayed(player: Player): return player.participant.treatment_p < 9 form_model = 'player' form_fields = ['CE6_pred_A', 'CE6_pred_B', 'CE6_pred_C'] @staticmethod def live_method(player: Player, data): if data['clicked_button'] == 1: a = float(data['fieldA']) / (C.PLAYERS_PER_GROUP - 1) b = float(data['fieldB']) / (C.PLAYERS_PER_GROUP - 1) c = float(data['fieldC']) / (C.PLAYERS_PER_GROUP - 1) factor1 = a * a + b * b + c * c payoff_a = round(C.quadratic_score_A + C.quadratic_score_B * (2 * a - factor1), 1) payoff_b = round(C.quadratic_score_A + C.quadratic_score_B * (2 * b - factor1), 1) payoff_c = round(C.quadratic_score_A + C.quadratic_score_B * (2 * c - factor1), 1) response = dict(payoff_a=payoff_a, payoff_b=payoff_b, payoff_c=payoff_c) player.payoff6_a = payoff_a player.payoff6_b = payoff_b player.payoff6_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.PLAYERS_PER_GROUP, tempA=0, tempB=0, tempC=0) @staticmethod def error_message(player, values): if values['CE6_pred_A'] + values['CE6_pred_B'] + values[ 'CE6_pred_C'] != ( C.PLAYERS_PER_GROUP - 1): return 'La somma delle predizioni deve essere uguale a ' + str(C.PLAYERS_PER_GROUP - 1) def vars_for_template(player: Player): price_pair = player.participant.price_list[5] level1 = price_pair[0] level2 = price_pair[1] return dict(level1=level1, level2=level2, group_size=C.PLAYERS_PER_GROUP - 1) class CM_6_aux(Page): @staticmethod def is_displayed(player: Player): return player.participant.treatment_p == 9 form_model = 'player' form_fields = ['CE_choice_6_aux'] def vars_for_template(player: Player): price_pair = player.participant.price_list_aux[5] level1 = price_pair[0] level2 = price_pair[1] return dict(level1=level1, level2=level2) class CM_7(Page): @staticmethod def is_displayed(player: Player): return player.participant.treatment_p < 9 form_model = 'player' form_fields = ['CE7_pred_A', 'CE7_pred_B', 'CE7_pred_C'] @staticmethod def live_method(player: Player, data): if data['clicked_button'] == 1: a = float(data['fieldA']) / (C.PLAYERS_PER_GROUP - 1) b = float(data['fieldB']) / (C.PLAYERS_PER_GROUP - 1) c = float(data['fieldC']) / (C.PLAYERS_PER_GROUP - 1) factor1 = a * a + b * b + c * c payoff_a = round(C.quadratic_score_A + C.quadratic_score_B * (2 * a - factor1), 1) payoff_b = round(C.quadratic_score_A + C.quadratic_score_B * (2 * b - factor1), 1) payoff_c = round(C.quadratic_score_A + C.quadratic_score_B * (2 * c - factor1), 1) response = dict(payoff_a=payoff_a, payoff_b=payoff_b, payoff_c=payoff_c) player.payoff7_a = payoff_a player.payoff7_b = payoff_b player.payoff7_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.PLAYERS_PER_GROUP, tempA=0, tempB=0, tempC=0) @staticmethod def error_message(player, values): if values['CE7_pred_A'] + values['CE7_pred_B'] + values[ 'CE7_pred_C'] != ( C.PLAYERS_PER_GROUP - 1): return 'La somma delle predizioni deve essere uguale a ' + str(C.PLAYERS_PER_GROUP - 1) def vars_for_template(player: Player): price_pair = player.participant.price_list[6] level1 = price_pair[0] level2 = price_pair[1] return dict(level1=level1, level2=level2, group_size=C.PLAYERS_PER_GROUP - 1) class CM_7_aux(Page): @staticmethod def is_displayed(player: Player): return player.participant.treatment_p == 9 form_model = 'player' form_fields = ['CE_choice_7_aux'] def vars_for_template(player: Player): price_pair = player.participant.price_list_aux[6] level1 = price_pair[0] level2 = price_pair[1] return dict(level1=level1, level2=level2) class CM_8(Page): @staticmethod def is_displayed(player: Player): return player.participant.treatment_p < 9 form_model = 'player' form_fields = ['CE8_pred_A', 'CE8_pred_B', 'CE8_pred_C'] @staticmethod def live_method(player: Player, data): if data['clicked_button'] == 1: a = float(data['fieldA']) / (C.PLAYERS_PER_GROUP - 1) b = float(data['fieldB']) / (C.PLAYERS_PER_GROUP - 1) c = float(data['fieldC']) / (C.PLAYERS_PER_GROUP - 1) factor1 = a * a + b * b + c * c payoff_a = round(C.quadratic_score_A + C.quadratic_score_B * (2 * a - factor1), 1) payoff_b = round(C.quadratic_score_A + C.quadratic_score_B * (2 * b - factor1), 1) payoff_c = round(C.quadratic_score_A + C.quadratic_score_B * (2 * c - factor1), 1) response = dict(payoff_a=payoff_a, payoff_b=payoff_b, payoff_c=payoff_c) player.payoff8_a = payoff_a player.payoff8_b = payoff_b player.payoff8_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.PLAYERS_PER_GROUP, tempA=0, tempB=0, tempC=0) @staticmethod def error_message(player, values): if values['CE8_pred_A'] + values['CE8_pred_B'] + values[ 'CE8_pred_C'] != ( C.PLAYERS_PER_GROUP - 1): return 'La somma delle predizioni deve essere uguale a ' + str(C.PLAYERS_PER_GROUP - 1) def vars_for_template(player: Player): price_pair = player.participant.price_list[7] level1 = price_pair[0] level2 = price_pair[1] return dict(level1=level1, level2=level2, group_size=C.PLAYERS_PER_GROUP - 1) class CM_8_aux(Page): @staticmethod def is_displayed(player: Player): return player.participant.treatment_p == 9 form_model = 'player' form_fields = ['CE_choice_8_aux'] def vars_for_template(player: Player): price_pair = player.participant.price_list_aux[7] level1 = price_pair[0] level2 = price_pair[1] return dict(level1=level1, level2=level2) class CM_9(Page): @staticmethod def is_displayed(player: Player): return player.participant.treatment_p < 9 form_model = 'player' form_fields = ['CE9_pred_A', 'CE9_pred_B', 'CE9_pred_C'] @staticmethod def live_method(player: Player, data): if data['clicked_button'] == 1: a = float(data['fieldA']) / (C.PLAYERS_PER_GROUP - 1) b = float(data['fieldB']) / (C.PLAYERS_PER_GROUP - 1) c = float(data['fieldC']) / (C.PLAYERS_PER_GROUP - 1) factor1 = a * a + b * b + c * c payoff_a = round(C.quadratic_score_A + C.quadratic_score_B * (2 * a - factor1), 1) payoff_b = round(C.quadratic_score_A + C.quadratic_score_B * (2 * b - factor1), 1) payoff_c = round(C.quadratic_score_A + C.quadratic_score_B * (2 * c - factor1), 1) response = dict(payoff_a=payoff_a, payoff_b=payoff_b, payoff_c=payoff_c) player.payoff9_a = payoff_a player.payoff9_b = payoff_b player.payoff9_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.PLAYERS_PER_GROUP, tempA=0, tempB=0, tempC=0) @staticmethod def error_message(player, values): if values['CE9_pred_A'] + values['CE9_pred_B'] + values[ 'CE9_pred_C'] != ( C.PLAYERS_PER_GROUP - 1): return 'La somma delle predizioni deve essere uguale a ' + str(C.PLAYERS_PER_GROUP - 1) def vars_for_template(player: Player): price_pair = player.participant.price_list[8] level1 = price_pair[0] level2 = price_pair[1] return dict(level1=level1, level2=level2, group_size=C.PLAYERS_PER_GROUP - 1) class CM_9_aux(Page): @staticmethod def is_displayed(player: Player): return player.participant.treatment_p == 9 form_model = 'player' form_fields = ['CE_choice_9_aux'] def vars_for_template(player: Player): price_pair = player.participant.price_list_aux[8] level1 = price_pair[0] level2 = price_pair[1] return dict(level1=level1, level2=level2) class CM_10(Page): @staticmethod def is_displayed(player: Player): return player.participant.treatment_p < 9 form_model = 'player' form_fields = ['CE10_pred_A', 'CE10_pred_B', 'CE10_pred_C'] @staticmethod def live_method(player: Player, data): if data['clicked_button'] == 1: a = float(data['fieldA']) / (C.PLAYERS_PER_GROUP - 1) b = float(data['fieldB']) / (C.PLAYERS_PER_GROUP - 1) c = float(data['fieldC']) / (C.PLAYERS_PER_GROUP - 1) factor1 = a * a + b * b + c * c payoff_a = round(C.quadratic_score_A + C.quadratic_score_B * (2 * a - factor1), 1) payoff_b = round(C.quadratic_score_A + C.quadratic_score_B * (2 * b - factor1), 1) payoff_c = round(C.quadratic_score_A + C.quadratic_score_B * (2 * c - factor1), 1) response = dict(payoff_a=payoff_a, payoff_b=payoff_b, payoff_c=payoff_c) player.payoff10_a = payoff_a player.payoff10_b = payoff_b player.payoff10_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.PLAYERS_PER_GROUP, tempA=0, tempB=0, tempC=0) @staticmethod def error_message(player, values): if values['CE10_pred_A'] + values['CE10_pred_B'] + values[ 'CE10_pred_C'] != ( C.PLAYERS_PER_GROUP - 1): return 'La somma delle predizioni deve essere uguale a ' + str(C.PLAYERS_PER_GROUP - 1) def vars_for_template(player: Player): price_pair = player.participant.price_list[9] level1 = price_pair[0] level2 = price_pair[1] return dict(level1=level1, level2=level2, group_size=C.PLAYERS_PER_GROUP - 1) class CM_10_aux(Page): @staticmethod def is_displayed(player: Player): return player.participant.treatment_p == 9 form_model = 'player' form_fields = ['CE_choice_10_aux'] def vars_for_template(player: Player): price_pair = player.participant.price_list_aux[9] level1 = price_pair[0] level2 = price_pair[1] return dict(level1=level1, level2=level2) # Waiting page class WaitPageCM(WaitPage): title_text = "Ti chiediamo gentilmente di attendere" body_text = "Attendi che tutti i partecipanti abbiano completato la parte 1" def after_all_players_arrive(group: Group): randomlist = list(range(1, C.num_CE + 1)) random.shuffle(randomlist) group.binding_sit = randomlist[0] playerx = group.get_players() choices = [1] * playerx[1].participant.num_players sw = 0 cont = 1 while sw == 0: cont2 = 0 for p in group.in_round(1).get_players(): choices[cont2] = choice_binding(p, group) cont2 = cont2 + 1 if (choices.count(1) > 1 and choices.count(2) > 1 and choices.count(3) > 1) or \ (choices.count(1) > 1 and choices.count(2) > 1 and choices.count(3) == 0): sw = 1 else: group.binding_sit = randomlist[cont] cont = cont + 1 if cont == 9: sw = 1 for p in group.in_round(1).get_players(): p.participant.group_elec = choice_binding(p, group) p.participant.predA = group_pre_A_(p) p.participant.predB = group_pre_B_(p) p.participant.predC = group_pre_C_(p) group.sum_binding_sit_1 = p.participant.group_elec * (p.participant.group_elec == 1) + group.sum_binding_sit_1 group.sum_binding_sit_2 = int( p.participant.group_elec * (p.participant.group_elec == 2) / 2) + group.sum_binding_sit_2 group.sum_binding_sit_3 = int( p.participant.group_elec * (p.participant.group_elec == 3) / 3) + group.sum_binding_sit_3 group.id_player_groupA = str(p.id_in_group) * ( p.participant.group_elec == 1) + ',' + group.id_player_groupA group.id_player_groupB = str(p.id_in_group) * ( p.participant.group_elec == 2) + ',' + group.id_player_groupB group.id_player_groupC = str(p.id_in_group) * ( p.participant.group_elec == 3) + ',' + group.id_player_groupC group.list_pred_C_A = str(group_pre_A_(p)) * (p.participant.group_elec == 3) + ',' + group.list_pred_C_A group.list_pred_C_B = str(group_pre_B_(p)) * (p.participant.group_elec == 3) + ',' + group.list_pred_C_B group.list_pred_C_C = str(group_pre_C_(p)) * (p.participant.group_elec == 3) + ',' + group.list_pred_C_C group.list_pred_A_A = str(group_pre_A_(p)) * (p.participant.group_elec == 1) + ',' + group.list_pred_A_A group.list_pred_A_B = str(group_pre_B_(p)) * (p.participant.group_elec == 1) + ',' + group.list_pred_A_B group.list_pred_A_C = str(group_pre_C_(p)) * (p.participant.group_elec == 1) + ',' + group.list_pred_A_C group.list_pred_B_A = str(group_pre_A_(p)) * (p.participant.group_elec == 2) + ',' + group.list_pred_B_A group.list_pred_B_B = str(group_pre_B_(p)) * (p.participant.group_elec == 2) + ',' + group.list_pred_B_B group.list_pred_B_C = str(group_pre_C_(p)) * (p.participant.group_elec == 2) + ',' + group.list_pred_B_C for p in group.in_round(1).get_players(): if p.participant.group_elec == 1: p.list_choices_A = " ".join(['A'] * (group.sum_binding_sit_1 - 1)) p.list_choices_B = " ".join(['B'] * (group.sum_binding_sit_2)) p.list_choices_C = " ".join(['C'] * (group.sum_binding_sit_3)) list_pred_A_A_temp = group.list_pred_A_A list_pred_A_B_temp = group.list_pred_A_B list_pred_A_C_temp = group.list_pred_A_C list_pred_A_A_temp2 = list_pred_A_A_temp.split(",") list_pred_A_B_temp2 = list_pred_A_B_temp.split(",") list_pred_A_C_temp2 = list_pred_A_C_temp.split(",") list_pred_A_A_temp3 = [i for i in list_pred_A_A_temp2 if i] list_pred_A_B_temp3 = [i for i in list_pred_A_B_temp2 if i] list_pred_A_C_temp3 = [i for i in list_pred_A_C_temp2 if i] temp_id_resto_temp_ = group.id_player_groupA.split(",") temp_id_resto_temp_2 = [i for i in temp_id_resto_temp_ if i] index_remove = temp_id_resto_temp_2.index(str(p.id_in_group)) del list_pred_A_A_temp3[index_remove] del list_pred_A_B_temp3[index_remove] del list_pred_A_C_temp3[index_remove] p.participant.group_list_pred_A = list_pred_A_A_temp3 p.participant.group_list_pred_B = list_pred_A_B_temp3 p.participant.group_list_pred_C = list_pred_A_C_temp3 temp_id_resto = group.id_player_groupA.replace(str(p.id_in_group), "") temp_id_resto2 = temp_id_resto.split(",") p.participant.id_resto = [i for i in temp_id_resto2 if i] else: if p.participant.group_elec == 2: p.list_choices_A = " ".join(['A'] * (group.sum_binding_sit_1)) p.list_choices_B = " ".join(['B'] * (group.sum_binding_sit_2 - 1)) p.list_choices_C = " ".join(['C'] * (group.sum_binding_sit_3)) list_pred_B_A_temp = group.list_pred_B_A list_pred_B_B_temp = group.list_pred_B_B list_pred_B_C_temp = group.list_pred_B_C list_pred_B_A_temp2 = list_pred_B_A_temp.split(",") list_pred_B_B_temp2 = list_pred_B_B_temp.split(",") list_pred_B_C_temp2 = list_pred_B_C_temp.split(",") list_pred_B_A_temp3 = [i for i in list_pred_B_A_temp2 if i] list_pred_B_B_temp3 = [i for i in list_pred_B_B_temp2 if i] list_pred_B_C_temp3 = [i for i in list_pred_B_C_temp2 if i] temp_id_resto_temp_ = group.id_player_groupB.split(",") temp_id_resto_temp_2 = [i for i in temp_id_resto_temp_ if i] index_remove = temp_id_resto_temp_2.index(str(p.id_in_group)) del list_pred_B_A_temp3[index_remove] del list_pred_B_B_temp3[index_remove] del list_pred_B_C_temp3[index_remove] p.participant.group_list_pred_A = list_pred_B_A_temp3 p.participant.group_list_pred_B = list_pred_B_B_temp3 p.participant.group_list_pred_C = list_pred_B_C_temp3 temp_id_resto = group.id_player_groupB.replace(str(p.id_in_group), "") temp_id_resto2 = temp_id_resto.split(",") p.participant.id_resto = [i for i in temp_id_resto2 if i] else: p.list_choices_A = " ".join(['A'] * (group.sum_binding_sit_1)) p.list_choices_B = " ".join(['B'] * (group.sum_binding_sit_2)) p.list_choices_C = " ".join(['C'] * (group.sum_binding_sit_3 - 1)) list_pred_C_A_temp = group.list_pred_C_A list_pred_C_B_temp = group.list_pred_C_B list_pred_C_C_temp = group.list_pred_C_C list_pred_C_A_temp2 = list_pred_C_A_temp.split(",") list_pred_C_B_temp2 = list_pred_C_B_temp.split(",") list_pred_C_C_temp2 = list_pred_C_C_temp.split(",") list_pred_C_A_temp3 = [i for i in list_pred_C_A_temp2 if i] list_pred_C_B_temp3 = [i for i in list_pred_C_B_temp2 if i] list_pred_C_C_temp3 = [i for i in list_pred_C_C_temp2 if i] temp_id_resto_temp_ = group.id_player_groupC.split(",") temp_id_resto_temp_2 = [i for i in temp_id_resto_temp_ if i] index_remove = temp_id_resto_temp_2.index(str(p.id_in_group)) del list_pred_C_A_temp3[index_remove] del list_pred_C_B_temp3[index_remove] del list_pred_C_C_temp3[index_remove] p.participant.group_list_pred_A = list_pred_C_A_temp3 p.participant.group_list_pred_B = list_pred_C_B_temp3 p.participant.group_list_pred_C = list_pred_C_C_temp3 temp_id_resto = group.id_player_groupC.replace(str(p.id_in_group), "") temp_id_resto2 = temp_id_resto.split(",") p.participant.id_resto = [i for i in temp_id_resto2 if i] class fortune_wheel(Page): @staticmethod def js_vars(player): return dict(replace=player.participant.replace_predictions) @staticmethod def before_next_page(player, timeout_happened): if player.participant.random_draw == 1: player.CE_choice = player.participant.CE_choice_1 else: if player.participant.random_draw == 2: player.CE_choice = player.participant.CE_choice_2 else: if player.participant.random_draw == 3: player.CE_choice = player.participant.CE_choice_3 else: if player.participant.random_draw == 4: player.CE_choice = player.participant.CE_choice_4 else: if player.participant.random_draw == 5: player.CE_choice = player.participant.CE_choice_5 else: if player.participant.random_draw == 6: player.CE_choice = player.participant.CE_choice_6 else: if player.participant.random_draw == 7: player.CE_choice = player.participant.CE_choice_7 else: if player.participant.random_draw == 8: player.CE_choice = player.participant.CE_choice_8 else: if player.participant.random_draw == 9: player.CE_choice = player.participant.CE_choice_9 else: player.CE_choice = player.participant.CE_choice_10 class Results_no_replace(Page): def is_displayed(player: Player): return player.participant.replace_predictions == 0 and player.participant.treatment_p < 9 @staticmethod def vars_for_template(player): if player.participant.random_draw == 1: payoff_a = player.payoff1_a payoff_b = player.payoff1_b payoff_c = player.payoff1_c choice = player.participant.CE_choice_1 pred_A = player.CE1_pred_A pred_B = player.CE1_pred_B pred_C = player.CE1_pred_C price_pair = player.participant.price_list[0] cost_1 = price_pair[0] cost_2 = price_pair[1] else: if player.participant.random_draw == 2: payoff_a = player.payoff2_a payoff_b = player.payoff2_b payoff_c = player.payoff2_c choice = player.participant.CE_choice_2 pred_A = player.CE2_pred_A pred_B = player.CE2_pred_B pred_C = player.CE2_pred_C price_pair = player.participant.price_list[1] cost_1 = price_pair[0] cost_2 = price_pair[1] else: if player.participant.random_draw == 3: payoff_a = player.payoff3_a payoff_b = player.payoff3_b payoff_c = player.payoff3_c choice = player.participant.CE_choice_3 pred_A = player.CE3_pred_A pred_B = player.CE3_pred_B pred_C = player.CE3_pred_C price_pair = player.participant.price_list[2] cost_1 = price_pair[0] cost_2 = price_pair[1] else: if player.participant.random_draw == 4: payoff_a = player.payoff4_a payoff_b = player.payoff4_b payoff_c = player.payoff4_c choice = player.participant.CE_choice_4 pred_A = player.CE4_pred_A pred_B = player.CE4_pred_B pred_C = player.CE4_pred_C price_pair = player.participant.price_list[3] cost_1 = price_pair[0] cost_2 = price_pair[1] else: if player.participant.random_draw == 5: payoff_a = player.payoff5_a payoff_b = player.payoff5_b payoff_c = player.payoff5_c choice = player.participant.CE_choice_5 pred_A = player.CE5_pred_A pred_B = player.CE5_pred_B pred_C = player.CE5_pred_C price_pair = player.participant.price_list[4] cost_1 = price_pair[0] cost_2 = price_pair[1] else: if player.participant.random_draw == 6: payoff_a = player.payoff6_a payoff_b = player.payoff6_b payoff_c = player.payoff6_c choice = player.participant.CE_choice_6 pred_A = player.CE6_pred_A pred_B = player.CE6_pred_B pred_C = player.CE6_pred_C price_pair = player.participant.price_list[5] cost_1 = price_pair[0] cost_2 = price_pair[1] else: if player.participant.random_draw == 7: payoff_a = player.payoff7_a payoff_b = player.payoff7_b payoff_c = player.payoff7_c choice = player.participant.CE_choice_7 pred_A = player.CE7_pred_A pred_B = player.CE7_pred_B pred_C = player.CE7_pred_C price_pair = player.participant.price_list[6] cost_1 = price_pair[0] cost_2 = price_pair[1] else: if player.participant.random_draw == 8: payoff_a = player.payoff8_a payoff_b = player.payoff8_b payoff_c = player.payoff8_c choice = player.participant.CE_choice_8 pred_A = player.CE8_pred_A pred_B = player.CE8_pred_B pred_C = player.CE8_pred_C price_pair = player.participant.price_list[7] cost_1 = price_pair[0] cost_2 = price_pair[1] else: if player.participant.random_draw == 9: payoff_a = player.payoff9_a payoff_b = player.payoff9_b payoff_c = player.payoff9_c choice = player.participant.CE_choice_9 pred_A = player.CE9_pred_A pred_B = player.CE9_pred_B pred_C = player.CE9_pred_C price_pair = player.participant.price_list[8] cost_1 = price_pair[0] cost_2 = price_pair[1] else: payoff_a = player.payoff10_a payoff_b = player.payoff10_b payoff_c = player.payoff10_c choice = player.participant.CE_choice_10 pred_A = player.CE10_pred_A pred_B = player.CE10_pred_B pred_C = player.CE10_pred_C price_pair = player.participant.price_list[9] cost_1 = price_pair[0] cost_2 = price_pair[1] listA = player.list_choices_A.split() listB = player.list_choices_B.split() listC = player.list_choices_C.split() list_choices = listA + listC + listB player.participant.random_choice = random.choice(list_choices) if player.participant.random_choice == 'A': player.payoff_bonus = payoff_a else: if player.participant.random_choice == 'B': player.payoff_bonus = payoff_b else: player.payoff_bonus = payoff_c nr_pred_A = player.list_choices_A.count('A') nr_pred_B = player.list_choices_A.count('B') nr_pred_C = player.list_choices_A.count('C') if nr_pred_A == pred_A and nr_pred_B == pred_B and nr_pred_C == pred_C: player.frequency_prediction = 1 else: player.frequency_prediction = 0 return dict( num_participants=C.PLAYERS_PER_GROUP - 1, costs1=cost_1, costs2=cost_2, payoff_a=payoff_a, payoff_b=payoff_b, payoff_c=payoff_c, choice=choice, pred_A=pred_A, pred_B=pred_B, pred_C=pred_C, draw=player.participant.random_draw, listA=listA, listB=listB, listC=listC, nr_pred_A=nr_pred_A, nr_pred_B=nr_pred_B, nr_pred_C=nr_pred_C, frequency_prediction=player.frequency_prediction ) @staticmethod def js_vars(player): return dict(replace=player.participant.replace_predictions, random_choice=player.participant.random_choice) @staticmethod def before_next_page(player, timeout_happened): player.pounds = round(player.payoff_bonus * C.exchange_pounds, 1) class Results_no_replace_aux(Page): def is_displayed(player: Player): return player.participant.replace_predictions == 0 and player.participant.treatment_p == 9 @staticmethod def vars_for_template(player): if player.participant.random_draw == 1: player.CE_choice = player.participant.CE_choice_1 player.CE_choice_aux = player.CE_choice_1_aux price_pair = player.participant.price_list[0] level1 = price_pair[0] level2 = price_pair[1] else: if player.participant.random_draw == 2: player.CE_choice = player.participant.CE_choice_2 player.CE_choice_aux = player.CE_choice_2_aux price_pair = player.participant.price_list[1] level1 = price_pair[0] level2 = price_pair[1] else: if player.participant.random_draw == 3: player.CE_choice = player.participant.CE_choice_3 player.CE_choice_aux = player.CE_choice_3_aux price_pair = player.participant.price_list[2] level1 = price_pair[0] level2 = price_pair[1] else: if player.participant.random_draw == 4: player.CE_choice = player.participant.CE_choice_4 player.CE_choice_aux = player.CE_choice_4_aux price_pair = player.price_list[3] level1 = price_pair[0] level2 = price_pair[1] else: if player.participant.random_draw == 5: player.CE_choice = player.participant.CE_choice_5 player.CE_choice_aux = player.CE_choice_5_aux price_pair = player.participant.price_list[4] level1 = price_pair[0] level2 = price_pair[1] else: if player.participant.random_draw == 6: player.CE_choice = player.participant.CE_choice_6 player.CE_choice_aux = player.CE_choice_6_aux price_pair = player.participant.price_list[5] level1 = price_pair[0] level2 = price_pair[1] else: if player.participant.random_draw == 7: player.CE_choice = player.participant.CE_choice_7 player.CE_choice_aux = player.CE_choice_7_aux price_pair = player.participant.price_list[6] level1 = price_pair[0] level2 = price_pair[1] else: if player.participant.random_draw == 8: player.CE_choice = player.participant.CE_choice_8 player.CE_choice_aux = player.CE_choice_8_aux price_pair = player.participant.price_list[7] level1 = price_pair[0] level2 = price_pair[1] else: if player.participant.random_draw == 9: player.CE_choice = player.participant.CE_choice_9 player.CE_choice_aux = player.CE_choice_9_aux price_pair = player.participant.price_list[8] level1 = price_pair[0] level2 = price_pair[1] else: player.CE_choice = player.participant.CE_choice_10 player.CE_choice_aux = player.CE_choice_10_aux price_pair = player.participant.price_list[9] level1 = price_pair[0] level2 = price_pair[1] listA = player.list_choices_A.split() listB = player.list_choices_B.split() listC = player.list_choices_C.split() list_choices = listA + listC + listB player.participant.random_choice = random.choice(list_choices) if player.participant.random_choice == 'A': player.payoff_bonus = C.budget - level1 else: if player.participant.random_choice == 'B': player.payoff_bonus = C.budget - level2 else: player.payoff_bonus = C.budget return dict(costs1=level1, costs2=level2, num_participants=C.PLAYERS_PER_GROUP - 1, choice=player.CE_choice_aux, draw=player.participant.random_draw, listA=listA, listB=listB, listC=listC, payoff=player.payoff_bonus ) @staticmethod def js_vars(player): return dict(replace=player.participant.replace_predictions, random_choice=player.participant.random_choice) @staticmethod def before_next_page(player, timeout_happened): player.pounds = round(player.payoff_bonus * C.exchange_pounds, 1) class Results_replace(Page): def is_displayed(player: Player): return player.participant.replace_predictions == 1 and player.participant.treatment_p < 9 @staticmethod def vars_for_template(player): leng = len(player.participant.group_list_pred_A) if leng == 0: # sitation nobody else chose the individual choices random_prediction_A = random.randint( int(round((player.participant.num_players - 1) * 0.2, 0)), int(round((player.participant.num_players - 1) * 0.4, 0))) random_prediction_B = random.randint( int(round((player.participant.num_players - 1) * 0.2, 0)), (int(round((player.participant.num_players - 1) * 0.4, 0)))) random_prediction_C = player.participant.num_players - 1 - random_prediction_A - random_prediction_B if player.participant.group_elec == 1: player.list_choices_A = "A" lenb = len(player.list_choices_B.split()) lenc = len(player.list_choices_C.split()) if lenb > lenc: player.list_choices_B = \ player.list_choices_B.replace("B", "", 1) else: player.list_choices_C = \ player.list_choices_C.replace("C", "", 1) if player.participant.group_elec == 2: player.list_choices_B = "B" lena = len(player.list_choices_A.split()) lenc = len(player.list_choices_C.split()) if lena > lenc: player.list_choices_A = \ player.list_choices_A.replace("A", "", 1) else: player.list_choices_C = \ player.list_choices_C.replace("C", "", 1) if player.participant.group_elec == 3: player.list_choices_C = 'C' lena = len(player.list_choices_A.split()) lenb = len(player.list_choices_B.split()) if lena > lenb: player.list_choices_A = \ player.list_choices_A.replace('A', '', 1) else: player.list_choices_B = \ player.list_choices_B.replace('B', '', 1) player.participant.id_resto = [random.randint(1, player.participant.num_players)] id_resto = {0: player.participant.id_resto[0]} example_prediction_selected_A = {0: random_prediction_A} example_prediction_selected_B = {0: random_prediction_B} example_prediction_selected_C = {0: random_prediction_C} player.participant.group_list_pred_A = [random_prediction_A] player.participant.group_list_pred_B = [random_prediction_B] player.participant.group_list_pred_C = [random_prediction_C] listA_2 = id_resto leng = 1 else: id_resto = {i: player.participant.id_resto[i] for i in range(0, leng)} # Corresponding predictions of other players example_prediction_selected_A = {i: player.participant.group_list_pred_A[i] for i in range(0, leng)} example_prediction_selected_B = {i: player.participant.group_list_pred_B[i] for i in range(0, leng)} example_prediction_selected_C = {i: player.participant.group_list_pred_C[i] for i in range(0, leng)} listA_2 = {i: player.participant.id_resto[i] for i in range(0, leng)} integersA = [int(i) for i in player.participant.group_list_pred_A] integersB = [int(i) for i in player.participant.group_list_pred_B] integersC = [int(i) for i in player.participant.group_list_pred_C] selected_id = random.randint(0, len(listA_2)-1) replaced_A = integersA[selected_id] replaced_B = integersB[selected_id] replaced_C = integersC[selected_id] cont = list(range(0, leng)) if player.participant.random_draw == 1: pred_A = player.CE1_pred_A pred_B = player.CE1_pred_B pred_C = player.CE1_pred_C player.CE_choice = player.participant.CE_choice_1 price_pair = player.participant.price_list[0] cost_1 = price_pair[0] cost_2 = price_pair[1] else: if player.participant.random_draw == 2: pred_A = player.CE2_pred_A pred_B = player.CE2_pred_B pred_C = player.CE2_pred_C player.CE_choice = player.participant.CE_choice_2 price_pair = player.participant.price_list[1] cost_1 = price_pair[0] cost_2 = price_pair[1] else: if player.participant.random_draw == 3: pred_A = player.CE3_pred_A pred_B = player.CE3_pred_B pred_C = player.CE3_pred_C player.CE_choice = player.participant.CE_choice_3 price_pair = player.participant.price_list[2] cost_1 = price_pair[0] cost_2 = price_pair[1] else: if player.participant.random_draw == 4: pred_A = player.CE4_pred_A pred_B = player.CE4_pred_B pred_C = player.CE4_pred_C player.CE_choice = player.participant.CE_choice_4 price_pair = player.participant.price_list[3] cost_1 = price_pair[0] cost_2 = price_pair[1] else: if player.participant.random_draw == 5: pred_A = player.CE5_pred_A pred_B = player.CE5_pred_B pred_C = player.CE5_pred_C player.CE_choice = player.participant.CE_choice_5 price_pair = player.participant.price_list[4] cost_1 = price_pair[0] cost_2 = price_pair[1] else: if player.participant.random_draw == 6: pred_A = player.CE6_pred_A pred_B = player.CE6_pred_B pred_C = player.CE6_pred_C player.CE_choice = player.participant.CE_choice_6 price_pair = player.participant.price_list[5] cost_1 = price_pair[0] cost_2 = price_pair[1] else: if player.participant.random_draw == 7: pred_A = player.CE7_pred_A pred_B = player.CE7_pred_B pred_C = player.CE7_pred_C player.CE_choice = player.participant.CE_choice_7 price_pair = player.participant.price_list[6] cost_1 = price_pair[0] cost_2 = price_pair[1] else: if player.participant.random_draw == 8: pred_A = player.CE8_pred_A pred_B = player.CE8_pred_B pred_C = player.CE8_pred_C player.CE_choice = player.participant.CE_choice_8 price_pair = player.participant.price_list[7] cost_1 = price_pair[0] cost_2 = price_pair[1] else: if player.participant.random_draw == 9: pred_A = player.CE9_pred_A pred_B = player.CE9_pred_B pred_C = player.CE9_pred_C player.CE_choice = player.participant.CE_choice_9 price_pair = player.participant.price_list[8] cost_1 = price_pair[0] cost_2 = price_pair[1] else: pred_A = player.CE10_pred_A pred_B = player.CE10_pred_B pred_C = player.CE10_pred_C player.CE_choice = player.participant.CE_choice_10 price_pair = player.participant.price_list[9] cost_1 = price_pair[0] cost_2 = price_pair[1] Pred_A = replaced_A / (player.participant.num_players - 1) Pred_B = replaced_B / (player.participant.num_players - 1) Pred_C = replaced_C / (player.participant.num_players - 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), 1) payoff_b = round(C.quadratic_score_A + C.quadratic_score_B * (2 * Pred_B - factor1), 1) payoff_c = round(C.quadratic_score_A + C.quadratic_score_B * (2 * Pred_C - factor1), 1) listA = player.list_choices_A.split() listB = player.list_choices_B.split() listC = player.list_choices_C.split() list_choices = listA + listC + listB player.participant.random_choice = random.choice(list_choices) if player.participant.random_choice == 'A': player.payoff_bonus = payoff_a else: if player.participant.random_choice == 'B': player.payoff_bonus = payoff_b else: player.payoff_bonus = payoff_c nr_pred_A = player.list_choices_A.count('A') nr_pred_B = player.list_choices_A.count('B') nr_pred_C = player.list_choices_A.count('C') if nr_pred_A == replaced_A and nr_pred_B == replaced_B and nr_pred_C == replaced_C: player.frequency_prediction = 1 else: player.frequency_prediction = 0 return dict(id_resto=id_resto, example_prediction_selected_A=example_prediction_selected_A, example_prediction_selected_B=example_prediction_selected_B, example_prediction_selected_C=example_prediction_selected_C, # listA=listA_2, cont=cont, replaced_A=replaced_A, replaced_B=replaced_B, replaced_C=replaced_C, costs1=cost_1, costs2=cost_2, num_participants=C.PLAYERS_PER_GROUP - 1, payoff_a=payoff_a, payoff_b=payoff_b, payoff_c=payoff_c, nr_pred_A=nr_pred_A, nr_pred_B=nr_pred_B, nr_pred_C=nr_pred_C, CE_choice=player.CE_choice, pred_A=pred_A, pred_B=pred_B, pred_C=pred_C, draw=player.participant.random_draw, listA=listA, listB=listB, listC=listC, random_prediction_A=len(listA), random_prediction_B=len(listB), random_prediction_C=len(listC), frequency_prediction=player.frequency_prediction ) @staticmethod def js_vars(player): return dict(replace=player.participant.replace_predictions, random_choice=player.participant.random_choice) @staticmethod def before_next_page(player, timeout_happened): player.pounds = round(player.payoff_bonus * C.exchange_pounds, 1) # Replace results: T9 class Results_replace_aux(Page): def is_displayed(player: Player): return player.participant.replace_predictions == 1 and player.participant.treatment_p == 9 @staticmethod def vars_for_template(player): leng = len(player.participant.group_list_pred_A) if leng == 0: # situation nobody else chose the individual choices random_prediction_A = random.randint( int(round((player.participant.num_players - 1) * 0.2, 0)), int(round((player.participant.num_players - 1) * 0.4, 0))) random_prediction_B = random.randint( int(round((player.participant.num_players - 1) * 0.2, 0)), (int(round((player.participant.num_players - 1) * 0.4, 0)))) random_prediction_C = player.participant.num_players - 1 - random_prediction_A - random_prediction_B if player.participant.group_elec == 1: player.list_choices_A = "A" lenb = len(player.list_choices_B.split()) lenc = len(player.list_choices_C.split()) if lenb > lenc: player.list_choices_B = \ player.list_choices_B.replace("B", "", 1) else: player.list_choices_C = \ player.list_choices_C.replace("C", "", 1) if player.participant.group_elec == 2: player.list_choices_B = "B" lena = len(player.list_choices_A.split()) lenc = len(player.list_choices_C.split()) if lena > lenc: player.list_choices_A = \ player.list_choices_A.replace("A", "", 1) else: player.list_choices_C = \ player.list_choices_C.replace("C", "", 1) if player.participant.group_elec == 3: player.list_choices_C = 'C' lena = len(player.list_choices_A.split()) lenb = len(player.list_choices_B.split()) if lena > lenb: player.list_choices_A = \ player.list_choices_A.replace('A', '', 1) else: player.list_choices_B = \ player.list_choices_B.replace('B', '', 1) player.participant.id_resto = [random.randint(1, player.participant.num_players)] id_resto = {0: player.participant.id_resto[0]} example_prediction_selected_A = {0: random_prediction_A} example_prediction_selected_B = {0: random_prediction_B} example_prediction_selected_C = {0: random_prediction_C} player.participant.group_list_pred_A = [random_prediction_A] player.participant.group_list_pred_B = [random_prediction_B] player.participant.group_list_pred_C = [random_prediction_C] listA_2 = id_resto leng = 1 else: id_resto = {i: player.participant.id_resto[i] for i in range(0, leng)} # Corresponding predictions of other players example_prediction_selected_A = {i: player.participant.group_list_pred_A[i] for i in range(0, leng)} example_prediction_selected_B = {i: player.participant.group_list_pred_B[i] for i in range(0, leng)} example_prediction_selected_C = {i: player.participant.group_list_pred_C[i] for i in range(0, leng)} listA_2 = {i: player.participant.id_resto[i] for i in range(0, leng)} integersA = [int(i) for i in player.participant.group_list_pred_A] integersB = [int(i) for i in player.participant.group_list_pred_B] integersC = [int(i) for i in player.participant.group_list_pred_C] selected_id = random.randint(0, len(listA_2)-1) replaced_A = integersA[selected_id] replaced_B = integersB[selected_id] replaced_C = integersC[selected_id] print('A', replaced_A, 'B', replaced_B, 'C', replaced_C) cont = list(range(0, leng)) if player.participant.random_draw == 1: player.CE_choice = player.participant.CE_choice_1 player.CE_choice_aux = player.CE_choice_1_aux price_pair = player.participant.price_list[0] level1 = price_pair[0] level2 = price_pair[1] else: if player.participant.random_draw == 2: player.CE_choice = player.participant.CE_choice_2 player.CE_choice_aux = player.CE_choice_2_aux price_pair = player.participant.price_list[1] level1 = price_pair[0] level2 = price_pair[1] else: if player.participant.random_draw == 3: player.CE_choice = player.participant.CE_choice_3 player.CE_choice_aux = player.CE_choice_3_aux price_pair = player.participant.price_list[2] level1 = price_pair[0] level2 = price_pair[1] else: if player.participant.random_draw == 4: player.CE_choice = player.participant.CE_choice_4 player.CE_choice_aux = player.CE_choice_4_aux price_pair = player.participant.price_list[3] level1 = price_pair[0] level2 = price_pair[1] else: if player.participant.random_draw == 5: player.CE_choice = player.participant.CE_choice_5 player.CE_choice_aux = player.CE_choice_5_aux price_pair = player.participant.price_list[4] level1 = price_pair[0] level2 = price_pair[1] else: if player.participant.random_draw == 6: player.CE_choice = player.participant.CE_choice_6 player.CE_choice_aux = player.CE_choice_6_aux price_pair = player.participant.price_list[5] level1 = price_pair[0] level2 = price_pair[1] else: if player.participant.random_draw == 7: player.CE_choice = player.participant.CE_choice_7 player.CE_choice_aux = player.CE_choice_7_aux price_pair = player.participant.price_list[6] level1 = price_pair[0] level2 = price_pair[1] else: if player.participant.random_draw == 8: player.CE_choice = player.participant.CE_choice_8 player.CE_choice_aux = player.CE_choice_8_aux price_pair = player.participant.price_list[7] level1 = price_pair[0] level2 = price_pair[1] else: if player.participant.random_draw == 9: player.CE_choice = player.participant.CE_choice_9 player.CE_choice_aux = player.CE_choice_9_aux price_pair = player.participant.price_list[8] level1 = price_pair[0] level2 = price_pair[1] else: player.CE_choice = player.participant.CE_choice_10 player.CE_choice_aux = player.CE_choice_10_aux price_pair = player.participant.price_list[9] level1 = price_pair[0] level2 = price_pair[1] listA = player.list_choices_A.split() listB = player.list_choices_B.split() listC = player.list_choices_C.split() list_choices = listA + listC + listB player.participant.random_choice = random.choice(list_choices) if player.participant.random_choice == 'A': player.payoff_bonus = C.budget - level1 else: if player.participant.random_choice == 'B': player.payoff_bonus = C.budget - level2 else: player.payoff_bonus = C.budget return dict(id_resto=id_resto, example_prediction_selected_A=example_prediction_selected_A, example_prediction_selected_B=example_prediction_selected_B, example_prediction_selected_C=example_prediction_selected_C, # listA=listA_2, cont=cont, replaced_A=replaced_A, replaced_B=replaced_B, replaced_C=replaced_C, costs1=level1, costs2=level2, num_participants=C.PLAYERS_PER_GROUP - 1, choice=player.CE_choice_aux, CE_choice=player.CE_choice, draw=player.participant.random_draw, random_choice=player.participant.random_choice, listA=listA, listB=listB, listC=listC, payoff=player.payoff_bonus, ) @staticmethod def js_vars(player): return dict(replace=player.participant.replace_predictions, random_choice=player.participant.random_choice) @staticmethod def before_next_page(player, timeout_happened): player.pounds = round(player.payoff_bonus * C.exchange_pounds, 1) class Beliefs(Page): form_model = 'player' form_fields = ['beliefs'] class Questionnaire(Page): form_model = 'player' form_fields = ['risk_1', 'risk_2', 'age', 'gender', 'student', 'study_area', 'income'] class Final(Page): @staticmethod def is_displayed(player: Player): return player.participant.treatment_p < 9 @staticmethod def vars_for_template(player: Player): return dict(payoff=player.payoff_bonus, frequency_prediction=player.frequency_prediction, bonus_pounds=player.pounds) class Final_aux(Page): @staticmethod def is_displayed(player: Player): return player.participant.treatment_p == 9 @staticmethod def vars_for_template(player: Player): return dict(payoff=player.payoff_bonus, bonus_pounds=player.pounds, choice=player.CE_choice_aux) page_sequence = [ InstrWaitPage, CM_1, CM_2, CM_3, CM_4, CM_5, CM_6, CM_7, CM_8, CM_9, CM_10, CM_1_aux, CM_2_aux, CM_3_aux, CM_4_aux, CM_5_aux, CM_6_aux, CM_7_aux, CM_8_aux, CM_9_aux, CM_10_aux, WaitPageCM, # fortune_wheel, Beliefs, Questionnaire, Results_no_replace, Results_no_replace_aux, Results_replace, Results_replace_aux, Final, Final_aux ]