from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants import random import numpy as np import re class EnterID(Page): form_model ='player' form_fields=['mturkID'] class Introduction(Page): pass class BeginSurvey(Page): # deploys class 'player' and display the following questions: age, gender, party, income form_model = 'player' form_fields = ['age', 'gender', 'race1', 'income'] def before_next_page(self): # if self.player.race1 == 'White': if self.player.race1 == 'White': choice_alter_race = ['White','Hispanic'] labels_age = ['25–29 years', '30–34 years','35-39 years'] labels_income = ['$40,000–$49,999', '$50,000–$59,999','$60,000–$69,999'] # The label and other information will be stored and passed to next application (main application) self.participant.vars['age'] = self.player.age if self.player.gender == 'Male': self.participant.vars['gender'] = 'male' if self.player.gender == 'Female': self.participant.vars['gender'] = 'female' self.participant.vars['race1'] = self.player.race1 self.participant.vars['income'] = self.player.income # populates race randomly if self.player.race1 == 'White': self.participant.vars['playerB_race'] = random.choice(["White","Hispanic"]) self.player.playerB_race = self.participant.vars['playerB_race'] self.participant.vars['playerC_race'] = random.choice(["White","Hispanic"]) self.player.playerC_race = self.participant.vars['playerC_race'] # elif self.player.race1 == 'Hispanic/Latino(a/x)': # self.participant.vars['playerB_race'] = 'White' # self.player.playerB_race = self.participant.vars['playerB_race'] # self.participant.vars['playerC_race'] = 'White' # self.player.playerC_race = self.participant.vars['playerC_race'] # participant gender is used as alter gender if self.player.gender == 'Something else': self.participant.vars['playerB_gender'] = random.choice(['male','female']) self.player.playerB_gender = self.participant.vars['playerB_gender'] self.participant.vars['playerC_gender'] = self.player.playerB_gender self.player.playerC_gender = self.participant.vars['playerC_gender'] elif self.player.gender == 'Male' or self.player.gender == 'Female': self.participant.vars['playerB_gender'] = self.participant.vars['gender'] self.player.playerB_gender = self.participant.vars['playerB_gender'] self.participant.vars['playerC_gender'] = self.participant.vars['gender'] self.player.playerC_gender = self.participant.vars['playerC_gender'] # populates age randomly self.participant.vars['playerB_age'] = random.choice(labels_age) self.player.playerB_age = self.participant.vars['playerB_age'] self.participant.vars['playerC_age'] = random.choice(labels_age) self.player.playerC_age = self.participant.vars['playerC_age'] # populates income randomly self.participant.vars['playerB_income'] = random.choice(labels_income) self.player.playerB_income = self.participant.vars['playerB_income'] self.participant.vars['playerC_income'] = random.choice(labels_income) self.player.playerC_income = self.participant.vars['playerC_income'] ### created for the "selection scenario" # define round 2 selection # if self.player.race1=='Hispanic/Latino(a/x)': # self.participant.vars['selection']= 0 # self.player.selection = self.participant.vars['selection'] if self.player.race1 == 'White': self.participant.vars['selection']= random.choice([0,1]) self.player.selection = self.participant.vars['selection'] self.participant.vars['chosen_alter1_race'] = random.choice(choice_alter_race) self.player.chosen_alter1_race = self.participant.vars['chosen_alter1_race'] self.participant.vars['chosen_alter1_gender'] = self.player.playerB_gender self.player.chosen_alter1_gender = self.participant.vars['chosen_alter1_gender'] self.participant.vars['chosen_alter1_age'] = random.choice(labels_age) self.player.chosen_alter1_age = self.participant.vars['chosen_alter1_age'] self.participant.vars['chosen_alter1_income'] = random.choice(labels_income) self.player.chosen_alter1_income = self.participant.vars['chosen_alter1_income'] if self.player.chosen_alter1_race == "White": self.participant.vars['chosen_alter2_race'] = "Hispanic" self.player.chosen_alter2_race = self.participant.vars['chosen_alter2_race'] else: self.participant.vars['chosen_alter2_race'] = "White" self.player.chosen_alter2_race = self.participant.vars['chosen_alter2_race'] self.participant.vars['chosen_alter2_gender'] = self.player.playerB_gender self.player.chosen_alter2_gender = self.participant.vars['chosen_alter2_gender'] self.participant.vars['chosen_alter2_age'] = random.choice(labels_age) self.player.chosen_alter2_age = self.participant.vars['chosen_alter2_age'] self.participant.vars['chosen_alter2_income'] = random.choice(labels_income) self.player.chosen_alter2_income = self.participant.vars['chosen_alter2_income'] lf_index = ['lf1','lf2','lf3','lf4','lf5','lf6','lf7','lf8','lf9','lf10','lf11','lf12'] lf_displayed = random.sample(lf_index,6) wf_index = ['wf1','wf2','wf3','wf4','wf5','wf6','wf7','wf8','wf9','wf10','wf11','wf12'] wf_displayed = random.sample(wf_index,6) lm_index = ['lm1','lm2','lm3','lm4','lm5','lm6','lm7','lm8','lm9','lm10','lm11','lm12'] lm_displayed = random.sample(lm_index,6) wm_index = ['wm1','wm2','wm3','wm4','wm5','wm6','wm7','wm8','wm9','wm10','wm11','wm12'] wm_displayed = random.sample(wm_index,6) chosen_fotos = (lf_displayed + wf_displayed + lm_displayed + wm_displayed) lf_asked = random.sample(lf_index,9) wf_asked = random.sample(wf_index,9) lm_asked = random.sample(lm_index,9) wm_asked = random.sample(wm_index,9) asked_fotos = (lf_asked + wf_asked + lm_asked + wm_asked) for img in chosen_fotos: img_name = 'show_{}'.format(img) if img in chosen_fotos: self.participant.vars[img] = 1 setattr(self.player,img_name,self.participant.vars[img]) else: self.participant.vars[img] = 0 setattr(self.player,img_name,self.participant.vars[img]) for img in asked_fotos: img_name = 'ask_{}'.format(img) if img in asked_fotos: self.participant.vars[img] = 1 setattr(self.player,img_name,self.participant.vars[img]) else: self.participant.vars[img] = 0 setattr(self.player,img_name,self.participant.vars[img]) # For other people, jump to exit page class Exit(Page): def is_displayed(self): if self.player.race1 == 'White': # if self.player.race1 == 'White' or self.player.race1=='Hispanic/Latino(a/x)': return False else: return True def vars_for_template(self): return{ 'redemption_code': self.participant.label or self.participant.code } class firstIntro(Page): # White players might be player A or B in either rounds # Hispanic players are always Player B in round 1, they might be A or B in round 2 def before_next_page(self): if self.player.race1 == 'White': self.participant.vars['role_round1'] = np.random.choice(['A','B'], p=[0.97, 0.03]) self.player.role_round1 = self.participant.vars['role_round1'] self.participant.vars['role_round2'] = self.player.role_round1 self.player.role_round2 = self.participant.vars['role_round2'] # elif self.player.race1 == 'Hispanic/Latino(a/x)': # self.participant.vars['role_round1'] = 'B' # self.player.role_round1 = self.participant.vars['role_round1'] # # self.participant.vars['role_round2'] = 'B' # self.player.role_round2 = self.participant.vars['role_round2'] class secondIntro(Page): pass class secondIntroB(Page): pass class ftlf1(Page): template_name = 'tg2021/ft_lf_1.html' timeout_seconds = 2 def is_displayed(self): if self.player.show_lf1 == 1: return True else: return False class ftlf2(Page): template_name = 'tg2021/ft_lf_2.html' timeout_seconds = 2 def is_displayed(self): if self.player.show_lf2 == 1: return True else: return False class ftlf3(Page): template_name = 'tg2021/ft_lf_3.html' timeout_seconds = 2 def is_displayed(self): if self.player.show_lf3 == 1: return True else: return False class ftlf4(Page): template_name = 'tg2021/ft_lf_4.html' timeout_seconds = 2 def is_displayed(self): if self.player.show_lf4 == 1: return True else: return False class ftlf5(Page): template_name = 'tg2021/ft_lf_5.html' timeout_seconds = 2 def is_displayed(self): if self.player.show_lf5 == 1: return True else: return False class ftlf6(Page): template_name = 'tg2021/ft_lf_6.html' timeout_seconds = 2 def is_displayed(self): if self.player.show_lf6 == 1: return True else: return False class ftlf7(Page): template_name = 'tg2021/ft_lf_7.html' timeout_seconds = 2 def is_displayed(self): if self.player.show_lf7 == 1: return True else: return False class ftlf8(Page): template_name = 'tg2021/ft_lf_8.html' timeout_seconds = 2 def is_displayed(self): if self.player.show_lf8 == 1: return True else: return False class ftlf9(Page): template_name = 'tg2021/ft_lf_9.html' timeout_seconds = 2 def is_displayed(self): if self.player.show_lf9 == 1: return True else: return False class ftlf10(Page): template_name = 'tg2021/ft_lf_10.html' timeout_seconds = 2 def is_displayed(self): if self.player.show_lf10 == 1: return True else: return False class ftlf11(Page): template_name = 'tg2021/ft_lf_11.html' timeout_seconds = 2 def is_displayed(self): if self.player.show_lf11 == 1: return True else: return False class ftlf12(Page): template_name = 'tg2021/ft_lf_12.html' timeout_seconds = 2 def is_displayed(self): if self.player.show_lf12 == 1: return True else: return False class ftlm1(Page): template_name = 'tg2021/ft_lm_1.html' timeout_seconds = 2 def is_displayed(self): if self.player.show_lm1 == 1: return True else: return False class ftlm2(Page): template_name = 'tg2021/ft_lm_2.html' timeout_seconds = 2 def is_displayed(self): if self.player.show_lm2 == 1: return True else: return False class ftlm3(Page): template_name = 'tg2021/ft_lm_3.html' timeout_seconds = 2 def is_displayed(self): if self.player.show_lm3 == 1: return True else: return False class ftlm4(Page): template_name = 'tg2021/ft_lm_4.html' timeout_seconds = 2 def is_displayed(self): if self.player.show_lm4 == 1: return True else: return False class ftlm5(Page): template_name = 'tg2021/ft_lm_5.html' timeout_seconds = 2 def is_displayed(self): if self.player.show_lm5 == 1: return True else: return False class ftlm6(Page): template_name = 'tg2021/ft_lm_6.html' timeout_seconds = 2 def is_displayed(self): if self.player.show_lm6 == 1: return True else: return False class ftlm7(Page): template_name = 'tg2021/ft_lm_7.html' timeout_seconds = 2 def is_displayed(self): if self.player.show_lm7 == 1: return True else: return False class ftlm8(Page): template_name = 'tg2021/ft_lm_8.html' timeout_seconds = 2 def is_displayed(self): if self.player.show_lm8 == 1: return True else: return False class ftlm9(Page): template_name = 'tg2021/ft_lm_9.html' timeout_seconds = 2 def is_displayed(self): if self.player.show_lm9 == 1: return True else: return False class ftlm10(Page): template_name = 'tg2021/ft_lm_10.html' timeout_seconds = 2 def is_displayed(self): if self.player.show_lm10 == 1: return True else: return False class ftlm11(Page): template_name = 'tg2021/ft_lm_11.html' timeout_seconds = 2 def is_displayed(self): if self.player.show_lm11 == 1: return True else: return False class ftlm12(Page): template_name = 'tg2021/ft_lm_12.html' timeout_seconds = 2 def is_displayed(self): if self.player.show_lm12 == 1: return True else: return False class ftwf1(Page): template_name = 'tg2021/ft_wf_1.html' timeout_seconds = 2 def is_displayed(self): if self.player.show_wf1 == 1: return True else: return False class ftwf2(Page): template_name = 'tg2021/ft_wf_2.html' timeout_seconds = 2 def is_displayed(self): if self.player.show_wf2 == 1: return True else: return False class ftwf3(Page): template_name = 'tg2021/ft_wf_3.html' timeout_seconds = 2 def is_displayed(self): if self.player.show_wf3 == 1: return True else: return False class ftwf4(Page): template_name = 'tg2021/ft_wf_4.html' timeout_seconds = 2 def is_displayed(self): if self.player.show_wf4 == 1: return True else: return False class ftwf5(Page): template_name = 'tg2021/ft_wf_5.html' timeout_seconds = 2 def is_displayed(self): if self.player.show_wf5 == 1: return True else: return False class ftwf6(Page): template_name = 'tg2021/ft_wf_6.html' timeout_seconds = 2 def is_displayed(self): if self.player.show_wf6 == 1: return True else: return False class ftwf7(Page): template_name = 'tg2021/ft_wf_7.html' timeout_seconds = 2 def is_displayed(self): if self.player.show_wf7 == 1: return True else: return False class ftwf8(Page): template_name = 'tg2021/ft_wf_8.html' timeout_seconds = 2 def is_displayed(self): if self.player.show_wf8 == 1: return True else: return False class ftwf9(Page): template_name = 'tg2021/ft_wf_9.html' timeout_seconds = 2 def is_displayed(self): if self.player.show_wf9 == 1: return True else: return False class ftwf10(Page): template_name = 'tg2021/ft_wf_10.html' timeout_seconds = 2 def is_displayed(self): if self.player.show_wf10 == 1: return True else: return False class ftwf11(Page): template_name = 'tg2021/ft_wf_11.html' timeout_seconds = 2 def is_displayed(self): if self.player.show_wf11 == 1: return True else: return False class ftwf12(Page): template_name = 'tg2021/ft_wf_12.html' timeout_seconds = 2 def is_displayed(self): if self.player.show_wf12 == 1: return True else: return False class ftwm1(Page): template_name = 'tg2021/ft_wm_1.html' timeout_seconds = 2 def is_displayed(self): if self.player.show_wm1 == 1: return True else: return False class ftwm2(Page): template_name = 'tg2021/ft_wm_2.html' timeout_seconds = 2 def is_displayed(self): if self.player.show_wm2 == 1: return True else: return False class ftwm3(Page): template_name = 'tg2021/ft_wm_3.html' timeout_seconds = 2 def is_displayed(self): if self.player.show_wm3 == 1: return True else: return False class ftwm4(Page): template_name = 'tg2021/ft_wm_4.html' timeout_seconds = 2 def is_displayed(self): if self.player.show_wm4 == 1: return True else: return False class ftwm5(Page): template_name = 'tg2021/ft_wm_5.html' timeout_seconds = 2 def is_displayed(self): if self.player.show_wm5 == 1: return True else: return False class ftwm6(Page): template_name = 'tg2021/ft_wm_6.html' timeout_seconds = 2 def is_displayed(self): if self.player.show_wm6 == 1: return True else: return False class ftwm7(Page): template_name = 'tg2021/ft_wm_7.html' timeout_seconds = 2 def is_displayed(self): if self.player.show_wm7 == 1: return True else: return False class ftwm8(Page): template_name = 'tg2021/ft_wm_8.html' timeout_seconds = 2 def is_displayed(self): if self.player.show_wm8 == 1: return True else: return False class ftwm9(Page): template_name = 'tg2021/ft_wm_9.html' timeout_seconds = 2 def is_displayed(self): if self.player.show_wm9 == 1: return True else: return False class ftwm10(Page): template_name = 'tg2021/ft_wm_10.html' timeout_seconds = 2 def is_displayed(self): if self.player.show_wm10 == 1: return True else: return False class ftwm11(Page): template_name = 'tg2021/ft_wm_11.html' timeout_seconds = 2 def is_displayed(self): if self.player.show_wm11 == 1: return True else: return False class ftwm12(Page): template_name = 'tg2021/ft_wm_12.html' timeout_seconds = 2 def is_displayed(self): if self.player.show_wm12 == 1: return True else: return False class qlf1(Page): template_name = 'tg2021/q_ft_lf_1.html' form_model = 'player' form_fields= ['q_lf1'] def is_displayed(self): if self.player.ask_lf1 == 1: return True else: return False class qlf2(Page): template_name = 'tg2021/q_ft_lf_2.html' form_model = 'player' form_fields= ['q_lf2'] def is_displayed(self): if self.player.ask_lf2 == 1: return True else: return False class qlf3(Page): template_name = 'tg2021/q_ft_lf_3.html' form_model = 'player' form_fields= ['q_lf3'] def is_displayed(self): if self.player.ask_lf3 == 1: return True else: return False class qlf4(Page): template_name = 'tg2021/q_ft_lf_4.html' form_model = 'player' form_fields= ['q_lf4'] def is_displayed(self): if self.player.ask_lf4 == 1: return True else: return False class qlf5(Page): template_name = 'tg2021/q_ft_lf_5.html' form_model = 'player' form_fields= ['q_lf5'] def is_displayed(self): if self.player.ask_lf5 == 1: return True else: return False class qlf6(Page): template_name = 'tg2021/q_ft_lf_6.html' form_model = 'player' form_fields= ['q_lf6'] def is_displayed(self): if self.player.ask_lf6 == 1: return True else: return False class qlf7(Page): template_name = 'tg2021/q_ft_lf_7.html' form_model = 'player' form_fields= ['q_lf7'] def is_displayed(self): if self.player.ask_lf7 == 1: return True else: return False class qlf8(Page): template_name = 'tg2021/q_ft_lf_8.html' form_model = 'player' form_fields= ['q_lf8'] def is_displayed(self): if self.player.ask_lf8 == 1: return True else: return False class qlf9(Page): template_name = 'tg2021/q_ft_lf_9.html' form_model = 'player' form_fields= ['q_lf9'] def is_displayed(self): if self.player.ask_lf9 == 1: return True else: return False class qlf10(Page): template_name = 'tg2021/q_ft_lf_10.html' form_model = 'player' form_fields= ['q_lf10'] def is_displayed(self): if self.player.ask_lf10 == 1: return True else: return False class qlf11(Page): template_name = 'tg2021/q_ft_lf_11.html' form_model = 'player' form_fields= ['q_lf11'] def is_displayed(self): if self.player.ask_lf11 == 1: return True else: return False class qlf12(Page): template_name = 'tg2021/q_ft_lf_12.html' form_model = 'player' form_fields= ['q_lf12'] def is_displayed(self): if self.player.ask_lf12 == 1: return True else: return False class qlm1(Page): template_name = 'tg2021/q_ft_lm_1.html' form_model = 'player' form_fields= ['q_lm1'] def is_displayed(self): if self.player.ask_lm1 == 1: return True else: return False class qlm2(Page): template_name = 'tg2021/q_ft_lm_2.html' form_model = 'player' form_fields= ['q_lm2'] def is_displayed(self): if self.player.ask_lm2 == 1: return True else: return False class qlm3(Page): template_name = 'tg2021/q_ft_lm_3.html' form_model = 'player' form_fields= ['q_lm3'] def is_displayed(self): if self.player.ask_lm3 == 1: return True else: return False class qlm4(Page): template_name = 'tg2021/q_ft_lm_4.html' form_model = 'player' form_fields= ['q_lm4'] def is_displayed(self): if self.player.ask_lm4 == 1: return True else: return False class qlm5(Page): template_name = 'tg2021/q_ft_lm_5.html' form_model = 'player' form_fields= ['q_lm5'] def is_displayed(self): if self.player.ask_lm5 == 1: return True else: return False class qlm6(Page): template_name = 'tg2021/q_ft_lm_6.html' form_model = 'player' form_fields= ['q_lm6'] def is_displayed(self): if self.player.ask_lm6 == 1: return True else: return False class qlm7(Page): template_name = 'tg2021/q_ft_lm_7.html' form_model = 'player' form_fields= ['q_lm7'] def is_displayed(self): if self.player.ask_lm7 == 1: return True else: return False class qlm8(Page): template_name = 'tg2021/q_ft_lm_8.html' form_model = 'player' form_fields= ['q_lm8'] def is_displayed(self): if self.player.ask_lm8 == 1: return True else: return False class qlm9(Page): template_name = 'tg2021/q_ft_lm_9.html' form_model = 'player' form_fields= ['q_lm9'] def is_displayed(self): if self.player.ask_lm9 == 1: return True else: return False class qlm10(Page): template_name = 'tg2021/q_ft_lm_10.html' form_model = 'player' form_fields= ['q_lm10'] def is_displayed(self): if self.player.ask_lm10 == 1: return True else: return False class qlm11(Page): template_name = 'tg2021/q_ft_lm_11.html' form_model = 'player' form_fields= ['q_lm11'] def is_displayed(self): if self.player.ask_lm11 == 1: return True else: return False class qlm12(Page): template_name = 'tg2021/q_ft_lm_12.html' form_model = 'player' form_fields= ['q_lm12'] def is_displayed(self): if self.player.ask_lm12 == 1: return True else: return False class qwf1(Page): template_name = 'tg2021/q_ft_wf_1.html' form_model = 'player' form_fields= ['q_wf1'] def is_displayed(self): if self.player.ask_wf1 == 1: return True else: return False class qwf2(Page): template_name = 'tg2021/q_ft_wf_2.html' form_model = 'player' form_fields= ['q_wf2'] def is_displayed(self): if self.player.ask_wf2 == 1: return True else: return False class qwf3(Page): template_name = 'tg2021/q_ft_wf_3.html' form_model = 'player' form_fields= ['q_wf3'] def is_displayed(self): if self.player.ask_wf3 == 1: return True else: return False class qwf4(Page): template_name = 'tg2021/q_ft_wf_4.html' form_model = 'player' form_fields= ['q_wf4'] def is_displayed(self): if self.player.ask_wf4 == 1: return True else: return False class qwf5(Page): template_name = 'tg2021/q_ft_wf_5.html' form_model = 'player' form_fields= ['q_wf5'] def is_displayed(self): if self.player.ask_wf5 == 1: return True else: return False class qwf6(Page): template_name = 'tg2021/q_ft_wf_6.html' form_model = 'player' form_fields= ['q_wf6'] def is_displayed(self): if self.player.ask_wf6 == 1: return True else: return False class qwf7(Page): template_name = 'tg2021/q_ft_wf_7.html' form_model = 'player' form_fields= ['q_wf7'] def is_displayed(self): if self.player.ask_wf7 == 1: return True else: return False class qwf8(Page): template_name = 'tg2021/q_ft_wf_8.html' form_model = 'player' form_fields= ['q_wf8'] def is_displayed(self): if self.player.ask_wf8 == 1: return True else: return False class qwf9(Page): template_name = 'tg2021/q_ft_wf_9.html' form_model = 'player' form_fields= ['q_wf9'] def is_displayed(self): if self.player.ask_wf9 == 1: return True else: return False class qwf10(Page): template_name = 'tg2021/q_ft_wf_10.html' form_model = 'player' form_fields= ['q_wf10'] def is_displayed(self): if self.player.ask_wf10 == 1: return True else: return False class qwf11(Page): template_name = 'tg2021/q_ft_wf_11.html' form_model = 'player' form_fields= ['q_wf11'] def is_displayed(self): if self.player.ask_wf11 == 1: return True else: return False class qwf12(Page): template_name = 'tg2021/q_ft_wf_12.html' form_model = 'player' form_fields= ['q_wf12'] def is_displayed(self): if self.player.ask_wf12 == 1: return True else: return False class qwm1(Page): template_name = 'tg2021/q_ft_wm_1.html' form_model = 'player' form_fields= ['q_wm1'] def is_displayed(self): return self.player.ask_wm1 == 1 class qwm2(Page): template_name = 'tg2021/q_ft_wm_2.html' form_model = 'player' form_fields= ['q_wm2'] def is_displayed(self): return self.player.ask_wm2 == 1 class qwm3(Page): template_name = 'tg2021/q_ft_wm_3.html' form_model = 'player' form_fields= ['q_wm3'] def is_displayed(self): return self.player.ask_wm3 == 1 class qwm4(Page): template_name = 'tg2021/q_ft_wm_4.html' form_model = 'player' form_fields= ['q_wm4'] def is_displayed(self): return self.player.ask_wm4 == 1 class qwm5(Page): template_name = 'tg2021/q_ft_wm_5.html' form_model = 'player' form_fields= ['q_wm5'] def is_displayed(self): return self.player.ask_wm5 == 1 class qwm6(Page): template_name = 'tg2021/q_ft_wm_6.html' form_model = 'player' form_fields= ['q_wm6'] def is_displayed(self): return self.player.ask_wm6 == 1 class qwm7(Page): template_name = 'tg2021/q_ft_wm_7.html' form_model = 'player' form_fields= ['q_wm7'] def is_displayed(self): return self.player.ask_wm7 == 1 class qwm8(Page): template_name = 'tg2021/q_ft_wm_8.html' form_model = 'player' form_fields= ['q_wm8'] def is_displayed(self): return self.player.ask_wm8 == 1 class qwm9(Page): template_name = 'tg2021/q_ft_wm_9.html' form_model = 'player' form_fields= ['q_wm9'] def is_displayed(self): return self.player.ask_wm9 == 1 class qwm10(Page): template_name = 'tg2021/q_ft_wm_10.html' form_model = 'player' form_fields= ['q_wm10'] def is_displayed(self): return self.player.ask_wm10 == 1 class qwm11(Page): template_name = 'tg2021/q_ft_wm_11.html' form_model = 'player' form_fields= ['q_wm11'] def is_displayed(self): return self.player.ask_wm11 == 1 class qwm12(Page): template_name = 'tg2021/q_ft_wm_12.html' form_model = 'player' form_fields= ['q_wm12'] def is_displayed(self): return self.player.ask_wm12 == 1 class CheckComprehension(Page): form_model = 'player' form_fields = ['quiz1_max','quiz2_min','quiz3_calc'] def before_next_page(self): if self.player.quiz1_max == 10 and self.player.quiz2_min == 0 and \ self.player.quiz3_calc == 20: self.player.correct = 1 else: self.player.correct = 0 class CheckComprehension2(Page): def is_displayed(self): return self.player.correct == 0 form_model = 'player' form_fields = ['quiz1_max','quiz2_min','quiz3_calc'] def before_next_page(self): if self.player.quiz1_max == 10 and self.player.quiz2_min == 0 and \ self.player.quiz3_calc == 20: self.player.correct = 1 else: self.player.correct = 0 class Exit2(Page): def is_displayed(self): return self.player.correct == 0 def vars_for_template(self): return{ 'redemption_code': self.participant.label or self.participant.code } class Waitingroom(Page): pass class playerInfoDisplay(Page): pass class makeContribution(Page): form_model = 'player' form_fields = ['contribution'] def is_displayed(self): return self.player.role_round1 == 'A' def before_next_page(self): self.player.contribution_dp = int(self.player.contribution) self.player.contribution_4x = int(self.player.contribution)*4 self.player.ego_kept_r1 = (10-self.player.contribution_dp) # strategy if A sends 5 self.participant.vars['B_r1_c5_sent'] = random.choice([0, 12]) self.player.B_r1_c5_sent = self.participant.vars['B_r1_c5_sent'] self.participant.vars['B_r1_c5_kept'] = int(20-self.player.B_r1_c5_sent) self.player.B_r1_c5_kept = self.participant.vars['B_r1_c5_kept'] # self.participant.vars['B_r1_c5_sent'] = 0 # self.player.B_r1_c5_sent = self.participant.vars['B_r1_c5_sent'] # self.participant.vars['B_r1_c5_kept'] = int(20-self.player.B_r1_c5_sent) # self.player.B_r1_c5_kept = self.participant.vars['B_r1_c5_kept'] #strategy if A sends 10 if self.player.B_r1_c5_sent == 0: self.participant.vars['B_r1_c10_sent'] = 0 self.player.B_r1_c10_sent = self.participant.vars['B_r1_c10_sent'] self.participant.vars['B_r1_c10_kept'] = int(40-self.player.B_r1_c10_sent) self.player.B_r1_c10_kept = self.participant.vars['B_r1_c10_kept'] elif self.player.B_r1_c5_sent == 12: self.participant.vars['B_r1_c10_sent'] = 22 self.player.B_r1_c10_sent = self.participant.vars['B_r1_c10_sent'] self.participant.vars['B_r1_c10_kept'] = int(40-self.player.B_r1_c10_sent) self.player.B_r1_c10_kept = self.participant.vars['B_r1_c10_kept'] class youSentCheck(Page): form_model = 'player' form_fields = ['check4xamount'] def is_displayed(self): return self.player.contribution != 0 and self.player.role_round1 == 'A' def before_next_page(self): self.player.contribution_dp = int(self.player.contribution) class guess_r1(Page): form_model = 'player' def get_form_fields(self): if self.player.role_round1 =='A': if self.player.contribution_dp == 5: return ['guess_alter_1a'] else: return ['guess_alter_1b'] if self.player.role_round1 == 'B': return ['guess_playerA_r1'] def is_displayed(self): if self.player.role_round1 == 'A': return self.player.contribution != 0 else: return True class Waitingroom2(Page): def is_displayed(self): return self.player.role_round1 == 'A' ### add?? class survey_contribution(Page): form_model ='player' form_fields =['reason_contribution'] class playerB_screen(Page): form_model = 'player' form_fields = ['if20','if40'] def before_next_page(self): self.participant.vars['playerA_sends_r1'] = random.choice([0,5,10]) self.player.playerA_sends_r1 = self.participant.vars['playerA_sends_r1'] def is_displayed(self): return self.player.role_round1 == 'B' class Results(Page): pass class Waitingroom3(Page): pass class playerInfoDisplay2(Page): form_model ='player' def get_form_fields(self): if self.player.selection == 1: return ['player_choice'] else: return [] class playerB_screen_r2(Page): form_model = 'player' form_fields = ['if20_r2','if40_r2'] def before_next_page(self): self.participant.vars['playerA_sends_r2'] = random.choice([0,5,10]) self.player.playerA_sends_r2 = self.participant.vars['playerA_sends_r2'] def is_displayed(self): return self.player.role_round2 == 'B' class makeContribution2(Page): form_model = 'player' form_fields = ['contribution_round2'] def is_displayed(self): return self.player.role_round2 == 'A' def before_next_page(self): self.player.contribution_round2_dp = int(self.player.contribution_round2) self.player.contribution_round2_4x = int(self.player.contribution_round2)*4 self.player.ego_kept_r2 = (10-self.player.contribution_round2_dp) # strategy if A sends 5 self.participant.vars['B_r2_c5_sent'] = random.choice([0, 12]) self.player.B_r2_c5_sent = self.participant.vars['B_r2_c5_sent'] self.participant.vars['B_r2_c5_kept'] = int(20-self.player.B_r2_c5_sent) self.player.B_r2_c5_kept = self.participant.vars['B_r2_c5_kept'] #strategy if A sends 10 if self.player.B_r2_c5_sent == 0: self.participant.vars['B_r2_c10_sent'] = 0 self.player.B_r2_c10_sent = self.participant.vars['B_r2_c10_sent'] self.participant.vars['B_r2_c10_kept'] = int(40-self.player.B_r2_c10_sent) self.player.B_r2_c10_kept = self.participant.vars['B_r2_c10_kept'] elif self.player.B_r2_c5_sent == 12: self.participant.vars['B_r2_c10_sent'] = 22 self.player.B_r2_c10_sent = self.participant.vars['B_r2_c10_sent'] self.participant.vars['B_r2_c10_kept'] = int(40-self.player.B_r2_c10_sent) self.player.B_r2_c10_kept = self.participant.vars['B_r2_c10_kept'] class youSentCheck2(Page): form_model = 'player' form_fields = ['check4xamount_round2'] ## sth up here? def is_displayed(self): return self.player.contribution_round2 != 0 and self.player.role_round2 == 'A' def before_next_page(self): self.player.contribution_round2_dp = int(self.player.contribution_round2) class guess_r2(Page): form_model = 'player' def get_form_fields(self): if self.player.role_round2 =='A': if self.player.contribution_round2_dp == 5: return ['guess_alter_2a'] else: return ['guess_alter_2b'] elif self.player.role_round2 =='B': return ['guess_playerA_r2'] def is_displayed(self): if self.player.role_round2 == 'A': return self.player.contribution_round2_dp != 0 else: return True class Waitingroom4(Page): def is_displayed(self): return self.player.role_round2 == 'A' class Results2(Page): form_model = 'player' def before_next_page(self): self.participant.vars['pick_round'] = random.choice([1,2]) self.player.pick_round = self.participant.vars['pick_round'] if self.player.pick_round == 1: if self.player.role_round1 == 'A': if self.player.contribution_dp == 5: self.participant.vars['ego_payoff'] = self.player.B_r1_c5_sent + self.player.ego_kept_r1 self.player.ego_payoff = self.participant.vars['ego_payoff'] elif self.player.contribution_dp == 10: self.participant.vars['ego_payoff'] = self.player.B_r1_c10_sent + self.player.ego_kept_r1 self.player.ego_payoff = self.participant.vars['ego_payoff'] elif self.player.contribution_dp == 0: self.participant.vars['ego_payoff'] = self.player.ego_kept_r1 self.player.ego_payoff = self.participant.vars['ego_payoff'] elif self.player.role_round1 == 'B': if self.player.playerA_sends_r1 == 0: self.participant.vars['ego_payoff'] = 0 self.player.ego_payoff = self.participant.vars['ego_payoff'] if self.player.playerA_sends_r1 == 5: if self.player.if20 == 'Keep §20 and send §0 back to Player A.': self.participant.vars['ego_payoff'] = 20 self.player.ego_payoff = self.participant.vars['ego_payoff'] elif self.player.if20 == 'Keep §8 and send §12 back to Player A.': self.participant.vars['ego_payoff'] = 8 self.player.ego_payoff = self.participant.vars['ego_payoff'] if self.player.playerA_sends_r1 == 10: if self.player.if40 == 'Keep §40 and send §0 back to Player A.': self.participant.vars['ego_payoff'] = 40 self.player.ego_payoff = self.participant.vars['ego_payoff'] elif self.player.if40 == 'Keep §18 and send §22 back to Player A.': self.participant.vars['ego_payoff'] = 18 self.player.ego_payoff = self.participant.vars['ego_payoff'] ## change contribution_dp to contribution_round2_dp elif self.player.pick_round ==2: if self.player.role_round2 == 'A': if self.player.contribution_round2_dp == 5: self.participant.vars['ego_payoff'] = self.player.B_r2_c5_sent + self.player.ego_kept_r2 self.player.ego_payoff = self.participant.vars['ego_payoff'] elif self.player.contribution_round2_dp == 10: self.participant.vars['ego_payoff'] = self.player.B_r2_c10_sent + self.player.ego_kept_r2 self.player.ego_payoff = self.participant.vars['ego_payoff'] elif self.player.contribution_round2_dp == 0: self.participant.vars['ego_payoff'] = self.player.ego_kept_r2 self.player.ego_payoff = self.participant.vars['ego_payoff'] elif self.player.role_round2 == 'B': if self.player.playerA_sends_r2 == 0: self.participant.vars['ego_payoff'] = 0 self.player.ego_payoff = self.participant.vars['ego_payoff'] # if question might need r2 if self.player.playerA_sends_r2 == 5: if self.player.if20_r2 == 'Keep §20 and send §0 back to Player A.': self.participant.vars['ego_payoff'] = 20 self.player.ego_payoff = self.participant.vars['ego_payoff'] elif self.player.if20_r2 == 'Keep §8 and send §12 back to Player A.': self.participant.vars['ego_payoff'] = 8 self.player.ego_payoff = self.participant.vars['ego_payoff'] if self.player.playerA_sends_r2 == 10: if self.player.if40_r2 == 'Keep §40 and send §0 back to Player A.': self.participant.vars['ego_payoff'] = 40 self.player.ego_payoff = self.participant.vars['ego_payoff'] elif self.player.if40_r2 == 'Keep §18 and send §22 back to Player A.': self.participant.vars['ego_payoff'] = 18 self.player.ego_payoff = self.participant.vars['ego_payoff'] self.participant.vars['ego_payoff_USD'] = self.player.ego_payoff * 0.05 self.player.ego_payoff_USD = round(self.participant.vars['ego_payoff_USD'],2) class thirdIntro(Page): pass class finalSurvey_party(Page): form_model = 'player' form_fields = ['party'] def before_next_page(self): self.participant.vars['party'] = self.player.party class finalSurvey_partyStr(Page): form_model = 'player' form_fields = ['party_strength'] def is_displayed(self): return self.player.party == 'Republican' or self.player.party == 'Democrat' def vars_for_template(self): return { 'party_label': 'Do you consider yourself a strong {} or not a very ' 'strong {}?'.format(self.participant.vars['party'], self.participant.vars['party']) } class finalSurvey_partyCloser(Page): form_model='player' form_fields =['party_closer'] def is_displayed(self): return self.player.party != 'Republican' and self.player.party != 'Democrat' class finalSurvey_vote(Page): form_model = 'player' form_fields = ['vote'] class finalSurvey_playerInfo(Page): form_model = 'player' form_fields = ['born','educ','fin_sat'] class finalSurvey_zipcode(Page): form_model = 'player' form_fields=['zipcode'] class finalSurvey_add(Page): form_model= 'player' form_fields = ['risk','wallet'] class finalSurvey_actPurpose(Page): form_model = 'player' form_fields = ['act_purpose'] class finalSurvey_actReaction(Page): form_model = 'player' form_fields = ['act_reaction'] class MemoryCheck1(Page): form_model = 'player' form_fields = ['mem_r1_age','mem_r1_gender','mem_r1_race','mem_r1_income'] class MemoryCheck2(Page): form_model = 'player' form_fields = ['mem_r2_age','mem_r2_gender','mem_r2_race','mem_r2_income'] class fourthIntro(Page): pass class FinalMessage(Page): def vars_for_template(self): return{ 'redemption_code': self.participant.label or self.participant.code } page_list = [ftwf1,ftwf2,ftwf3,ftwf4,ftwf5,ftwf6,ftwf7,ftwf8,ftwf9,ftwf10,ftwf11,ftwf12, ftwm1,ftwm2,ftwm3,ftwm4,ftwm5,ftwm6,ftwm7,ftwm8,ftwm9,ftwm10,ftwm11,ftwm12, ftlf1,ftlf2,ftlf3,ftlf4,ftlf5,ftlf6,ftlf7,ftlf8,ftlf9,ftlf10,ftlf11,ftlf12, ftlm1,ftlm2,ftlm3,ftlm4,ftlm5,ftlm6, ftlm7,ftlm8,ftlm9,ftlm10,ftlm11,ftlm12, ] randomized_list = random.sample(page_list,48) q_list = [qlf1,qlf2,qlf3,qlf4,qlf5,qlf6,qlf7,qlf8,qlf9,qlf10,qlf11,qlf12, qlm1,qlm2,qlm3,qlm4,qlm5,qlm6,qlm7,qlm8,qlm9,qlm10,qlm11,qlm12, qwf1,qwf2,qwf3,qwf4,qwf5,qwf6,qwf7,qwf8,qwf9,qwf10,qwf11,qwf12, qwm1,qwm2,qwm3,qwm4,qwm5,qwm6,qwm7,qwm8,qwm9,qwm10,qwm11,qwm12] randomized_q_list = random.sample(q_list,48) page_sequence = [ EnterID, Introduction, BeginSurvey, Exit, firstIntro, # randomized_list, ### secondIntro, secondIntroB, # secondIntroB] + randomized_list + \ # [ CheckComprehension, CheckComprehension2, Exit2, Waitingroom, playerInfoDisplay, makeContribution, ## only A playerB_screen, ## only B youSentCheck, # only round 1 A guess_r1, Waitingroom2, ## only round 1 A Results, Waitingroom3, playerInfoDisplay2, makeContribution2, # only A playerB_screen_r2, # only B youSentCheck2, # only round 2 A guess_r2, Waitingroom4, # only round 2 A Results2, finalSurvey_actPurpose, finalSurvey_actReaction, thirdIntro] + randomized_list + [ finalSurvey_party, finalSurvey_partyStr, finalSurvey_partyCloser, finalSurvey_vote, finalSurvey_add, finalSurvey_playerInfo, finalSurvey_zipcode, MemoryCheck1, MemoryCheck2, fourthIntro] + randomized_q_list + [ FinalMessage ]