from otree.api import * import pandas as pd import random doc = """ Your app description """ class C(BaseConstants): NAME_IN_URL = 'eval_phase3' PLAYERS_PER_GROUP = None NUM_ROUNDS = 1 AData = pd.read_csv('eval_phase3/AsianData.csv') # Asian Data for payment BData = pd.read_csv('eval_phase3/BlackData.csv') # Black Data for payment WData1 = pd.read_csv('eval_phase3/WhiteData1.csv') # White (vs Asian) Data for payment WData2 = pd.read_csv('eval_phase3/WhiteData2.csv') # White (vs Black) Data for payment class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): order0 = models.IntegerField() order1 = models.IntegerField() # demo+control w1 = models.FloatField() # choice for Whites ab1 = models.FloatField() # choice for Asians/Blacks r1 = models.IntegerField() # ratio choice # demo+control+freq wf1 = models.FloatField() # choice for Whites (with frequency) abf1 = models.FloatField() # choice for Asians/Blacks (with frequency) rf1 = models.IntegerField(initial=0) # ratio choice (with frequency) # info parameters wd = models.FloatField() wc = models.FloatField() abd = models.FloatField() abc = models.FloatField() freqw = models.FloatField() freqab = models.FloatField() infoS = models.StringField() infoM = models.StringField() # admin info consent_choice = models.StringField( label="", choices=["Consent", "Do not consent"], widget=widgets.RadioSelect ) prolific_id = models.StringField(label="What is your Prolific ID?") compG1 = models.IntegerField() compG2 = models.IntegerField() instlog = models.IntegerField() # Result info WId = models.StringField() mId = models.StringField() p1 = models.IntegerField() p2 = models.IntegerField() # PAGES class Consent(Page): pass class Consent2(Page): form_model = "player" form_fields = ['consent_choice'] class EndNowC(Page): @staticmethod def is_displayed(player): return player.consent_choice == 'Do not consent' class ProlificID(Page): form_model = "player" form_fields = ["prolific_id"] def before_next_page(player: Player, timeout_happened): dist0 = [1/6, 1/6, 1/6, 1/6, 1/6, 1/6] number0 = [1, 2, 3, 4, 5, 6] y = random.choices(number0, dist0, k=1) player.order0 = y[0] # player.order0 = player.participant.id_in_session dist1 = [1/2, 1/2] number1 = [0, 1] y1 = random.choices(number1, dist1, k=1) player.order1 = y1[0] # 1= demo, 0 = control # player.order1 = 1 if player.order0 == 1: # 1 = social h, White vs Asian player.wd = 14.10 player.wc = 12.64 player.abd = 13.69 player.abc = 12.25 player.freqw = 54 player.freqab = 60 player.infoS = 'over 2' player.infoM = '' if player.order0 == 2: # 2 = social l, White vs Asian player.wd = 12.04 player.wc = 12.24 player.abd = 11.83 player.abc = 13.59 player.freqw = 58 player.freqab = 48 player.infoS = '0-2' player.infoM = '' if player.order0 == 3: # 3 = comb hh, White vs Asian player.wd = 15.12 player.wc = 13.90 player.abd = 15.27 player.abc = 12.46 player.freqw = 44 player.freqab = 44 player.infoS = 'over 2' player.infoM = 'over 3' if player.order0 == 4: # 4 = comb ll, White vs Asian player.wd = 12.35 player.wc = 12.42 player.abd = 12.45 player.abc = 14.13 player.freqw = 46 player.freqab = 50 player.infoS = '0-2' player.infoM = '0-3' if player.order0 == 5: # 5 = math l, White vs Black player.wd = 11.65 player.wc = 11.43 player.abd = 11.43 player.abc = 12.69 player.freqw = 14 player.freqab = 10 player.infoS = '' player.infoM = '0-3' if player.order0 == 6: # 6 = comb hh, White vs Black player.wd = 15.12 player.wc = 13.90 player.abd = 15.63 player.abc = 13.08 player.freqw = 44 player.freqab = 29 player.infoS = 'over 2' player.infoM = 'over 3' class InstG(Page): form_model = "player" form_fields = ["compG1", "instlog"] @staticmethod def error_message(player, values): if values['compG1'] != 2: return 'Please try again.' class InstG2(Page): form_model = "player" form_fields = ["compG2"] @staticmethod def error_message(player, values): if values['compG2'] != 1: return 'Please try again.' class Task1(Page): form_model = 'player' form_fields = ['w1', 'ab1', 'r1'] def vars_for_template(player: Player): infS = player.infoS infM = player.infoM wd = player.wd wc = player.wc ad = player.abd ac = player.abc amtd1 = round(25*wd/(wd+ad),2) amtd2 = 25-amtd1 amtc1 = round(25*wc/(wc+ac),2) amtc2 = 25-amtc1 return dict( infS=infS, infM=infM, wd=wd, wc=wc, ad=ad, ac=ac, amtd1=amtd1, amtd2=amtd2, amtc1=amtc1, amtc2=amtc2 ) class Task2(Page): form_model = 'player' form_fields = ['wf1', 'abf1', 'rf1'] def vars_for_template(player: Player): infS = player.infoS infM = player.infoM wd = player.wd wc = player.wc ad = player.abd ac = player.abc fw = player.freqw fa = player.freqab fw2 = 100-player.freqw fa2 = 100-player.freqab amtd1 = round(25 * wd / (wd + ad), 2) amtd2 = 25 - amtd1 amtc1 = round(25 * wc / (wc + ac), 2) amtc2 = 25 - amtc1 return dict( infS=infS, infM=infM, wd=wd, wc=wc, ad=ad, ac=ac, fw=fw, fa=fa, fw2=fw2, fa2=fa2, amtd1=amtd1, amtd2=amtd2, amtc1=amtc1, amtc2=amtc2 ) class Results(Page): form_model = 'player' def before_next_page(player: Player, timeout_happened): IDAsian = C.AData.values IDBlack = C.BData.values IDWhite1 = C.WData1.values IDWhite2 = C.WData2.values if player.order0 == 1: # 1 = social h, White vs Asian Acandi = int(random.uniform(0, 43)) if Acandi == 43: Acandi = 42 Wcandi = int(random.uniform(0, 35)) if Wcandi == 35: Wcandi = 34 player.WId = IDWhite1[Wcandi][0] player.p1 = IDWhite1[Wcandi][3] player.mId = IDAsian[Acandi][0] player.p2 = IDAsian[Acandi][3] if player.order0 == 2: # 2 = social l, White vs Asian Acandi = int(random.uniform(43, 95)) if Acandi == 95: Acandi = 94 Wcandi = int(random.uniform(35, 95)) if Wcandi == 95: Wcandi = 94 player.WId = IDWhite1[Wcandi][0] player.p1 = IDWhite1[Wcandi][3] player.mId = IDAsian[Acandi][0] player.p2 = IDAsian[Acandi][3] if player.order0 == 3: # 3 = comb hh, White vs Asian Acandi = int(random.uniform(0, 32)) if Acandi == 32: Acandi = 31 Wcandi = int(random.uniform(0, 18)) if Wcandi == 18: Wcandi = 17 player.WId = IDWhite1[Wcandi][0] player.p1 = IDWhite1[Wcandi][4] player.mId = IDAsian[Acandi][0] player.p2 = IDAsian[Acandi][4] if player.order0 == 4: # 4 = comb ll, White vs Asian Acandi = int(random.uniform(65, 95)) if Acandi == 95: Acandi = 94 Wcandi = int(random.uniform(49, 95)) if Wcandi == 95: Wcandi = 94 player.WId = IDWhite1[Wcandi][0] player.p1 = IDWhite1[Wcandi][3] player.mId = IDAsian[Acandi][0] player.p2 = IDAsian[Acandi][3] if player.order0 == 5: # 5 = math l, White vs Black Bcandi = int(random.uniform(0, 62)) if Bcandi == 62: Bcandi = 61 Wcandi = int(random.uniform(0, 63)) if Wcandi == 63: Wcandi = 62 player.mId = IDBlack[Bcandi][0] player.p2 = IDBlack[Bcandi][3] player.wID = IDWhite2[Wcandi][0] player.p2 = IDWhite2[Wcandi][3] if player.order0 == 6: # 6 = comb hh, White vs Black Bcandi = int(random.uniform(62, 86)) if Bcandi == 86: Bcandi = 85 Wcandi = int(random.uniform(63, 81)) if Wcandi == 81: Wcandi = 80 player.mId = IDBlack[Bcandi][0] player.p2 = IDBlack[Bcandi][4] player.wID = IDWhite2[Wcandi][0] player.p2 = IDWhite2[Wcandi][4] player.payoff = 0.05*(10*(player.p1+1)+10*(player.p2+1) - 25) class Results2(Page): def vars_for_template(player: Player): x = 0.5*(10*(player.p1+1)+10*(player.p2+1) - 25) if player.p1 == 0: t1 = 'Low' pay1 = 10 if player.p1 == 1: t1 ='High' pay1 = 20 if player.p2 == 0: t2 = 'Low' pay2 = 10 if player.p2 == 1: t2 ='High' pay2 = 20 if player.order1 == 0: g1 = 'Group 1' g2 = 'Group 2' if player.order1 == 1: g1 = 'White' if player.order0 < 5: g2 = 'Asian' if player.order0 > 4: g2 = 'Black' return dict( t1=t1, t2=t2, g1=g1, g2=g2, pay1=pay1, pay2=pay2, x=x ) page_sequence = [Consent, Consent2, EndNowC, ProlificID, InstG, InstG2, Task1, Task2, Results, Results2]