from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants class Pregunta(Page): form_model = 'player' form_fields = ['Encuestado', 'familia', 'confianza'] def error_message(self, values): print('values is', values) if values['Encuestado'] == 'a1' and values['familia'] == 'a2' or values['Encuestado'] == 'a1' and values['familia'] == 'b2' or values['Encuestado'] == 'b1' and values['familia'] == 'a2' or values['Encuestado'] == 'b1' and values['familia'] == 'b2' or values['Encuestado'] == 'c1' and values['familia'] == 'c2' or values['Encuestado'] == 'c1' and values['familia'] == 'd2' or values['Encuestado'] == 'd1' and values['familia'] == 'c2' or values['Encuestado'] == 'd1' and values['familia'] == 'd2': return 'Esta combinación no está disponible' def before_next_page(self): for p in self.subsession.get_players(): if p.Encuestado=="a1": p.procedencia2 = "Bogotá" elif p.Encuestado=="b1": p.procedencia2 = "Cartagena" elif p.Encuestado == "c1": p.procedencia2 = "Miami" elif p.Encuestado=="d1": p.procedencia2 = "Nueva York" for p in self.subsession.get_players(): if p.familia=="a2": p.familia2 = "Bogotá" elif p.familia=="b2": p.familia2 = "Cartagena" elif p.familia == "c2": p.familia2 = "Miami" elif p.familia=="d2": p.familia2 = "Nueva York" pass class Actividad_principal(Page): form_model = 'player' form_fields = ['Decision_carta1', 'Decision_carta2','Decision_carta3','Decision_carta4'] def before_next_page(self): self.player.Tipo_carta1 = Constants.B[self.participant.vars['orden'][self.round_number-1]][0] self.player.Tipo_carta2 = Constants.B[self.participant.vars['orden'][self.round_number-1]][1] self.player.Tipo_carta3 = Constants.B[self.participant.vars['orden'][self.round_number-1]][2] self.player.Tipo_carta4 = Constants.B[self.participant.vars['orden'][self.round_number-1]][3] def vars_for_template(self): if self.player.Encuestado== "a1" and self.player.familia== "c2": self.participant.vars['carta1'] = Constants.Bac[self.participant.vars['orden'][self.round_number-1]][0] self.participant.vars['carta2'] = Constants.Bac[self.participant.vars['orden'][self.round_number-1]][1] self.participant.vars['carta3'] = Constants.Bac[self.participant.vars['orden'][self.round_number-1]][2] self.participant.vars['carta4'] = Constants.Bac[self.participant.vars['orden'][self.round_number-1]][3] return dict( image_path1='Cartas/{}.png'.format(Constants.Bac[self.participant.vars['orden'][self.round_number-1]][0]), image_path2='Cartas/{}.png'.format(Constants.Bac[self.participant.vars['orden'][self.round_number-1]][1]), image_path3='Cartas/{}.png'.format(Constants.Bac[self.participant.vars['orden'][self.round_number-1]][2]), image_path4='Cartas/{}.png'.format(Constants.Bac[self.participant.vars['orden'][self.round_number-1]][3]), grupo=self.player.participant.vars['grupo'] ) elif self.player.Encuestado== "a1" and self.player.familia== "d2": self.participant.vars['carta1'] = Constants.Bad[self.participant.vars['orden'][self.round_number-1]][0] self.participant.vars['carta2'] = Constants.Bad[self.participant.vars['orden'][self.round_number-1]][1] self.participant.vars['carta3'] = Constants.Bad[self.participant.vars['orden'][self.round_number-1]][2] self.participant.vars['carta4'] = Constants.Bad[self.participant.vars['orden'][self.round_number-1]][3] return dict( image_path1='Cartas/{}.png'.format(Constants.Bad[self.participant.vars['orden'][self.round_number-1]][0]), image_path2='Cartas/{}.png'.format(Constants.Bad[self.participant.vars['orden'][self.round_number-1]][1]), image_path3='Cartas/{}.png'.format(Constants.Bad[self.participant.vars['orden'][self.round_number-1]][2]), image_path4='Cartas/{}.png'.format(Constants.Bad[self.participant.vars['orden'][self.round_number-1]][3]), grupo=self.player.participant.vars['grupo'] ) elif self.player.Encuestado== "b1" and self.player.familia== "c2": self.participant.vars['carta1'] = Constants.Bbc[self.participant.vars['orden'][self.round_number-1]][0] self.participant.vars['carta2'] = Constants.Bbc[self.participant.vars['orden'][self.round_number-1]][1] self.participant.vars['carta3'] = Constants.Bbc[self.participant.vars['orden'][self.round_number-1]][2] self.participant.vars['carta4'] = Constants.Bbc[self.participant.vars['orden'][self.round_number-1]][3] return dict( image_path1='Cartas/{}.png'.format(Constants.Bbc[self.participant.vars['orden'][self.round_number-1]][0]), image_path2='Cartas/{}.png'.format(Constants.Bbc[self.participant.vars['orden'][self.round_number-1]][1]), image_path3='Cartas/{}.png'.format(Constants.Bbc[self.participant.vars['orden'][self.round_number-1]][2]), image_path4='Cartas/{}.png'.format(Constants.Bbc[self.participant.vars['orden'][self.round_number-1]][3]), grupo=self.player.participant.vars['grupo'] ) elif self.player.Encuestado== "b1" and self.player.familia== "d2": self.participant.vars['carta1'] = Constants.Bbd[self.participant.vars['orden'][self.round_number-1]][0] self.participant.vars['carta2'] = Constants.Bbd[self.participant.vars['orden'][self.round_number-1]][1] self.participant.vars['carta3'] = Constants.Bbd[self.participant.vars['orden'][self.round_number-1]][2] self.participant.vars['carta4'] = Constants.Bbd[self.participant.vars['orden'][self.round_number-1]][3] return dict( image_path1='Cartas/{}.png'.format(Constants.Bbd[self.participant.vars['orden'][self.round_number-1]][0]), image_path2='Cartas/{}.png'.format(Constants.Bbd[self.participant.vars['orden'][self.round_number-1]][1]), image_path3='Cartas/{}.png'.format(Constants.Bbd[self.participant.vars['orden'][self.round_number-1]][2]), image_path4='Cartas/{}.png'.format(Constants.Bbd[self.participant.vars['orden'][self.round_number-1]][3]), grupo=self.player.participant.vars['grupo'] ) elif self.player.Encuestado== "c1" and self.player.familia== "a2": self.participant.vars['carta1'] = Constants.Bca[self.participant.vars['orden'][self.round_number-1]][0] self.participant.vars['carta2'] = Constants.Bca[self.participant.vars['orden'][self.round_number-1]][1] self.participant.vars['carta3'] = Constants.Bca[self.participant.vars['orden'][self.round_number-1]][2] self.participant.vars['carta4'] = Constants.Bca[self.participant.vars['orden'][self.round_number-1]][3] return dict( image_path1='Cartas/{}.png'.format(Constants.Bca[self.participant.vars['orden'][self.round_number-1]][0]), image_path2='Cartas/{}.png'.format(Constants.Bca[self.participant.vars['orden'][self.round_number-1]][1]), image_path3='Cartas/{}.png'.format(Constants.Bca[self.participant.vars['orden'][self.round_number-1]][2]), image_path4='Cartas/{}.png'.format(Constants.Bca[self.participant.vars['orden'][self.round_number-1]][3]), grupo=self.player.participant.vars['grupo'] ) elif self.player.Encuestado== "c1" and self.player.familia== "b2": self.participant.vars['carta1'] = Constants.Bcb[self.participant.vars['orden'][self.round_number-1]][0] self.participant.vars['carta2'] = Constants.Bcb[self.participant.vars['orden'][self.round_number-1]][1] self.participant.vars['carta3'] = Constants.Bcb[self.participant.vars['orden'][self.round_number-1]][2] self.participant.vars['carta4'] = Constants.Bcb[self.participant.vars['orden'][self.round_number-1]][3] return dict( image_path1='Cartas/{}.png'.format(Constants.Bcb[self.participant.vars['orden'][self.round_number-1]][0]), image_path2='Cartas/{}.png'.format(Constants.Bcb[self.participant.vars['orden'][self.round_number-1]][1]), image_path3='Cartas/{}.png'.format(Constants.Bcb[self.participant.vars['orden'][self.round_number-1]][2]), image_path4='Cartas/{}.png'.format(Constants.Bcb[self.participant.vars['orden'][self.round_number-1]][3]), grupo=self.player.participant.vars['grupo'] ) elif self.player.Encuestado== "d1" and self.player.familia== "a2": self.participant.vars['carta1'] = Constants.Bda[self.participant.vars['orden'][self.round_number-1]][0] self.participant.vars['carta2'] = Constants.Bda[self.participant.vars['orden'][self.round_number-1]][1] self.participant.vars['carta3'] = Constants.Bda[self.participant.vars['orden'][self.round_number-1]][2] self.participant.vars['carta4'] = Constants.Bda[self.participant.vars['orden'][self.round_number-1]][3] return dict( image_path1='Cartas/{}.png'.format(Constants.Bda[self.participant.vars['orden'][self.round_number-1]][0]), image_path2='Cartas/{}.png'.format(Constants.Bda[self.participant.vars['orden'][self.round_number-1]][1]), image_path3='Cartas/{}.png'.format(Constants.Bda[self.participant.vars['orden'][self.round_number-1]][2]), image_path4='Cartas/{}.png'.format(Constants.Bda[self.participant.vars['orden'][self.round_number-1]][3]), grupo=self.player.participant.vars['grupo'] ) elif self.player.Encuestado== "d1" and self.player.familia== "b2": self.participant.vars['carta1'] = Constants.Bdb[self.participant.vars['orden'][self.round_number-1]][0] self.participant.vars['carta2'] = Constants.Bdb[self.participant.vars['orden'][self.round_number-1]][1] self.participant.vars['carta3'] = Constants.Bdb[self.participant.vars['orden'][self.round_number-1]][2] self.participant.vars['carta4'] = Constants.Bdb[self.participant.vars['orden'][self.round_number-1]][3] return dict( image_path1='Cartas/{}.png'.format(Constants.Bdb[self.participant.vars['orden'][self.round_number-1]][0]), image_path2='Cartas/{}.png'.format(Constants.Bdb[self.participant.vars['orden'][self.round_number-1]][1]), image_path3='Cartas/{}.png'.format(Constants.Bdb[self.participant.vars['orden'][self.round_number-1]][2]), image_path4='Cartas/{}.png'.format(Constants.Bdb[self.participant.vars['orden'][self.round_number-1]][3]), grupo=self.player.participant.vars['grupo'] ) pass class Results(Page): form_model = 'player' form_fields = ['Decision_final'] def before_next_page(self): self.player.set_payoffs() def vars_for_template(self): path = dict( aimage_path1='Cartas/{}.png'.format(self.participant.vars['carta1']), aimage_path2='Cartas/{}.png'.format(self.participant.vars['carta2']), aimage_path3='Cartas/{}.png'.format(self.participant.vars['carta3']), aimage_path4='Cartas/{}.png'.format(self.participant.vars['carta4']) ) if self.player.Decision_carta1 == True and self.session.vars['c1'][self.round_number - 1]<0.8: if self.participant.vars['carta1'] == "a1": path["bimage_path1"]='Cartas/{}.png'.format("c2") elif self.participant.vars['carta1'] == "b1": path["bimage_path1"]='Cartas/{}.png'.format("d2") elif self.participant.vars['carta1'] == "c1": path["bimage_path1"]='Cartas/{}.png'.format("a2") elif self.participant.vars['carta1'] == "d1": path["bimage_path1"]='Cartas/{}.png'.format("b2") elif self.participant.vars['carta1'] == "a2": path["bimage_path1"]='Cartas/{}.png'.format("c1") elif self.participant.vars['carta1'] == "b2": path["bimage_path1"]='Cartas/{}.png'.format("d1") elif self.participant.vars['carta1'] == "c2": path["bimage_path1"]='Cartas/{}.png'.format("a1") elif self.participant.vars['carta1'] == "d2": path["bimage_path1"]='Cartas/{}.png'.format("b1") elif self.player.Decision_carta1 ==True and self.session.vars['c1'][self.round_number - 1]>=0.8: if self.participant.vars['carta1'] == "a1": path["bimage_path1"]='Cartas/{}.png'.format("d2") elif self.participant.vars['carta1'] == "b1": path["bimage_path1"]='Cartas/{}.png'.format("c2") elif self.participant.vars['carta1'] == "c1": path["bimage_path1"]='Cartas/{}.png'.format("b2") elif self.participant.vars['carta1'] == "d1": path["bimage_path1"]='Cartas/{}.png'.format("a2") elif self.participant.vars['carta1'] == "a2": path["bimage_path1"]='Cartas/{}.png'.format("d1") elif self.participant.vars['carta1'] == "b2": path["bimage_path1"]='Cartas/{}.png'.format("c1") elif self.participant.vars['carta1'] == "c2": path["bimage_path1"]='Cartas/{}.png'.format("b1") elif self.participant.vars['carta1'] == "d2": path["bimage_path1"]='Cartas/{}.png'.format("a1") elif self.player.Decision_carta1 == False : path["bimage_path1"] ='Cartas/{}.png'.format("x") if self.player.Decision_carta2 == True and self.session.vars['c2'][self.round_number - 1]<0.8: if self.participant.vars['carta2'] == "a1": path["image_path2"] = 'Cartas/{}.png'.format("c2") elif self.participant.vars['carta2'] == "b1": path["image_path2"] = 'Cartas/{}.png'.format("d2") elif self.participant.vars['carta2'] == "c1": path["image_path2"] ='Cartas/{}.png'.format("a2") elif self.participant.vars['carta2'] == "d1": path["image_path2"] ='Cartas/{}.png'.format("b2") elif self.participant.vars['carta2'] == "a2": path["image_path2"] ='Cartas/{}.png'.format("c1") elif self.participant.vars['carta2'] == "b2": path["image_path2"] ='Cartas/{}.png'.format("d1") elif self.participant.vars['carta2'] == "c2": path["image_path2"] ='Cartas/{}.png'.format("a1") elif self.participant.vars['carta2'] == "d2": path["image_path2"] ='Cartas/{}.png'.format("b1") elif self.player.Decision_carta2 ==True and self.session.vars['c2'][self.round_number - 1]>=0.8: if self.participant.vars['carta2'] == "a1": path["image_path2"] ='Cartas/{}.png'.format("d2") elif self.participant.vars['carta2'] == "b1": path["image_path2"] ='Cartas/{}.png'.format("c2") elif self.participant.vars['carta2'] == "c1": path["image_path2"] ='Cartas/{}.png'.format("b2") elif self.participant.vars['carta2'] == "d1": path["image_path2"] ='Cartas/{}.png'.format("a2") elif self.participant.vars['carta2'] == "a2": path["image_path2"] ='Cartas/{}.png'.format("d1") elif self.participant.vars['carta2'] == "b2": path["image_path2"] ='Cartas/{}.png'.format("c1") elif self.participant.vars['carta2'] == "c2": path["image_path2"] ='Cartas/{}.png'.format("b1") elif self.participant.vars['carta2'] == "d2": path["image_path2"] ='Cartas/{}.png'.format("a1") elif self.player.Decision_carta2 == False : path["image_path2"] ='Cartas/{}.png'.format("x") if self.player.Decision_carta3 == True and self.session.vars['c3'][self.round_number - 1]<0.8: if self.participant.vars['carta3'] == "a1": path["image_path3"] ='Cartas/{}.png'.format("c2") elif self.participant.vars['carta3'] == "b1": path["image_path3"] ='Cartas/{}.png'.format("d2") elif self.participant.vars['carta3'] == "c1": path["image_path3"] ='Cartas/{}.png'.format("a2") elif self.participant.vars['carta3'] == "d1": path["image_path3"] ='Cartas/{}.png'.format("b2") elif self.participant.vars['carta3'] == "a2": path["image_path3"] ='Cartas/{}.png'.format("c1") elif self.participant.vars['carta3'] == "b2": path["image_path3"] ='Cartas/{}.png'.format("d1") elif self.participant.vars['carta3'] == "c2": path["image_path3"] ='Cartas/{}.png'.format("a1") elif self.participant.vars['carta3'] == "d2": path["image_path3"] ='Cartas/{}.png'.format("b1") elif self.player.Decision_carta3 ==True and self.session.vars['c3'][self.round_number - 1]>=0.8: if self.participant.vars['carta3'] == "a1": path["image_path3"] = 'Cartas/{}.png'.format("d2") elif self.participant.vars['carta3'] == "b1": path["image_path3"] ='Cartas/{}.png'.format("c2") elif self.participant.vars['carta3'] == "c1": path["image_path3"] ='Cartas/{}.png'.format("b2") elif self.participant.vars['carta3'] == "d1": path["image_path3"] ='Cartas/{}.png'.format("a2") elif self.participant.vars['carta3'] == "a2": path["image_path3"] ='Cartas/{}.png'.format("d1") elif self.participant.vars['carta3'] == "b2": path["image_path3"] ='Cartas/{}.png'.format("c1") elif self.participant.vars['carta3'] == "c2": path["image_path3"] ='Cartas/{}.png'.format("b1") elif self.participant.vars['carta3'] == "d2": path["image_path3"] ='Cartas/{}.png'.format("a1") elif self.player.Decision_carta3 == False : path["image_path3"] ='Cartas/{}.png'.format("x") if self.player.Decision_carta4 == True and self.session.vars['c4'][self.round_number - 1]<0.8: if self.participant.vars['carta4'] == "a1": path["image_path4"] ='Cartas/{}.png'.format("c2") elif self.participant.vars['carta4'] == "b1": path["image_path4"] ='Cartas/{}.png'.format("d2") elif self.participant.vars['carta4'] == "c1": path["image_path4"] ='Cartas/{}.png'.format("a2") elif self.participant.vars['carta4'] == "d1": path["image_path4"] ='Cartas/{}.png'.format("b2") elif self.participant.vars['carta4'] == "a2": path["image_path4"] ='Cartas/{}.png'.format("c1") elif self.participant.vars['carta4'] == "b2": path["image_path4"] ='Cartas/{}.png'.format("d1") elif self.participant.vars['carta4'] == "c2": path["image_path4"] ='Cartas/{}.png'.format("a1") elif self.participant.vars['carta4'] == "d2": path["image_path4"] ='Cartas/{}.png'.format("b1") elif self.player.Decision_carta4 ==True and self.session.vars['c4'][self.round_number - 1]>=0.8: if self.participant.vars['carta4'] == "a1": path["image_path4"] ='Cartas/{}.png'.format("d2") elif self.participant.vars['carta4'] == "b1": path["image_path4"] ='Cartas/{}.png'.format("c2") elif self.participant.vars['carta4'] == "c1": path["image_path4"] ='Cartas/{}.png'.format("b2") elif self.participant.vars['carta4'] == "d1": path["image_path4"] ='Cartas/{}.png'.format("a2") elif self.participant.vars['carta4'] == "a2": path["image_path4"] ='Cartas/{}.png'.format("d1") elif self.participant.vars['carta4'] == "b2": path["image_path4"] ='Cartas/{}.png'.format("c1") elif self.participant.vars['carta4'] == "c2": path["image_path4"] ='Cartas/{}.png'.format("b1") elif self.participant.vars['carta4'] == "d2": path["image_path4"] ='Cartas/{}.png'.format("a1") elif self.player.Decision_carta4 == False : path["image_path4"] = 'Cartas/{}.png'.format("x") return path pass class T_Waiting_Results(WaitPage): wait_for_all_groups = True after_all_players_arrive = 'final_payoffs' page_sequence = [ Pregunta, Actividad_principal, Results, T_Waiting_Results ]