from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, ) import random class Constants(BaseConstants): name_in_url = 'treatmentgender' players_per_group = 6 num_rounds = 1 class Subsession(BaseSubsession): winnerscore = models.FloatField() loserscore = models.FloatField() winnername = models.StringField() temp1 = models.StringField() temp2 = models.StringField() temp3 = models.StringField() temp4 = models.StringField() class Group(BaseGroup): maxscore = models.FloatField() def math0_payoff(self): for p in self.get_players(): p.math0score = int(p.M0==4)+int(p.M1==18)+int(p.M2==27)+int(p.M12==30) +int(p.M13==30) +int(p.M14==19) +int(p.M15==62) +int(p.M16==26) +int(p.M17==22) +int(p.M18==26)+int(p.M19==7) +int(p.M20==52) +int(p.M21==79) +int(p.M22==63) +int(p.M23==22) +int(p.M24==10) +int(p.M25==20) +int(p.M26==20) +int(p.M27==18) +int(p.M28==22) def math1_payoff(self): for p in self.get_players(): p.winner = 0 p.otherwinner = 0 p.payoff = c(100) p.math1score = int(p.M3==2)+ int(p.M4==7)+ int(p.M5==1)+int(p.M29==2) +int(p.M30==6) +int(p.M31==11) +int(p.M32==27) +int(p.M33==3) +int(p.M34==9) +int(p.M35==7) +int(p.M36==25) +int(p.M37==4) +int(p.M38==1) +int(p.M39==70) +int(p.M40==2) +int(p.M41==5) +int(p.M42==4) +int(p.M43==14) +int(p.M44==6) +int(p.M45==2) p.payoff = p.payoff+ 8*p.math1score p.math1payoff = float(p.payoff) - 100 p.randommath1score = p.math1score + 0.5*(random.random()) maxscore = -1 for p in self.get_players(): if p.gender == 'F' : if p.randommath1score > maxscore: maxscore = p.randommath1score for p in self.get_players(): if p.gender == 'F' : if p.randommath1score == maxscore: p.winner = 1 Subsession.temp1 = "P"+ str(p.id_in_group) Subsession.temp2 = p.gender p.randommath1score = p.randommath1score - 1000 for p in self.get_players(): p.math1winnername = Subsession.temp1 p.math1winnergender = Subsession.temp2 maxscore = max([p.randommath1score for p in self.get_players()]) for p in self.get_players(): if p.randommath1score == maxscore: p.winner = 0 p.otherwinner = 1 Subsession.temp3 = "P"+ str(p.id_in_group) Subsession.temp4 = p.gender for p in self.get_players(): p.math1otherwinnername = Subsession.temp3 p.math1otherwinnergender = Subsession.temp4 def math2_payoff(self): for p in self.get_players(): if p.winner == 1 or p.otherwinner == 1: p.score = int(p.M6==3)+ int(p.M7==4)+ int(p.M8==47)+int(p.M46==12) +int(p.M47==6) +int(p.M48==10) +int(p.M49==12) +int(p.M50==5) +int(p.M51==4) +int(p.M52==15) + int(p.M53==3) +int(p.M54==10) +int(p.M55==2) +int(p.M56==8) +int(p.M57==18) +int(p.M58==9) +int(p.M59==5) +int(p.M60==50) +int(p.M61==5) +int(p.M62==5) p.payoff = p.payoff + 20*(p.score) p.randomscore = p.score + 0.5*(random.random()) else: p.randomscore = 0 maxscore = max([p.randomscore for p in self.get_players()]) for p in self.get_players(): if p.winner == 1 or p.otherwinner == 1: if p.randomscore == maxscore: p.math2winner = 1 p.math2loser = 0 Subsession.winnerscore= p.score Subsession.winnername = "P"+ str(p.id_in_group) p.payoff = p.payoff + c(100) p.math2payoff = float(p.payoff) - 100 - p.math1payoff else: p.math2payoff = float(p.payoff) - 100 - p.math1payoff p.math2loser = 1 p.math2winner = 0 Subsession.loserscore=p.score def gg_payoff(self): for p in self.get_players(): p.ggscore = 0 if p.winner == 0 and p.otherwinner == 0: p.guess1 = -100 p.guess2= -100 p.ggscore = int(p.M9 == Subsession.winnername) p.guess1 = abs(p.M10-Subsession.winnerscore) p.guess2 = abs(p.M11-Subsession.loserscore) p.payoff = p.payoff +max(c(0),c(0.5*(50 -15*p.guess2))+c(0.5*(50 -15*p.guess1))) if p.ggscore == 1 : p.payoff = p.payoff + c(50) for p in self.get_players(): if p.winner == 0 and p.otherwinner == 0: p.ggpayoff = float(p.payoff) - 100 - p.math1payoff class Player(BasePlayer): name = models.StringField(label='What is your name?') age = models.IntegerField(label='What is your age?') gender = models.StringField(label='What is your gender?', choices=[['M','M'],['F','F']]) background = models.StringField(label='What is your undergraduate background?', choices=[['Others','Others'],['Engineering','Engineering'],['Accounting ','Accounting '],['Advertising','Advertising'],['Apparel Production','Apparel Production'],['Applied Science','Applied Science'],['Bioinformatics','Bioinformatics'],['Biotechnology','Biotechnology'],['Avionics','Avionics'],['Business and Law','Business and Law'],['Business Administration','Business Administration'],['Business Analytics','Business Analytics'],['BMS','BMS'],['Dairy Technology','Dairy Technology'],['Economics ','Economics'],['Commerce','Commerce'],['Engineering Design','Engineering Design'],['Engineering Physics','Engineering Physics'],['Food Technology','Food Technology'],['Food Engineering','Food Engineering'],['Finance and accounts','Finance and accounts'],['Finance and law','Finance and law'],['Finance and Economics','Finance and Economics'],['Philosophy ','Philosophy '],['Physics','Physics'],['Political Science','Political Science'],['Psychology','Psychology'],['Tourism Admin','Tourism Admin'],['International Law','International Law'],['IT','IT'],['Healthcare ','Healthcare '],['Medicine and Surgery','Medicine and Surgery']]) backgroundother = models.StringField(label='If you chose Others, please enter the specalization', blank = True) testq1 = models.StringField(label='If a participant answers ‘x’ questions in MATH1, what are his/her earnings from MATH1?') testq2 = models.StringField(label='1. 6 participants play the game (Male P1,P2,P3 and Female P4,P5,P6). Their scores after MATH1 are in the following order– P1>P2>P4>P3>P5>P6. The two participants that move on to MATH2 are: ') testq3 = models.StringField(label='2. Participant 1 answers x correct questions in MATH1 and is selected for MATH2. In MATH2, the participant answers y questions and wins. Total Earnings are: ',choices=[['8x + 20y + 100','8x + 20y + 100'],['8x + 20y + 100 + 100 ','8x + 20y + 100 + 100 '],['8x + 20y','8x + 20y'],['8x + 200','8x + 200']], widget=widgets.RadioSelect) testq4 = models.StringField(label= '1. In the Prediction task, a participant guesses the winner correctly. The participant got zero from score predictions as his/her score guesses were very inaccurate. What are the participants total earnings from the Prediction Task:') testq5 = models.StringField(label= '2. Suppose a participant incorrectly guessed the winner. But the participant made accurate score predictions for the first MATH2 player (x1 = y1) but overestimated the score of the second MATH2 player by z (x2 – y2 = z). What are the participant’s total earnings from the Prediction Task?',choices=[['50 + 0.5(50 - 0) + 0.5(50 - 15*z)','50 + 0.5(50 - 0) + 0.5(50 - 15*z)'],['100','100'],['50 + 0.5(50 - 0) + 0.5(50 - 0)','50 + 0.5(50 - 0) + 0.5(50 - 0)'],['0 + 0.5(50 - 0) + 0.5(50 - 15*z)','0 + 0.5(50 - 0) + 0.5(50 - 15*z)']], widget=widgets.RadioSelect) #MATH0 questions M0 = models.FloatField(label="10-6") M1 = models.FloatField(label="30-12") M2 = models.FloatField(label="13+14") M12 = models.FloatField(label="45-15") M13 = models.FloatField(label="23+7") M14 = models.FloatField(label="29-10") M15 = models.FloatField(label="59+3") M16 = models.FloatField(label="12+14") M17 = models.FloatField(label="30-8") M18 = models.FloatField(label="40-14") M19 = models.FloatField(label="2+5") M20 = models.FloatField(label="46+6") M21 = models.FloatField(label="85-6") M22 = models.FloatField(label="56+7") M23 = models.FloatField(label="16+6") M24 = models.FloatField(label="16-6") M25 = models.FloatField(label="35-15") M26 = models.FloatField(label="13+7") M27 = models.FloatField(label="14+4") M28 = models.FloatField(label="17+5") #MATH1 questions M3 = models.FloatField(label="8 × (5 + 4) = a + 7 × 10", blank = True ) M4 = models.FloatField(label="(5 x 5 x 3) = 3 x a + 54", blank = True ) M5 = models.FloatField(label="18 ÷ (7 + 2) x (14 ÷ 2) = 16 x a - 2", blank = True ) M29 = models.FloatField(label="[7 + (28 ÷ 4)] ÷ 7 = 2 × a – 2", blank = True ) M30 = models.FloatField(label="6 + (72 ÷ 9) = a + (3 x 4) – 4", blank = True ) M31 = models.FloatField(label="(28 ÷ 7) x (12 - 4) = a + 25 – 4", blank = True ) M32 = models.FloatField(label="(6 + 7 x 8) ÷ (30 + 1) = a + 2 - 27", blank = True ) M33 = models.FloatField(label="8 + 9 x 6 - (25 ÷ 5) = 2 x a + 51", blank = True ) M34 = models.FloatField(label="(9 + 2) x (7 - 2) = 5 x a + 10", blank = True ) M35 = models.FloatField(label="(4 x 5) ÷ (19 - 17) = 59 - 7 x a ", blank = True ) M36 = models.FloatField(label="(16 ÷ 8) x (6 x 6) = 3 x a – 3", blank = True ) M37 = models.FloatField(label="32 - (3 x 5) + 4 = 4 x a + (65 ÷ 13)", blank = True ) M38 = models.FloatField(label="7 = 14 × a - (28 ÷ 4)", blank = True ) M39 = models.FloatField(label="5 + (18 - 6) x (3 + 2) = a - (55 ÷ 11)", blank = True ) M40 = models.FloatField(label="40 x (8 ÷ 4) = 20 x 2 x a", blank = True ) M41 = models.FloatField(label="3 + (5 + 6 ÷ 3) - (28 ÷ 4) + 5 = a + 3", blank = True ) M42 = models.FloatField(label="[5 + {28 - (19 - 7)}] = 37 – 4 x a", blank = True ) M43 = models.FloatField(label="2 x (96 ÷ 12) = (9 x 8) – 4 x a", blank = True ) M44 = models.FloatField(label="6 x (5 + 4) ÷ 3 – 7 = a + (25 ÷ 5)", blank = True ) M45 = models.FloatField(label="36 - 4 x 5 + (4 ÷ 2) = 8 x a + 2", blank = True ) #MATH2 questions M6 = models.FloatField(label="3 x [78 ÷ 26] = 5 x a – 6", blank = True ) M7 = models.FloatField(label="7 x (8 ÷ 2) - (6 ÷ 3) = 8 x a – 6", blank = True ) M8 = models.FloatField(label="5 + 5 x 8 - 3 = a – 9 + 4", blank = True ) M46 = models.FloatField(label="(54 ÷ (4 + 5)) x (4 ÷ 2) = 24 – a", blank = True ) M47 = models.FloatField(label="(12 ÷ 3) x 12 + 3 = 16 x a – 45", blank = True ) M48 = models.FloatField(label="2 x {13 - 1} + (6 ÷ 3) = 2 x a + 6", blank = True ) M49 = models.FloatField(label="(96 ÷ 12) + (14 x 2) = 2 x a + 12", blank = True ) M50 = models.FloatField(label="(6 + 4) x 5 = 11 x a - (10 ÷ 2)", blank = True ) M51 = models.FloatField(label="(6 ÷ 3) x (7 - 2) = 2 × a + 2", blank = True ) M52 = models.FloatField(label="45 + 2 x 3 = a + 40 - 16 ÷ 4", blank = True ) M53 = models.FloatField(label="16 + (8 ÷ 4) = 8 x a – (2 x 3)", blank = True ) M54 = models.FloatField(label="(14 + 15) + (21 ÷ 7) = 3 x a + 2", blank = True ) M55 = models.FloatField(label="4 x (16 - 8) + (24 ÷ 6) = 16 x a + 4", blank = True ) M56 = models.FloatField(label="[(16 - 4) ÷ 2] + (60 ÷ 6) = a + 8 ", blank = True ) M57 = models.FloatField(label="(25 + 11) x 2 = 100 – (40 ÷ 4) – a", blank = True ) M58 = models.FloatField(label="(8 + 3) x 9 ÷ 9 = a + (48 ÷ 24)", blank = True ) M59 = models.FloatField(label="48 ÷ (14 - 8) x 10 – 5 = 85 –2 x a", blank = True ) M60 = models.FloatField(label="73 - (2 x 8) = a + (14 ÷ 2) ", blank = True ) M61 = models.FloatField(label="4 + (42 ÷ 2 )+ 15 = 3 x a + 25", blank = True ) M62 = models.FloatField(label="[20 – 2 x (2 + 3)] = (45 ÷ 3) – a", blank = True ) #Prediction Task questions M9 = models.StringField(label="Who do you think will win?", choices = [['P','P'],['P1','P1'],['P2','P2'],['P3','P3'],['P4','P4'],['P5','P5'],['P6','P6']], default = 'P') M10= models.FloatField(label="Out of the 20 math questions, how many questions will the winner in MATH-2 be able to solve:") M11= models.FloatField(label="Out of the 20 math questions, how many questions will the loser in MATH-2 be able to solve:") winner = models.IntegerField() otherwinner = models.IntegerField() guessgame = models.IntegerField() math0score = models.FloatField() math1score = models.FloatField() score = models.FloatField() ggscore = models.FloatField() guess1= models.FloatField() guess2= models.FloatField() randommath1score = models.FloatField() randomscore = models.FloatField() math2winner = models.IntegerField() math2loser = models.IntegerField() math1winnername = models.StringField() math1otherwinnername = models.StringField() math1winnergender = models.StringField() math1otherwinnergender= models.StringField() math1payoff = models.FloatField() math2payoff = models.FloatField() ggpayoff = models.FloatField()