import random from otree.api import * author = 'Your name here' doc = """ Your app description """ class Constants(BaseConstants): name_in_url = 'third_party_one' players_per_group = 3 num_rounds = 5 instructionsInicio = 'third_party_one/instructionsInicio.html' instructionsGeneralA = 'third_party_one/instructionsGeneralA.html' instructionsGeneralB = 'third_party_one/instructionsGeneralB.html' instructionsGeneralC = 'third_party_one/instructionsGeneralC.html' instructionsEspA = 'third_party_one/InstructionsEspecificA.html' instructionsEspB = 'third_party_one/InstructionsEspecificB.html' instructionsEspC = 'third_party_one/InstructionsEspecificC.html' etapaUnoA = 'third_party_one/EtapaUnoA.html' etapaUnoB = 'third_party_one/EtapaUnoB.html' etapaUnoC = 'third_party_one/EtapaUnoC.html' etapaDosA = 'third_party_one/EtapaDosA.html' etapaDosB = 'third_party_one/EtapaDosB.html' etapaDosC = 'third_party_one/EtapaDosC.html' PcProdA = 'third_party_one/PcProcedureA.html' PcProdB = 'third_party_one/PcProcedureB.html' PcProdC = 'third_party_one/PcProcedureC.html' collapsed = 'third_party_one/collapseinstructions.html' endowmentA = cu(100) endowmentC = cu(50) multiplication_factor = 3 class Subsession(BaseSubsession): pass class Group(BaseGroup): sent_amount = models.CurrencyField(choices=[0, 10, 20, 30, 40, 50]) deduction_0 = models.CurrencyField( label="", min=0, max=Constants.endowmentC, ) deduction_10 = models.CurrencyField( label="", min=0, max=Constants.endowmentC, ) deduction_20 = models.CurrencyField( label="", min=0, max=Constants.endowmentC, ) deduction_30 = models.CurrencyField( label="", min=0, max=Constants.endowmentC, ) deduction_40 = models.CurrencyField( label="", min=0, max=Constants.endowmentC, ) deduction_50 = models.CurrencyField( label="", min=0, max=Constants.endowmentC, ) expectation_sent = models.CurrencyField( label="¿Cuántos puntos le dará a usted?", choices=[0, 10, 20, 30, 40, 50], min=0, max=Constants.endowmentA, ) expectation_return_0 = models.CurrencyField( label="", min=0, max=Constants.endowmentC, ) expectation_return_10 = models.CurrencyField( label="", min=0, max=Constants.endowmentC, ) expectation_return_20 = models.CurrencyField( label="", min=0, max=Constants.endowmentC, ) expectation_return_30 = models.CurrencyField( label="", min=0, max=Constants.endowmentC, ) expectation_return_40 = models.CurrencyField( label="", min=0, max=Constants.endowmentC, ) expectation_return_50 = models.CurrencyField( label="", min=0, max=Constants.endowmentC, ) expectation_social_norm_s1_B = models.IntegerField(initial=9, label="", choices=[ [0, "Muy socialmente inapropiada"], [1, "Algo socialmente inapropiada"], [2, "Algo socialmente apropiada"], [3, "Muy socialmente apropiada"], ], widget=widgets.RadioSelect, ) expectation_social_norm_s2_B = models.IntegerField(initial=9, label="", choices=[ [0, "Muy socialmente inapropiada"], [1, "Algo socialmente inapropiada"], [2, "Algo socialmente apropiada"], [3, "Muy socialmente apropiada"], ], widget=widgets.RadioSelect, ) expectation_social_norm_s1_C = models.IntegerField(initial=9, label="", choices=[ [0, "Muy socialmente inapropiada"], [1, "Algo socialmente inapropiada"], [2, "Algo socialmente apropiada"], [3, "Muy socialmente apropiada"], ], widget=widgets.RadioSelect, ) expectation_social_norm_s2_C = models.IntegerField(initial=9, label="", choices=[ [0, "Muy socialmente inapropiada"], [1, "Algo socialmente inapropiada"], [2, "Algo socialmente apropiada"], [3, "Muy socialmente apropiada"], ], widget=widgets.RadioSelect, ) class Player(BasePlayer): survey_10 = models.IntegerField(initial=0) survey_11 = models.IntegerField(initial=0) survey_12 = models.IntegerField(initial=0) survey_14 = models.IntegerField(initial=0) random_round = models.IntegerField() city = models.StringField() day = models.IntegerField(min=1, max=31) month = models.IntegerField(min=1, max=12) year = models.IntegerField(max=2022, min=2022, default=2022) hour = models.IntegerField(min=1, max=12) minutes = models.IntegerField(min=0, max=59) ampm = models.IntegerField(choices=[[0, 'AM'], [1, 'PM']]) name = models.StringField() signature = models.StringField() idcard = models.StringField() citycard = models.StringField() q1 = models.IntegerField(label="") q2 = models.IntegerField( choices=[[0, "Masculino"], [1, "Femenino"]], widget=widgets.RadioSelect ) q3 = models.IntegerField(label="") q4 = models.StringField(label="") q5 = models.IntegerField( choices=[ [0, "Pregrado"], [1, "Posgrado"], ], widget=widgets.RadioSelect, ) q6 = models.IntegerField(label="") q7 = models.IntegerField(choices=[[0, "Sí"], [1, "No"]], widget=widgets.RadioSelect) q8 = models.IntegerField(choices=[[0, "Sí"], [1, "No"]], widget=widgets.RadioSelect) q9 = models.IntegerField(min=0, max=100) q10 = models.IntegerField(label="") q11 = models.IntegerField( choices=[ [0, "0"], [1, "1"], [2, "2"], [3, "3"], [4, "4"], [5, "5"], [6, "6"], [7, "7"], [8, "8"], [9, "9"], [10, "10"], ], widget=widgets.RadioSelectHorizontal, ) q12 = models.IntegerField( choices=[ [0, "0"], [1, "1"], [2, "2"], [3, "3"], [4, "4"], [5, "5"], [6, "6"], [7, "7"], [8, "8"], [9, "9"], [10, "10"], ], widget=widgets.RadioSelectHorizontal, ) q13 = models.IntegerField( choices=[ [0, "0"], [1, "1"], [2, "2"], [3, "3"], [4, "4"], [5, "5"], [6, "6"], [7, "7"], [8, "8"], [9, "9"], [10, "10"], ], widget=widgets.RadioSelectHorizontal, ) q14 = models.IntegerField( choices=[ [0, "0"], [1, "1"], [2, "2"], [3, "3"], [4, "4"], [5, "5"], [6, "6"], [7, "7"], [8, "8"], [9, "9"], [10, "10"], ], widget=widgets.RadioSelectHorizontal, ) q15 = models.IntegerField( choices=[ [0, "1"], [1, "2"], [2, "3"], [3, "4"], [4, "5"], [5, "6"], [6, "No sabe/No Responde"], ], widget=widgets.RadioSelect, ) # # # # LA VIOLENCIA # # # q18 = models.LongStringField(label="") q19 = models.IntegerField( choices=[ [0, "0"], [1, "1"], [2, "2"], [3, "3"], [4, "4"], [5, "5"], [6, "6"], [7, "7"], [8, "8"], [9, "9"], [10, "10"], ], widget=widgets.RadioSelectHorizontal, ) q20 = models.LongStringField(blank=True) # afiliación política de los bisabuelos q21 = models.IntegerField( choices=[ [1, "Conservador"], [2, "Liberal"], [3, "No sé"], ], widget=widgets.RadioSelectHorizontal ) q22 = models.IntegerField( choices=[ [1, "Conservador"], [2, "Liberal"], [3, "No sé"], ], widget=widgets.RadioSelectHorizontal ) q23 = models.IntegerField( choices=[ [1, "Conservador"], [2, "Liberal"], [3, "No sé"], ], widget=widgets.RadioSelectHorizontal ) q24 = models.IntegerField( choices=[ [1, "Conservador"], [2, "Liberal"], [3, "No sé"], ], widget=widgets.RadioSelectHorizontal ) # Alguno de sus abuelos fue victima de la violencia q25 = models.IntegerField( choices=[ [0, "No"], [1, "Sí, una vez"], [2, "Sí, más de una vez"], [3, "No sé"], ], widget=widgets.RadioSelectHorizontal ) q26 = models.IntegerField( choices=[ [0, "No"], [1, "Sí, una vez"], [2, "Sí, más de una vez"], [3, "No sé"], ], widget=widgets.RadioSelectHorizontal ) q27 = models.IntegerField( choices=[ [0, "No"], [1, "Sí, una vez"], [2, "Sí, más de una vez"], [3, "No sé"], ], widget=widgets.RadioSelectHorizontal ) q28 = models.IntegerField( choices=[ [0, "No"], [1, "Sí, una vez"], [2, "Sí, más de una vez"], [3, "No sé"], ], widget=widgets.RadioSelectHorizontal ) # municipio de nacimiento de los abuelos q29 = models.StringField(label="") q30 = models.StringField(label="") q31 = models.StringField(label="") q32 = models.StringField(label="") # eventos de La Violencia # Pregunta: Desalojos o expropiaciones q33 = models.IntegerField( choices=[ [0, "Nunca"], [1, "Sí, una vez"], [2, "Sí, más de una vez"] ], widget=widgets.RadioSelectHorizontal ) q33_a = models.IntegerField(blank=True) q33_b = models.IntegerField(blank=True) # Pregunta: Amenazas por parte de los grupos armados al margen de la ley (guerrillas, paramilitares o delincuencia común) q34 = models.IntegerField( choices=[ [0, "Nunca"], [1, "Sí, una vez"], [2, "Sí, más de una vez"] ], widget=widgets.RadioSelectHorizontal ) q34_a = models.IntegerField(blank=True) q34_b = models.IntegerField(blank=True) # Pregunta: Amenazas por parte de carteles de la droga q35 = models.IntegerField( choices=[ [0, "Nunca"], [1, "Sí, una vez"], [2, "Sí, más de una vez"] ], widget=widgets.RadioSelectHorizontal ) q35_a = models.IntegerField(blank=True) q35_b = models.IntegerField(blank=True) # Pregunta: Masacres, enfrentamientos o ataques de grupos armados al margen de la ley (guerrillas, paramilitares o delincuencia común) q36 = models.IntegerField( choices=[ [0, "Nunca"], [1, "Sí, una vez"], [2, "Sí, más de una vez"] ], widget=widgets.RadioSelectHorizontal ) q36_a = models.IntegerField(blank=True) q36_b = models.IntegerField(blank=True) # Pregunta: Masacres, enfrentamientos o ataques de carteles de la droga q37 = models.IntegerField( choices=[ [0, "Nunca"], [1, "Sí, una vez"], [2, "Sí, más de una vez"] ], widget=widgets.RadioSelectHorizontal ) q37_a = models.IntegerField(blank=True) q37_b = models.IntegerField(blank=True) # Pregunta: Secuestros o extorsiones q38 = models.IntegerField( choices=[ [0, "Nunca"], [1, "Sí, una vez"], [2, "Sí, más de una vez"] ], widget=widgets.RadioSelectHorizontal ) q38_a = models.IntegerField(blank=True) q38_b = models.IntegerField(blank=True) # Pregunta: Atentados terroristas q39 = models.IntegerField( choices=[ [0, "Nunca"], [1, "Sí, una vez"], [2, "Sí, más de una vez"] ], widget=widgets.RadioSelectHorizontal ) q39_a = models.IntegerField(blank=True) q39_b = models.IntegerField(blank=True) ##Field del pago de la ronda sin coordinación. round_payoff = models.CurrencyField() ##Fields con respecto a los puntos enviados por A a B (expectativas de B) bel_sent = models.BooleanField(initial=False) expected_sent_ammount_B = models.CurrencyField(initial=None) global_payoff = models.CurrencyField(initial=None) ##Fields con respecto a los puntos de deducción cobrados por A a C (expectativas de B) bel_ded0 = models.BooleanField(initial=False) bel_ded10 = models.BooleanField(initial=False) bel_ded20 = models.BooleanField(initial=False) bel_ded30 = models.BooleanField(initial=False) bel_ded40 = models.BooleanField(initial=False) bel_ded50 = models.BooleanField(initial=False) expected_ded_0_B = models.CurrencyField(initial=None) expected_ded_10_B = models.CurrencyField(initial=None) expected_ded_20_B = models.CurrencyField(initial=None) expected_ded_30_B = models.CurrencyField(initial=None) expected_ded_40_B = models.CurrencyField(initial=None) expected_ded_50_B = models.CurrencyField(initial=None) ded_points = models.CurrencyField(initial=None) # **** PAYMENT **** ##Fields for payment idcard1 = models.StringField() expday = models.IntegerField(min=1, max=31) expmonth = models.IntegerField(min=1, max=12) expyear = models.StringField() namep = models.StringField() depto = models.StringField() cityp = models.StringField() country1 = models.StringField() email = models.StringField() telephone = models.StringField() dayp = models.IntegerField(min=1, max=31) monthp = models.IntegerField(min=1, max=12) yearp = models.IntegerField(max=2022, min=2022, default=2022) concept = models.StringField() signaturep = models.StringField() idcard2 = models.StringField() cedula = models.StringField() typepayment = models.BooleanField(choices=[ [True, "Transferencia Bancaria"], [False, "Daviplata / Nequi"], ], widget=widgets.RadioSelectHorizontal, ) platform = models.IntegerField(choices=[ [1, "Daviplata"], [2, "Nequi"], ], widget=widgets.RadioSelectHorizontal, initial=None) telephone_2 = models.StringField(initial=None) bank = models.IntegerField(choices=[ [0, "AV Villas"], [1, "Bancamía"], [2, "Banco Agrario"], [3, "Banco Bancoldex"], [4, "Banco Compartir"], [5, "Banco Coopcentral"], [6, "Banco Falabella"], [7, "Banco Finandina"], [8, "Banco Mundo Mujer"], [9, "Banco Pichincha"], [10, "Banco Procredit Colombia"], [11, "Banco Santander Colombia"], [12, "Banco Serfinanza"], [13, "Banco W"], [14, "Bancolombia"], [15, "Bancoomeva"], [16, "BBVA"], [17, "BNB Paribas"], [18, "Bogotá"], [19, "Caja Social"], [20, "CitiBank"], [21, "Coltefinanciera"], [22, "Compañía Financiera Juriscoop"], [23, "Confiar"], [24, "Cooperativa financiera Contrafa"], [25, "Cooperativa financiera de Antioquia"], [26, "Davivienda"], [27, "ITAU"], [28, "ITAU antes Corpbanca"], [29, "Occidente"], [30, "Popular"], [31, "Scotiabank Colpatria"], ], initial=None) id_bank = models.StringField(initial=None) name_2 = models.StringField(initial=None) account_type = models.BooleanField( choices=[ [True, "Ahorros"], [False, "Corriente"], ], initial=None ) idcard3 = models.StringField(initial=None) ## Address fields dir1 = models.IntegerField( choices=[ [0, "Avenida Calle"], [1, "Avenida Carrera"], [2, "Autopista"], [3, "Avenida"], [4, "Carretera"], [5, "Calle"], [6, "Camino"], [7, "Carrera"], [8, "Circunvalar"], [9, "Diagonal"], [10, "Kilometro"], [11, "Transversal"], [12, "Vereda"], [13, "Variante"], [14, "Zona Franca"] ], blank=True ) dir2 = models.IntegerField(min=1, blank=True) dir3 = models.IntegerField( choices=[ [1, "A"], [2, "B"], [3, "C"], [4, "D"], [5, "E"], [6, "F"], [7, "G"], [8, "H"], [9, "I"], [10, "J"], [11, "K"], [12, "L"], [13, "M"], [14, "N"], [15, "O"], [16, "P"], [17, "Q"], [18, "R"], [19, "S"], [20, "T"], [21, "U"], [22, "V"], [23, "W"], [24, "X"], [25, "Y"], [26, "Z"] ], blank=True ) dir4 = models.IntegerField( choices=[ [1, "Bis"], [2, "Este"], [3, "Noreste"], [4, "Noroeste"], [5, "Oeste"], [6, "Sur"], [7, "Sureste"], [8, "Suroeste"] ], blank=True ) dir5 = models.IntegerField(min=1, blank=True) dir6 = models.IntegerField( choices=[ [1, "A"], [2, "B"], [3, "C"], [4, "D"], [5, "E"], [6, "F"], [7, "G"], [8, "H"], [9, "I"], [10, "J"], [11, "K"], [12, "L"], [13, "M"], [14, "N"], [15, "O"], [16, "P"], [17, "Q"], [18, "R"], [19, "S"], [20, "T"], [21, "U"], [22, "V"], [23, "W"], [24, "X"], [25, "Y"], [26, "Z"] ], blank=True ) dir7 = models.IntegerField( choices=[ [1, "Bis"], [2, "Este"], [3, "Noreste"], [4, "Noroeste"], [5, "Oeste"], [6, "Sur"], [7, "Sureste"], [8, "Suroeste"] ], blank=True ) dir8 = models.IntegerField(min=1, blank=True) dir9 = models.IntegerField( choices=[ [1, "A"], [2, "B"], [3, "C"], [4, "D"], [5, "E"], [6, "F"], [7, "G"], [8, "H"], [9, "I"], [10, "J"], [11, "K"], [12, "L"], [13, "M"], [14, "N"], [15, "O"], [16, "P"], [17, "Q"], [18, "R"], [19, "S"], [20, "T"], [21, "U"], [22, "V"], [23, "W"], [24, "X"], [25, "Y"], [26, "Z"] ], blank=True ) dir10 = models.IntegerField( choices=[ [1, "Bis"], [2, "Este"], [3, "Noreste"], [4, "Noroeste"], [5, "Oeste"], [6, "Sur"], [7, "Sureste"], [8, "Suroeste"] ], blank=True ) dir11 = models.StringField(blank=True) dir12 = models.StringField(blank=True) # FUNCTIONS def creating_session(subsession: Subsession): global paying_round subsession.group_randomly(fixed_id_in_group=True) if subsession.round_number == 1: paying_round = random.randint(1, Constants.num_rounds) subsession.session.vars['paying_round'] = paying_round print('la ronda a pagar es', paying_round) for g in subsession.get_groups(): for p in subsession.get_players(): p.random_round = paying_round def survey_10_negative_error_message(player: Player, value): if not (value == 15): return 'Error, recuerde que el número de puntos de deducción se triplican cuando son deducidos.' def survey_11_negative_error_message(player: Player, value): if not (value == 40): return 'Error, el participante A le envió 40 puntos al participante B .' def survey_12_negative_error_message(player: Player, value): if not (value == 35): return 'Error, el participante C envió 15 puntos de deducción.' # PAGES class Introduction(Page): @staticmethod def is_displayed(player: Player): return player.round_number == 1 class Instructions_Especific(Page): @staticmethod def is_displayed(player: Player): return player.round_number == 1 class Offer(Page): form_model = 'group' form_fields = ['sent_amount'] @staticmethod def is_displayed(player: Player): return player.id_in_group == 1 @staticmethod def vars_for_template(player: Player): mostrar_ronda = True if player.subsession.round_number == 1: mostrar_ronda = False return dict(mostrar=mostrar_ronda) class Deduction(Page): form_model = 'group' form_fields = [ 'deduction_0', 'deduction_10', 'deduction_20', 'deduction_30', 'deduction_40', 'deduction_50', ] @staticmethod def is_displayed(player: Player): return player.id_in_group == 3 @staticmethod def vars_for_template(player: Player): mostrar_ronda = True if player.subsession.round_number == 1: mostrar_ronda = False return dict(mostrar=mostrar_ronda) class Expectations(Page): form_model = 'group' form_fields = [ 'expectation_sent', 'expectation_return_0', 'expectation_return_10', 'expectation_return_20', 'expectation_return_30', 'expectation_return_40', 'expectation_return_50', ] @staticmethod def is_displayed(player: Player): return player.id_in_group == 2 @staticmethod def vars_for_template(player: Player): mostrar_ronda = True if player.subsession.round_number == 1: mostrar_ronda = False return dict(mostrar=mostrar_ronda) class WaitForAll(WaitPage): wait_for_all_groups = True title_text = "Por favor espere a que el resto de participantes tomen sus decisiones." body_text = "De vez en cuando (cada 30 segundos aproximadamente), por favor oprima el botón de teclado F5 para refrescar la conexión de su computador con el servidor del experimento, y así poder avanzar más rápidamente." class RoundResults(Page): @staticmethod def vars_for_template(player: Player): mostrar_ronda = True if player.subsession.round_number == 1: mostrar_ronda = False if player.group.sent_amount == cu(0): deduction_points = player.group.deduction_0 elif player.group.sent_amount == cu(10): deduction_points = player.group.deduction_10 elif player.group.sent_amount == cu(20): deduction_points = player.group.deduction_20 elif player.group.sent_amount == cu(30): deduction_points = player.group.deduction_30 elif player.group.sent_amount == cu(40): deduction_points = player.group.deduction_40 else: deduction_points = player.group.deduction_50 return dict( round_paymentA=Constants.endowmentA - player.group.sent_amount - deduction_points * Constants.multiplication_factor, round_paymentC=Constants.endowmentC - deduction_points, ded_points=deduction_points, mostrar=mostrar_ronda, ) @staticmethod def before_next_page(player: Player, timeout_happened): group = player.group playerA = group.get_player_by_id(1) playerB = group.get_player_by_id(2) playerC = group.get_player_by_id(3) if group.sent_amount == cu(0): playerB.ded_points = group.deduction_0 elif group.sent_amount == cu(10): playerB.ded_points = group.deduction_10 elif group.sent_amount == cu(20): playerB.ded_points = group.deduction_20 elif group.sent_amount == cu(30): playerB.ded_points = group.deduction_30 elif group.sent_amount == cu(40): playerB.ded_points = group.deduction_40 elif group.sent_amount == cu(50): playerB.ded_points = group.deduction_50 playerA.round_payoff = ( Constants.endowmentA - group.sent_amount - Constants.multiplication_factor * playerB.ded_points ) * 2 playerB.round_payoff = (group.sent_amount) * 2 playerC.round_payoff = (Constants.endowmentC - playerB.ded_points) * 2 playerB.expected_sent_ammount_B = group.expectation_sent playerB.expected_ded_0_B = group.expectation_return_0 playerB.expected_ded_10_B = group.expectation_return_10 playerB.expected_ded_20_B = group.expectation_return_20 playerB.expected_ded_30_B = group.expectation_return_30 playerB.expected_ded_40_B = group.expectation_return_40 playerB.expected_ded_50_B = group.expectation_return_50 playerB.global_payoff = group.sent_amount * 2 Groups = player.subsession.get_groups() ##Creencias para la cantidad enviada por A. values_sent_ammount = [] for g in Groups: values_sent_ammount.append(g.sent_amount) # Vector de modas repetitions_1 = 0 for i in values_sent_ammount: aparitions = values_sent_ammount.count(i) if aparitions > repetitions_1: repetitions_1 = aparitions modes_sent_ammount = [] for i in values_sent_ammount: aparitions = values_sent_ammount.count(i) if aparitions == repetitions_1 and i not in modes_sent_ammount: modes_sent_ammount.append(i) if playerB.expected_sent_ammount_B in modes_sent_ammount: playerB.bel_sent = True playerB.global_payoff += cu(3) * 2 ##Creencias para los puntos de deducción de C cuando A envía 0 puntos. values_deduction_0 = [] for g in Groups: values_deduction_0.append(g.deduction_0) # Vector de modas repetitions_2 = 0 for i in values_deduction_0: aparitions = values_deduction_0.count(i) if aparitions > repetitions_2: repetitions_2 = aparitions modes_sent_ammount_0 = [] for i in values_deduction_0: aparitions = values_deduction_0.count(i) if aparitions == repetitions_2 and i not in modes_sent_ammount_0: modes_sent_ammount_0.append(i) if playerB.expected_ded_0_B in modes_sent_ammount_0: playerB.global_payoff += cu(0.5) playerB.bel_ded0 = True ##Creencias para los puntos de deducción de C cuando A envía 10 puntos. values_deduction_10 = [] for g in Groups: values_deduction_10.append(g.deduction_10) # Vector de modas repetitions_3 = 0 for i in values_deduction_10: aparitions = values_deduction_10.count(i) if aparitions > repetitions_3: repetitions_3 = aparitions modes_sent_ammount_10 = [] for i in values_deduction_10: aparitions = values_deduction_10.count(i) if aparitions == repetitions_3 and i not in modes_sent_ammount_10: modes_sent_ammount_10.append(i) if playerB.expected_ded_10_B in modes_sent_ammount_10: playerB.global_payoff += cu(0.5) playerB.bel_ded10 = True ##Creencias para los puntos de deducción de C cuando A envía 20 puntos. values_deduction_20 = [] for g in Groups: values_deduction_20.append(g.deduction_20) # Vector de modas repetitions_4 = 0 for i in values_deduction_20: aparitions = values_deduction_20.count(i) if aparitions > repetitions_4: repetitions_4 = aparitions modes_sent_ammount_20 = [] for i in values_deduction_20: aparitions = values_deduction_20.count(i) if aparitions == repetitions_4 and i not in modes_sent_ammount_20: modes_sent_ammount_20.append(i) if playerB.expected_ded_20_B in modes_sent_ammount_20: playerB.global_payoff += cu(0.5) playerB.bel_ded20 = True ##Creencias para los puntos de deducción de C cuando A envía 30 puntos. values_deduction_30 = [] for g in Groups: values_deduction_30.append(g.deduction_30) # Vector de modas repetitions_5 = 0 for i in values_deduction_30: aparitions = values_deduction_30.count(i) if aparitions > repetitions_5: repetitions_5 = aparitions modes_sent_ammount_30 = [] for i in values_deduction_30: aparitions = values_deduction_30.count(i) if aparitions == repetitions_5 and i not in modes_sent_ammount_30: modes_sent_ammount_30.append(i) if playerB.expected_ded_30_B in modes_sent_ammount_30: playerB.global_payoff += cu(0.5) playerB.bel_ded30 = True ##Creencias para los puntos de deducción de C cuando A envía 40 puntos. values_deduction_40 = [] for g in Groups: values_deduction_40.append(g.deduction_40) # Vector de modas repetitions_6 = 0 for i in values_deduction_40: aparitions = values_deduction_40.count(i) if aparitions > repetitions_6: repetitions_6 = aparitions modes_sent_ammount_40 = [] for i in values_deduction_40: aparitions = values_deduction_40.count(i) if aparitions == repetitions_6 and i not in modes_sent_ammount_40: modes_sent_ammount_40.append(i) if playerB.expected_ded_40_B in modes_sent_ammount_40: playerB.global_payoff += cu(0.5) playerB.bel_ded40 = True ##Creencias para los puntos de deducción de C cuando A envía 50 puntos. values_deduction_50 = [] for g in Groups: values_deduction_50.append(g.deduction_50) # Vector de modas repetitions_7 = 0 for i in values_deduction_50: aparitions = values_deduction_50.count(i) if aparitions > repetitions_7: repetitions_7 = aparitions modes_sent_ammount_50 = [] for i in values_deduction_50: aparitions = values_deduction_50.count(i) if aparitions == repetitions_7 and i not in modes_sent_ammount_50: modes_sent_ammount_50.append(i) if playerB.expected_ded_50_B in modes_sent_ammount_50: playerB.global_payoff += cu(0.5) playerB.bel_ded50 = True class DespuesRondaUno(Page): @staticmethod def is_displayed(player: Player): return player.round_number == 1 class ResultsWaitPage(WaitPage): @staticmethod def is_displayed(player: Player): return player.round_number == Constants.num_rounds @staticmethod def after_all_players_arrive(group: Group): num_round = group.session.vars['paying_round'] group = group player_A = group.get_player_by_id(1) player_B = group.get_player_by_id(2) player_C = group.get_player_by_id(3) player_A.payoff = player_A.in_round(num_round).round_payoff player_B.payoff = player_B.in_round(num_round).global_payoff player_C.payoff = player_C.in_round(num_round).round_payoff # método para coger el vector de los valores de mensaje para la ronda escogida Groups = group.subsession.get_groups() ##Creencias para B en la última ronda (normas sociales) matching = random.randint(0, len(Groups) - 2) ##pregunta 1 norms_B_s1 = [] for g in Groups: norms_B_s1.append(g.expectation_social_norm_s1_B) norms_B_s1.remove(group.expectation_social_norm_s1_B) if norms_B_s1[matching] == group.expectation_social_norm_s1_B: player_B.payoff += cu(1) * 2 ##pregunta 2 norms_B_s2 = [] for g in Groups: norms_B_s2.append(g.expectation_social_norm_s2_B) norms_B_s2.remove(group.expectation_social_norm_s2_B) if norms_B_s2[matching] == group.expectation_social_norm_s2_B: player_B.payoff += cu(1) * 2 ##Creencias para C en la última ronda (normas sociales) ##pregunta 1 norms_C_s1 = [] for g in Groups: norms_C_s1.append(g.expectation_social_norm_s1_C) norms_C_s1.remove(group.expectation_social_norm_s1_C) if norms_C_s1[matching] == group.expectation_social_norm_s1_C: player_C.payoff += cu(1) * 2 ##pregunta 2 norms_C_s2 = [] for g in Groups: norms_C_s2.append(g.expectation_social_norm_s2_C) norms_C_s2.remove(group.expectation_social_norm_s2_C) if norms_C_s2[matching] == group.expectation_social_norm_s2_C: player_C.payoff += cu(1) * 2 class Results(Page): @staticmethod def is_displayed(player: Player): return player.round_number == Constants.num_rounds @staticmethod def vars_for_template(player: Player): group = player.group playerA = group.get_player_by_id(1) playerB = group.get_player_by_id(2) playerC = group.get_player_by_id(3) num_round = player.session.vars['paying_round'] deduction_points = playerB.in_round(num_round).ded_points payoff_B = playerB.in_round(num_round).round_payoff / 2 # método para coger el vector de los valores de mensaje para la ronda escogida Groups = player.subsession.get_groups() ##Creencias para la cantidad enviada por A. values_sent_message_A = "No" payment_message_deduction = 0 if playerB.in_round(num_round).bel_sent == True: payment_message_deduction += 3 values_sent_message_A = "Sí" else: payment_message_deduction += 0 ##Creencias para los puntos de deducción de C cuando A envía 0 puntos. values_deduction_message_0 = "No" if playerB.in_round(num_round).bel_ded0 == True: payment_message_deduction += 0.5 values_deduction_message_0 = "Sí" else: payment_message_deduction += 0 ##Creencias para los puntos de deducción de C cuando A envía 10 puntos. values_deduction_message_10 = "No" if playerB.in_round(num_round).bel_ded10 == True: payment_message_deduction += 0.5 values_deduction_message_10 = "Sí" else: payment_message_deduction += 0 ##Creencias para los puntos de deducción de C cuando A envía 20 puntos. values_deduction_message_20 = "No" if playerB.in_round(num_round).bel_ded20 == True: payment_message_deduction += 0.5 values_deduction_message_20 = "Sí" else: payment_message_deduction += 0 ##Creencias para los puntos de deducción de C cuando A envía 30 puntos. values_deduction_message_30 = "No" if playerB.in_round(num_round).bel_ded30 == True: payment_message_deduction += 0.5 values_deduction_message_30 = "Sí" else: payment_message_deduction += 0 ##Creencias para los puntos de deducción de C cuando A envía 40 puntos. values_deduction_message_40 = "No" if playerB.in_round(num_round).bel_ded40 == True: payment_message_deduction += 0.5 values_deduction_message_40 = "Sí" else: payment_message_deduction += 0 ##Creencias para los puntos de deducción de C cuando A envía 50 puntos. values_deduction_message_50 = "No" if playerB.in_round(num_round).bel_ded50 == True: payment_message_deduction += 0.5 values_deduction_message_50 = "Sí" else: payment_message_deduction += 0 ##Creencias para B en la última ronda (normas sociales) matching = random.randint(0, len(Groups) - 2) social_norms_B = cu(0) ##pregunta 1 norms_B_s1 = [] correct_1_B = "No" for g in Groups: norms_B_s1.append(g.expectation_social_norm_s1_B) norms_B_s1.remove(player.group.expectation_social_norm_s1_B) if norms_B_s1[matching] == player.group.expectation_social_norm_s1_B: social_norms_B = +cu(1) correct_1_B = "Sí" ##pregunta 2 norms_B_s2 = [] correct_2_B = "No" for g in Groups: norms_B_s2.append(g.expectation_social_norm_s2_B) norms_B_s2.remove(player.group.expectation_social_norm_s2_B) if norms_B_s2[matching] == player.group.expectation_social_norm_s2_B: social_norms_B += cu(1) correct_2_B = "Sí" ##Creencias para C en la última ronda (normas sociales) social_norms_C = cu(0) ##pregunta 1 norms_C_s1 = [] correct_1_C = "No" for g in Groups: norms_C_s1.append(g.expectation_social_norm_s1_C) norms_C_s1.remove(player.group.expectation_social_norm_s1_C) if norms_C_s1[matching] == player.group.expectation_social_norm_s1_C: social_norms_C += cu(1) correct_1_C = "Sí" ##pregunta 2 norms_C_s2 = [] correct_2_C = "No" for g in Groups: norms_C_s2.append(g.expectation_social_norm_s2_C) norms_C_s2.remove(player.group.expectation_social_norm_s2_C) if norms_C_s2[matching] == player.group.expectation_social_norm_s2_C: social_norms_C += cu(1) correct_2_C = "Sí" ##Organización en Labels para la interfaz del jugador. # Normas sociales en la pregunta 1 para B if player.group.expectation_social_norm_s1_B == 0: belief_sn_B1 = "Muy socialmente inapropiada" elif player.group.expectation_social_norm_s1_B == 1: belief_sn_B1 = "Algo socialmente inapropiada" elif player.group.expectation_social_norm_s1_B == 2: belief_sn_B1 = "Algo socialmente apropiada" else: belief_sn_B1 = "Muy socialmente apropiada" # Normas sociales en la pregunta 2 para B if player.group.expectation_social_norm_s2_B == 0: belief_sn_B2 = "Muy socialmente inapropiada" elif player.group.expectation_social_norm_s2_B == 1: belief_sn_B2 = "Algo socialmente inapropiada" elif player.group.expectation_social_norm_s2_B == 2: belief_sn_B2 = "Algo socialmente apropiada" else: belief_sn_B2 = "Muy socialmente apropiada" # Normas sociales en la pregunta 1 para C if player.group.expectation_social_norm_s1_C == 0: belief_sn_C1 = "Muy socialmente inapropiada" elif player.group.expectation_social_norm_s1_C == 1: belief_sn_C1 = "Algo socialmente inapropiada" elif player.group.expectation_social_norm_s1_C == 2: belief_sn_C1 = "Algo socialmente apropiada" else: belief_sn_C1 = "Muy socialmente apropiada" # Normas sociales en la pregunta 2 para C if player.group.expectation_social_norm_s2_C == 0: belief_sn_C2 = "Muy socialmente inapropiada" elif player.group.expectation_social_norm_s2_C == 1: belief_sn_C2 = "Algo socialmente inapropiada" elif player.group.expectation_social_norm_s2_C == 2: belief_sn_C2 = "Algo socialmente apropiada" else: belief_sn_C2 = "Muy socialmente apropiada" # Invocamos al jugador B en la ronda aleatoria. player = playerB.in_round(num_round) # Sobre las expectativas de B de los puntos envíados por A. if player.expected_sent_ammount_B == cu(0): belief_sent = "0 puntos" elif player.expected_sent_ammount_B == cu(10): belief_sent = "10 puntos" elif player.expected_sent_ammount_B == cu(20): belief_sent = "20 puntos" elif player.expected_sent_ammount_B == cu(30): belief_sent = "30 puntos" elif player.expected_sent_ammount_B == cu(40): belief_sent = "40 puntos" elif player.expected_sent_ammount_B: belief_sent = "50 puntos" # Expectativas de B de los puntos de deducción enviados por C belief_ded_0 = str(int(player.expected_ded_0_B)) + " puntos." belief_ded_10 = str(int(player.expected_ded_10_B)) + " puntos." belief_ded_20 = str(int(player.expected_ded_20_B)) + " puntos." belief_ded_30 = str(int(player.expected_ded_30_B)) + " puntos." belief_ded_40 = str(int(player.expected_ded_40_B)) + " puntos." belief_ded_50 = str(int(player.expected_ded_50_B)) + " puntos." player_A_payoff = int(playerA.payoff) / 2 player_B_payoff = int(playerB.payoff) / 2 player_C_payoff = int(playerC.payoff) / 2 return dict( paying_round=num_round, payoff_B=payoff_B, ded_points=deduction_points, social_norms_C=social_norms_C, social_norms_B=social_norms_B, correct_1_C=correct_1_C, correct_1_B=correct_1_B, correct_2_B=correct_2_B, correct_2_C=correct_2_C, payment_message_deduction=payment_message_deduction, belief_sent=belief_sent, belief_ded_0=belief_ded_0, belief_ded_10=belief_ded_10, belief_ded_20=belief_ded_20, belief_ded_30=belief_ded_30, belief_ded_40=belief_ded_40, belief_ded_50=belief_ded_50, belief_sn_B1=belief_sn_B1, belief_sn_B2=belief_sn_B2, belief_sn_C1=belief_sn_C1, belief_sn_C2=belief_sn_C2, player_A_payoff=player_A_payoff, player_B_payoff=player_B_payoff, player_C_payoff=player_C_payoff, values_sent_message_A=values_sent_message_A, values_deduction_message_0=values_deduction_message_0, values_deduction_message_10=values_deduction_message_10, values_deduction_message_20=values_deduction_message_20, values_deduction_message_30=values_deduction_message_30, values_deduction_message_40=values_deduction_message_40, values_deduction_message_50=values_deduction_message_50, ) class Payment(Page): @staticmethod def vars_for_template(player: Player): group = player.group playerA = group.get_player_by_id(1) playerB = group.get_player_by_id(2) playerC = group.get_player_by_id(3) player_A_payoff = int(playerA.payoff) / 2 player_B_payoff = int(playerB.payoff) / 2 player_C_payoff = int(playerC.payoff) / 2 payment = player.participant.payoff.to_real_world_currency(player.session) total = player.participant.payoff_plus_participation_fee() return dict( player_A_payoff=player_A_payoff, player_B_payoff=player_B_payoff, player_C_payoff=player_C_payoff, payment=payment, total=total, ) @staticmethod def is_displayed(player: Player): return player.round_number == Constants.num_rounds class Survey(Page): form_model = 'player' form_fields = ["survey_10", "survey_11", "survey_12"] @staticmethod def is_displayed(player: Player): return player.round_number == 1 class AfterSurvey(Page): @staticmethod def vars_for_template(player: Player): total_correct = 0 correct_10 = "No" if player.survey_10 == 15: correct_10 = "Si" total_correct += 1 correct_11 = "No" if player.survey_11 == 40: correct_11 = "Si" total_correct += 1 correct_12 = "No" if player.survey_12 == 35: correct_12 = "Si" total_correct += 1 show = False if total_correct < 3: show = True return dict( correct_10=correct_10, correct_11=correct_11, correct_12=correct_12, total_correct=total_correct, show=show, ) @staticmethod def is_displayed(player: Player): return player.round_number == 1 class InstructionsLastRoundB(Page): @staticmethod def is_displayed(player: Player): return player.round_number == Constants.num_rounds and player.id_in_group == 2 class InstructionsLastRoundC(Page): @staticmethod def is_displayed(player: Player): return player.round_number == Constants.num_rounds and player.id_in_group == 3 class SocialNormsB(Page): form_model = 'group' form_fields = ["expectation_social_norm_s1_B", "expectation_social_norm_s2_B"] @staticmethod def is_displayed(player: Player): return player.round_number == Constants.num_rounds and player.id_in_group == 2 class SocialNormsC(Page): form_model = 'group' form_fields = ["expectation_social_norm_s1_C", "expectation_social_norm_s2_C"] @staticmethod def is_displayed(player: Player): return player.round_number == Constants.num_rounds and player.id_in_group == 3 class Survey2(Page): @staticmethod def is_displayed(player: Player): total_correct = 0 correct_10 = "No" if player.survey_10 == 15: correct_10 = "Si" total_correct += 1 correct_11 = "No" if player.survey_11 == 40: correct_11 = "Si" total_correct += 1 correct_12 = "No" if player.survey_12 == 35: correct_12 = "Si" total_correct += 1 show = False if total_correct < 3: show = True return show and player.round_number == 1 form_model = "player" form_fields = ["survey_14"] @staticmethod def error_message(player: Player, values): if values["survey_14"] != 10: return "Tiene un error en por lo menos una respuesta." class WaitForAll_2(WaitPage): wait_for_all_groups = True title_text = "Por favor espere a que el resto de participantes tomen sus decisiones." body_text = "De vez en cuando (cada 30 segundos aproximadamente), por favor oprima el botón de teclado F5 para refrescar la conexión de su computador con el servidor del experimento, y así poder avanzar más rápidamente." class WaitForAll_3(WaitPage): wait_for_all_groups = True title_text = "Por favor espere a que el resto de participantes tomen sus decisiones." body_text = "De vez en cuando (cada 30 segundos aproximadamente), por favor oprima el botón de teclado F5 para refrescar la conexión de su computador con el servidor del experimento, y así poder avanzar más rápidamente." class PcProcedure(Page): @staticmethod def is_displayed(player: Player): return player.round_number == 1 class instructionsEspecificA(Page): @staticmethod def is_displayed(player: Player): return player.round_number == 1 and player.id_in_group == 1 class instructionsEspecificB(Page): @staticmethod def is_displayed(player: Player): return player.round_number == 1 and player.id_in_group == 2 class InstructionsEspecificC(Page): @staticmethod def is_displayed(player: Player): return player.round_number == 1 and player.id_in_group == 3 class Questionnaire_A(Page): form_model = "player" form_fields = ["q1", "q2", "q3", "q4", "q5", "q6"] @staticmethod def is_displayed(player: Player): return player.round_number == Constants.num_rounds class Questionnaire_B(Page): form_model = "player" form_fields = ["q7", "q8", "q9", "q10", "q11", "q12", "q13", "q14", "q15", "q18", "q19", "q20", "q21", "q22", "q23", "q24", "q25", "q26", "q27", "q28", "q29", "q30", "q31", "q32", "q33", "q33_a", "q33_b", "q34", "q34_a", "q34_b", "q35", "q35_a", "q35_b", "q36", "q36_a", "q36_b", "q37", "q37_a", "q37_b", "q38", "q38_a", "q38_b", "q39", "q39_a", "q39_b"] @staticmethod def is_displayed(player: Player): return player.round_number == Constants.num_rounds class FinalMessage(Page): @staticmethod def is_displayed(player: Player): return player.round_number == Constants.num_rounds class PagosInicial(Page): @staticmethod def is_displayed(player: Player): return player.round_number == Constants.num_rounds class Pagos_1(Page): form_model = 'player' form_fields = ["idcard1", "expday", "expmonth", "expyear", "namep", "depto", "cityp", "country1", "email", "telephone", "dayp", "monthp", "yearp", "typepayment", "signaturep", "idcard2", "dir1", "dir2", "dir3", "dir4", "dir5", "dir6", "dir7", "dir8", "dir9", "dir10", "dir11", "dir12"] @staticmethod def is_displayed(player: Player): return player.round_number == Constants.num_rounds @staticmethod def vars_for_template(player: Player): group = player.group player_A = group.get_player_by_id(1) player_B = group.get_player_by_id(2) player_C = group.get_player_by_id(3) player_A_payoff = int(player_A.payoff) / 2 player_B_payoff = int(player_B.payoff) / 2 player_C_payoff = int(player_C.payoff) / 2 payment = player.participant.payoff.to_real_world_currency(player.session) total = player.participant.payoff_plus_participation_fee() return dict( player_A_payoff=player_A_payoff, player_B_payoff=player_B_payoff, player_C_payoff=player_C_payoff, payment=payment, total=total, ) class Pagos_2(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): return player.round_number == Constants.num_rounds @staticmethod def get_form_fields(player: Player): if player.typepayment: return ['bank', 'id_bank', 'name_2', 'account_type', 'idcard3'] else: return ['platform', 'telephone_2', 'cedula'] class EtapaUno(Page): @staticmethod def is_displayed(player: Player): return player.round_number == 1 class Bienvenida(Page): @staticmethod def is_displayed(player: Player): return player.round_number == 1 class InformedConsent_1(Page): @staticmethod def is_displayed(player: Player): return player.round_number == 1 class InformedConsent_2(Page): form_model = 'player' form_fields = [ 'city', 'day', 'month', 'year', 'hour', 'minutes', 'ampm', 'name', 'signature', 'idcard', 'citycard', ] @staticmethod def is_displayed(player: Player): return player.round_number == 1 class instructionsInicio(Page): @staticmethod def is_displayed(player: Player): return player.round_number == 1 class Puntaje(Page): @staticmethod def is_displayed(player: Player): return player.round_number == 1 class EtapaDos(Page): @staticmethod def is_displayed(player: Player): return player.round_number == 1 page_sequence = [ Introduction, InformedConsent_1, InformedConsent_2, Bienvenida, EtapaUno, EtapaDos, Puntaje, Survey, AfterSurvey, Survey2, WaitForAll_2, Offer, Expectations, Deduction, WaitForAll, RoundResults, DespuesRondaUno, InstructionsLastRoundB, InstructionsLastRoundC, SocialNormsB, SocialNormsC, ResultsWaitPage, Results, Payment, Questionnaire_A, Questionnaire_B, Pagos_1, Pagos_2, FinalMessage, ]