from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants import random municipalityquestionsN = random.sample([1, 2, 3], 3) municipalityquestionsH = random.sample([1, 2, 3], 3) # ********************************************** STAGE 0 ******************************************************** # ************* N ******************* # Página de instrucciones S0-N class S0_instructions_N(Page): pass # Página de preguntas sobre candidatos S0-N class S0_part1_municipalityquestions_N(Page): form_model = 'player' form_fields = ['s0Np1p1', 's0Np1p2', 's0Np1p3'] def vars_for_template(self): preguntas = municipalityquestionsN return dict( preguntas=preguntas ) # Página de resultados sobre candidatos S0_N class S0_part1_municipalityresults_N(Page): def vars_for_template(self): preguntas = municipalityquestionsN # respuestas de los jugadores r1 = self.player.get_s0Np1p1_display() r2 = self.player.get_s0Np1p2_display() r3 = self.player.get_s0Np1p3_display() # verdaderas respuestas v1 = 'Claudia López' v2 = 'Miguel Uribe' v3 = 'Carlos Galán' return dict( preguntas=preguntas, r1=r1, r2=r2, r3=r3, v1=v1, v2=v2, v3=v3, ) # Página de preguntas sobre zonas de Bogotá S0-N class S0_part2_neighborhoodquestions_N(Page): form_model = 'player' form_fields = ['s0Np2p1', 's0Np2p2', 's0Np2p3'] # Página de resultados sobre zonas de Bogotá S0-H class S0_part2_neighborhoodresults_N(Page): def vars_for_template(self): # respuestas de los jugadores r1 = self.player.s0Np2p1 r2 = self.player.s0Np2p2 r3 = self.player.s0Np2p3 return dict( r1=r1, r2=r2, r3=r3, ) # Página de preguntas sobre rango de día S0-N class S0_part3_hourquestions_N(Page): form_model = 'player' form_fields = ['s0Np3p1'] # Página de respuestas sobre rango de día S0-N class S0_part3_hourresults_N(Page): def vars_for_template(self): r1 = self.player.get_s0Np3p1_display() return dict(r1=r1, ) # ************* H ******************* # Página de instrucciones S0-H class S0_instructions_H(Page): pass # Página de preguntas sobre candidatos S0-H class S0_part1_municipalityquestions_H(Page): form_model = 'player' form_fields = ['s0Hp1p1', 's0Hp1p2', 's0Hp1p3'] def vars_for_template(self): preguntas = municipalityquestionsH return dict( preguntas=preguntas ) # Página de resultados sobre candidatos S0_H class S0_part1_municipalityresults_H(Page): def vars_for_template(self): preguntas = municipalityquestionsH # respuestas de los jugadores r1 = self.player.get_s0Hp1p1_display() r2 = self.player.get_s0Hp1p2_display() r3 = self.player.get_s0Hp1p3_display() # verdaderas respuestas v1 = 'Claudia López' v2 = 'Miguel Uribe' v3 = 'Carlos Galán' return dict( preguntas=preguntas, r1=r1, r2=r2, r3=r3, v1=v1, v2=v2, v3=v3, ) # Página de preguntas sobre zonas de Bogotá S0-H class S0_part2_neighborhoodquestions_H(Page): form_model = 'player' form_fields = ['s0Hp2p1', 's0Hp2p2', 's0Hp2p3'] # Página de resultados sobre zonas de Bogotá S0-H class S0_part2_neighborhoodresults_H(Page): def vars_for_template(self): # respuestas de los jugadores r1 = self.player.s0Hp2p1 r2 = self.player.s0Hp2p2 r3 = self.player.s0Hp2p3 return dict( r1=r1, r2=r2, r3=r3, ) # Página de preguntas sobre rango de día S0-N class S0_part3_hourquestions_H(Page): form_model = 'player' form_fields = ['s0Hp3p1'] # Página de respuestas sobre rango de día S0-N class S0_part3_hourresults_H(Page): def vars_for_template(self): r1 = self.player.get_s0Hp3p1_display() return dict(r1=r1, ) # ********************************************** STAGE 1 ******************************************************** # Página de instrucciones S1 class S1_instructions(Page): def vars_for_template(self): randomX = self.player.randomX randomX_min = randomX - c(15) randomX_max = randomX + c(15) return dict( randomX=randomX, randomX_min=randomX_min, randomX_max=randomX_max ) # Página del juego (la tabla de 11 situaciones) S1 class S1_juego(Page): form_model = 'player' form_fields = ['s1', 's2', 's3', 's4', 's5', 's6', 's7', 's8', 's9', 's10', 's11'] def vars_for_template(self): randomX = self.player.randomX randomX_b1 = randomX - c(15) randomX_b2 = randomX - c(10) randomX_b3 = randomX - c(7.5) randomX_b4 = randomX - c(5) randomX_b5 = randomX - c(2.5) randomX_b6 = randomX randomX_b7 = randomX + c(2.5) randomX_b8 = randomX + c(5) randomX_b9 = randomX + c(7.5) randomX_b10 = randomX + c(10) randomX_b11 = randomX + c(15) return dict( randomX=randomX, randomX_b1=randomX_b1, randomX_b2=randomX_b2, randomX_b3=randomX_b3, randomX_b4=randomX_b4, randomX_b5=randomX_b5, randomX_b6=randomX_b6, randomX_b7=randomX_b7, randomX_b8=randomX_b8, randomX_b9=randomX_b9, randomX_b10=randomX_b10, randomX_b11=randomX_b11 ) # Página de resultados S1 class S1_resultados(Page): def vars_for_template(self): randomX = self.player.randomX # Esta es la situación que escogerá el computador. random_s = random.choice([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) if random_s == 1: decision = self.player.s1 elif random_s == 2: decision = self.player.s2 elif random_s == 3: decision = self.player.s3 elif random_s == 4: decision = self.player.s4 elif random_s == 5: decision = self.player.s5 elif random_s == 6: decision = self.player.s6 elif random_s == 7: decision = self.player.s7 elif random_s == 8: decision = self.player.s8 elif random_s == 9: decision = self.player.s9 elif random_s == 10: decision = self.player.s10 else: decision = self.player.s11 if decision == 1: pago = randomX else: if random_s == 1: pago = randomX - c(15) elif random_s == 2: pago = randomX - c(10) elif random_s == 3: pago = randomX - c(7.5) elif random_s == 4: pago = randomX - c(5) elif random_s == 5: pago = randomX - c(2.5) elif random_s == 6: pago = randomX elif random_s == 7: pago = randomX + c(2.5) elif random_s == 8: pago = randomX + c(5) elif random_s == 9: pago = randomX + c(7.5) elif random_s == 10: pago = randomX + c(10) else: pago = randomX + c(15) if decision == 1: h1 = '9:00 am-10:00am' else: h1 = '8:00 pm-9:00pm' return dict(randomX=randomX, random_s=random_s, decision=decision, pago=pago, h1=h1) # ********************************************** STAGE 2 ******************************************************** # ****** Introducción S2 ******* class S2_A_introduccion(Page): pass # *** Risk experiment S2 *** # instrucciones risk experiment S2 class S2_B_instructions_risk(Page): form_model = 'player' form_fields = ['ET_riskreturn'] # juego risk experiment S2 class S2_C_juego_risk(Page): form_model = 'player' form_fields = ['r1', 'r2', 'r3', 'r4', 'r5', 'r6', 'r7', 'r8', 'r9', 'r10', 'r11'] def vars_for_template(self): color_choice = self.player.get_ET_riskreturn_display() if color_choice == 'Negro': colory = 'negra' colorn = 'blanca' else: colory = 'blanca' colorn = 'negra' return dict(color_choice=color_choice, colory=colory, colorn=colorn) # *** Ambiguity experiment S2 *** # instrucciones ambiguity experiment S2 class S2_D_instructions_ambiguity(Page): form_model = 'player' form_fields = ['ET_ambiguityreturn'] # juego ambiguity experiment S2 class S2_E_juego_ambiguity(Page): form_model = 'player' form_fields = ['a1', 'a2', 'a3', 'a4', 'a5', 'a6', 'a7', 'a8', 'a9', 'a10', 'a11'] def vars_for_template(self): color_choice = self.player.get_ET_ambiguityreturn_display() if color_choice == 'Blanco': adjetivoy = 'blanca' adjetivon = 'negra' else: adjetivoy = 'negra' adjetivon = 'blanca' return dict(color_choice=color_choice, adjetivoy=adjetivoy, adjetivon=adjetivon) # instrucciones y juego loss experiment S2 class S2_F_instructions_loss(Page): form_model = 'player' form_fields = ['ra1', 'ra2', 'ra3', 'ra4', 'ra5', 'ra6'] # **** WAITPAGE **** class S2_G_waitpage(Page): pass # Página de resultados class S2_H_payment(Page): form_model = 'player' def vars_for_template(self): random_game = random.choice([1, 2, 3]) riskcolorPE = {} random_risk_s = {} riskdecision = {} urna = {} random_riskcolor = {} risk_pago = {} colorbola = {} ambiguitycolorPE = {} ambiguity_colorchoicey = {} ambiguity_colorchoicen = {} random_ambiguity_s = {} ambiguitydecision = {} randomcolor = {} prob = {} random_ambiguitycolor = {} ambiguity_pago = {} random_risk_ar = {} riskadecision = {} moneda = {} won = {} acepto = {} Et_loss = {} won2 = {} # ****************Se escoge como juego a pagar el S2-M1 (RiskExperiment)***************** if random_game == 1: if self.player.ET_riskreturn == 0: riskcolorPE = 'blanco' else: riskcolorPE = 'negro' # Esta es la situación que escogerá el computador S2-M1 (RiskExperiment) random_risk_s = random.choice([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) # Esta es la urna que escoge el individuo en cada situación if random_risk_s == 1: riskdecision = self.player.r1 elif random_risk_s == 2: riskdecision = self.player.r2 elif random_risk_s == 3: riskdecision = self.player.r3 elif random_risk_s == 4: riskdecision = self.player.r4 elif random_risk_s == 5: riskdecision = self.player.r5 elif random_risk_s == 6: riskdecision = self.player.r6 elif random_risk_s == 7: riskdecision = self.player.r7 elif random_risk_s == 8: riskdecision = self.player.r8 elif random_risk_s == 9: riskdecision = self.player.r9 elif random_risk_s == 10: riskdecision = self.player.r10 else: riskdecision = self.player.r11 if riskdecision == 1: urna = 'Urna A' else: urna = 'Urna B' # El color de la bola extraída (en caso de que sea Urna A o Urna B) if riskdecision == 1: random_riskcolor = random.choices(population=[0, 1], weights=[50, 50], k=1) # Pagos if random_riskcolor[0] == self.player.ET_riskreturn: risk_pago = 6 else: risk_pago = 4 else: if random_risk_s == 1: random_riskcolor = 1 elif random_risk_s == 2: random_riskcolor = random.choices(population=[0, 1], weights=[10, 90], k=1) elif random_risk_s == 3: random_riskcolor = random.choices(population=[0, 1], weights=[20, 80], k=1) elif random_risk_s == 4: random_riskcolor = random.choices(population=[0, 1], weights=[30, 70], k=1) elif random_risk_s == 5: random_riskcolor = random.choices(population=[0, 1], weights=[40, 60], k=1) elif random_risk_s == 6: random_riskcolor = random.choices(population=[0, 1], weights=[50, 50], k=1) elif random_risk_s == 7: random_riskcolor = random.choices(population=[0, 1], weights=[60, 40], k=1) elif random_risk_s == 8: random_riskcolor = random.choices(population=[0, 1], weights=[70, 30], k=1) elif random_risk_s == 9: random_riskcolor = random.choices(population=[0, 1], weights=[80, 20], k=1) elif random_risk_s == 10: random_riskcolor = random.choices(population=[0, 1], weights=[90, 10], k=1) else: random_riskcolor = 0 # Pagos if random_riskcolor[0] == self.player.ET_riskreturn: risk_pago = 10 else: risk_pago = 0 if random_riskcolor[0] == 0: colorbola = 'blanca' else: colorbola = 'negra' pago_final = (risk_pago + 10) * 1000 # ********** Se escoge como juego a pagar el S2-M2 (AmbiguityExperiment) *********************** elif random_game == 2: if self.player.ET_ambiguityreturn == 0: ambiguitycolorPE = 'blanco' else: ambiguitycolorPE = 'negro' if self.player.ET_ambiguityreturn == 0: ambiguity_colorchoicey = 0 ambiguity_colorchoicen = 1 else: ambiguity_colorchoicey = 1 ambiguity_colorchoicen = 0 # Esta es la situación que escogerá el computador. random_ambiguity_s = random.choice([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) # Esta es la urna que escoge el individuo en cada situación if random_ambiguity_s == 1: ambiguitydecision = self.player.a1 elif random_ambiguity_s == 2: ambiguitydecision = self.player.a2 elif random_ambiguity_s == 3: ambiguitydecision = self.player.a3 elif random_ambiguity_s == 4: ambiguitydecision = self.player.a4 elif random_ambiguity_s == 5: ambiguitydecision = self.player.a5 elif random_ambiguity_s == 6: ambiguitydecision = self.player.a6 elif random_ambiguity_s == 7: ambiguitydecision = self.player.a7 elif random_ambiguity_s == 8: ambiguitydecision = self.player.a8 elif random_ambiguity_s == 9: ambiguitydecision = self.player.a9 elif random_ambiguity_s == 10: ambiguitydecision = self.player.a10 else: ambiguitydecision = self.player.a11 if ambiguitydecision == 1: urna = 'Urna A' else: urna = 'Urna B' # El color de la bola extraída (en caso de que sea Urna A o Urna B) if ambiguitydecision == 2: randomcolor = random.choice([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) prob = randomcolor * 10 random_ambiguitycolor = random.choices(population=[0, 1], weights=[prob, 100 - prob], k=1) # Pagos if random_ambiguitycolor == self.player.ET_ambiguityreturn: ambiguity_pago = 10 else: ambiguity_pago = 0 else: if random_ambiguity_s == 1: random_ambiguitycolor = 1 elif random_ambiguity_s == 2: random_ambiguitycolor = random.choices(population=[ambiguity_colorchoicey, ambiguity_colorchoicen], weights=[10, 90], k=1) elif random_ambiguity_s == 3: random_ambiguitycolor = random.choices(population=[ambiguity_colorchoicey, ambiguity_colorchoicen], weights=[20, 80], k=1) elif random_ambiguity_s == 4: random_ambiguitycolor = random.choices(population=[ambiguity_colorchoicey, ambiguity_colorchoicen], weights=[30, 70], k=1) elif random_ambiguity_s == 5: random_ambiguitycolor = random.choices(population=[ambiguity_colorchoicey, ambiguity_colorchoicen], weights=[40, 60], k=1) elif random_ambiguity_s == 6: random_ambiguitycolor = random.choices(population=[ambiguity_colorchoicey, ambiguity_colorchoicen], weights=[50, 50], k=1) elif random_ambiguity_s == 7: random_ambiguitycolor = random.choices(population=[ambiguity_colorchoicey, ambiguity_colorchoicen], weights=[60, 40], k=1) elif random_ambiguity_s == 8: random_ambiguitycolor = random.choices(population=[ambiguity_colorchoicey, ambiguity_colorchoicen], weights=[70, 30], k=1) elif random_ambiguity_s == 9: random_ambiguitycolor = random.choices(population=[ambiguity_colorchoicey, ambiguity_colorchoicen], weights=[80, 20], k=1) elif random_ambiguity_s == 10: random_ambiguitycolor = random.choices(population=[ambiguity_colorchoicey, ambiguity_colorchoicen], weights=[90, 10], k=1) else: random_ambiguitycolor = 0 # Pagos if random_ambiguitycolor == self.player.ET_ambiguityreturn: ambiguity_pago = 10 else: ambiguity_pago = 0 if random_ambiguitycolor == 0: colorbola = 'blanca' else: colorbola = 'negra' pago_final = (ambiguity_pago + 10) * 1000 # ********** Se escoge como juego a pagar el S2-M3 (LossExperiment) *********************** else: # Esta es la situación que escogerá el computador. random_risk_ar = random.choice([1, 2, 3, 4, 5, 6]) # Esta es la decisión que escoge el individuo en cada situación if random_risk_ar == 1: riskadecision = self.player.ra1 elif random_risk_ar == 2: riskadecision = self.player.ra2 elif random_risk_ar == 3: riskadecision = self.player.ra3 elif random_risk_ar == 4: riskadecision = self.player.ra4 elif random_risk_ar == 5: riskadecision = self.player.ra5 else: riskadecision = self.player.ra6 Et_loss = random_risk_ar + 1 # Escojo qué sale en la moneda coin_toss = random.choice([0, 1]) if riskadecision == 0: acepto = "aceptar" won2 = False if coin_toss == 0: moneda = "cara" won = False elif coin_toss == 1: moneda = "sello" won = True elif riskadecision == 1: acepto = "rechazar" won2 = True won = False if coin_toss == 0: moneda = "cara" else: moneda = "sello" pago_final = (Et_loss + 10) * 1000 return dict(random_game=random_game, riskcolorPE=riskcolorPE, random_risk_s=random_risk_s, riskdecision=riskdecision, pago_final=pago_final, urna=urna, random_riskcolor=random_riskcolor, risk_pago=risk_pago, colorbola=colorbola, ambiguitycolorPE=ambiguitycolorPE, ambiguity_colorchoicey=ambiguity_colorchoicey, ambiguity_colorchoicen=ambiguity_colorchoicen, random_ambiguity_s=random_ambiguity_s, ambiguitydecision=ambiguitydecision, randomcolor=randomcolor, prob=prob, random_ambiguitycolor=random_ambiguitycolor, ambiguity_pago=ambiguity_pago, random_risk_ar=random_risk_ar, riskadecision=riskadecision, moneda=moneda, won=won, acepto=acepto, Et_loss=Et_loss, won2=won2 ) # ********************************************** STAGE 3 ******************************************************** # *** Cuestionario *** class S3_questionnaire(Page): form_model = 'player' form_fields = ['p2', 'p3', 'p4', 'p5', 'p6', 'p7', 'p8', 'p9', 'p10', 'p11', 'p12', 'p13', 'p14', 'p15a', 'p15b', 'p15c', 'p15d', 'p15e', 'p15f', 'p15g', 'p15h', 'p15i', 'p16', 'p17', 'p18', 'p19'] class WaitForAll(WaitPage): 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 la tecla F5 para refrescar la \ conexión y así poder avanzar más rápidamente" page_sequence = [ S0_instructions_H, S0_part1_municipalityquestions_H, S0_part1_municipalityresults_H, S0_part2_neighborhoodquestions_H, S0_part2_neighborhoodresults_H, S0_part3_hourquestions_H, S0_part3_hourresults_H, S1_instructions, S1_juego, S1_resultados, S2_A_introduccion, S2_B_instructions_risk, S2_C_juego_risk, S2_D_instructions_ambiguity, S2_E_juego_ambiguity, S2_F_instructions_loss, WaitForAll, S2_H_payment, S3_questionnaire, ]