from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) doc = """ This is a standard 2-player trust_promise_inchinese game where the amount sent by player 1 gets tripled. The trust_promise_inchinese game was first proposed by Berg, Dickhaut, and McCabe (1995) . """ class Constants(BaseConstants): name_in_url = 'trust_promise' players_per_group = 2 num_rounds = 1 instructions_template = 'trust_promise_inchinese/instructions.html' # payoff if player A chooses out, A_out_payoff = c(21) B_out_payoff = c(21) # payoff if B don't roll A_dontroll_payoff = c(9) B_dontroll_payoff = c(42) # payoff if B roll A_succeed_payoff = c(45) B_roll_payoff = c(30) A_failed_payoff = c(9) # Guess Right Guess_right = c(2) Guess_wrong = c(0) class Subsession(BaseSubsession): # A' belief of B chose Roll num_broll = models.IntegerField() num_allb = models.IntegerField() brate_roll = models.FloatField() def set_rate_broll(self): players = self.get_players() broll = [p for p in players if p.Roll == 1] allb = [p for p in players if p.id_in_group == 2] self.num_broll = len(broll) self.num_allb = len(allb) self.brate_roll = 100 * len(broll) / len(allb) def set_elicita1_payoffs(self): players = self.get_players() rolea = [p for p in players if p.id_in_group == 1] for p in rolea: p.distancea1 = abs(p.Elicit_A1 - self.brate_roll) if p.distancea1 <= 5: p.elicita1_payoffs = Constants.Guess_right else: p.elicita1_payoffs = Constants.Guess_wrong # A' belief of B Succeed num_bsucceed = models.IntegerField() brate_succeed = models.FloatField() def set_rate_bsucceed(self): players = self.get_players() broll = [p for p in players if p.Roll == 1] for p in broll: bsucceed = [p for p in players if p.Roll == 1 or p.Roll == 2] self.num_bsucceed = len(bsucceed) self.brate_succeed = 100 * len(bsucceed) / len(broll) def set_elicita2_payoffs(self): players = self.get_players() rolea = [p for p in players if p.id_in_group == 1] for p in rolea: p.distancea2 = abs(p.Elicit_A2 - self.brate_succeed) if p.distancea2 <= 5: p.elicita2_payoffs = Constants.Guess_right else: p.elicita2_payoffs = Constants.Guess_wrong #B's belief of A's choose In (Elicit_B1) num_ain = models.IntegerField() num_alla = models.IntegerField() arate_in = models.FloatField() def set_rate_ain(self): players = self.get_players() ain = [p for p in players if p.Invest == 1] alla = [p for p in players if p.id_in_group == 1] self.num_ain = len(ain) self.num_alla = len(alla) self.arate_in = 100 * len(ain) / len(alla) def set_elicitb1_payoffs(self): players = self.get_players() roleb = [p for p in players if p.id_in_group == 2] for p in roleb: p.distanceb1 = abs(p.Elicit_B1 - self.arate_in) if p.distanceb1 <= 5: p.elicitb1_payoffs = Constants.Guess_right else: p.elicitb1_payoffs = Constants.Guess_wrong # B‘belief of A’s belief: B choose roll(Elicit_B2) elicita1_inavg = models.FloatField() sum_elicita1 = models.FloatField() len_A_in = models.IntegerField() def set_elicita1_inavg(self): players = self.get_players() A_in = [p for p in players if p.Invest == 1] elicita1 = [p.Elicit_A1 for p in players if p.Invest == 1] self.sum_elicita1 = sum(elicita1) self.len_A_in = len(A_in) self.elicita1_inavg = sum(elicita1) / self.len_A_in def set_elicitb2_payoffs(self): players = self.get_players() roleb = [p for p in players if p.id_in_group == 2] for p in roleb: p.distanceb2 = abs(p.Elicit_B2 - self.elicita1_inavg) if p.distanceb2 <= 5: p.elicitb2_payoffs = Constants.Guess_right else: p.elicitb2_payoffs = Constants.Guess_wrong # B‘belief of A’s belief: B succeed (Elicit_B3) elicita2_inavg = models.FloatField() sum_elicita2 = models.FloatField() def set_elicita2_inavg(self): players = self.get_players() elicita2 = [p.Elicit_A2 for p in players if p.Invest == 1] self.sum_elicita2 = sum(elicita2) self.elicita2_inavg = sum(elicita2) / self.len_A_in def set_elicitb3_payoffs(self): players = self.get_players() roleb = [p for p in players if p.id_in_group == 2] for p in roleb: p.distanceb3 = abs(p.Elicit_B3 - self.elicita2_inavg) if p.distanceb3 <= 5: p.elicitb3_payoffs = Constants.Guess_right else: p.elicitb3_payoffs = Constants.Guess_wrong # B‘belief of A’s belief: cheat to succeed (Elicit_B4) elicita3_inavg = models.FloatField() sum_elicita3 = models.FloatField() def set_elicita3_inavg(self): players = self.get_players() elicita3 = [p.Elicit_A3 for p in players if p.Invest == 1] self.sum_elicita3 = sum(elicita3) self.elicita3_inavg = sum(elicita3) / self.len_A_in def set_elicitb4_payoffs(self): players = self.get_players() roleb = [p for p in players if p.id_in_group == 2] for p in roleb: p.distanceb4 = abs(p.Elicit_B4 - self.elicita3_inavg) if p.distanceb4 <= 5: p.elicitb4_payoffs = Constants.Guess_right else: p.elicitb4_payoffs = Constants.Guess_wrong # calculate the choice of most num_agree_ab1 = models.IntegerField() num_middle_ab1 = models.IntegerField() num_disagree_ab1 = models.IntegerField() elicitab1_most = models.IntegerField() def set_elicitab1_most(self): players = self.get_players() disagree_ab1 = [p for p in players if p.Elicit_AB1 == 1] self.num_disagree_ab1 = len(disagree_ab1) middle_ab1 = [p for p in players if p.Elicit_AB1 == 2] self.num_middle_ab1 = len(middle_ab1) agree_ab1 = [p for p in players if p.Elicit_AB1 == 3] self.num_agree_ab1 = len(agree_ab1) if max(self.num_disagree_ab1,self.num_agree_ab1,self.num_middle_ab1) == self.num_agree_ab1: self.elicitab1_most = 3 elif max(self.num_disagree_ab1,self.num_agree_ab1,self.num_middle_ab1) == self.num_middle_ab1: self.elicitab1_most = 2 elif max(self.num_disagree_ab1,self.num_agree_ab1,self.num_middle_ab1) == self.num_disagree_ab1: self.elicitab1_most = 1 def set_elicitab1_payoffs(self): for p in self.get_players(): if p.Elicit_AB1 == self.elicitab1_most: p.elicitab1_payoffs = Constants.Guess_right else: p.elicitab1_payoffs = Constants.Guess_wrong num_agree_ab2 = models.IntegerField() num_middle_ab2 = models.IntegerField() num_disagree_ab2 = models.IntegerField() elicitab2_most = models.IntegerField() def set_elicitab2_most(self): players = self.get_players() disagree_ab2 = [p for p in players if p.Elicit_AB2 == 1] self.num_disagree_ab2 = len(disagree_ab2) middle_ab2 = [p for p in players if p.Elicit_AB2 == 2] self.num_middle_ab2 = len(middle_ab2) agree_ab2 = [p for p in players if p.Elicit_AB2 == 3] self.num_agree_ab2 = len(agree_ab2) if max(self.num_disagree_ab2,self.num_agree_ab2,self.num_middle_ab2) == self.num_agree_ab2: self.elicitab2_most = 3 elif max(self.num_disagree_ab2,self.num_agree_ab2,self.num_middle_ab2) == self.num_middle_ab2: self.elicitab2_most = 2 elif max(self.num_disagree_ab2,self.num_agree_ab2,self.num_middle_ab2) == self.num_disagree_ab2: self.elicitab2_most = 1 def set_elicitab2_payoffs(self): for p in self.get_players(): if p.Elicit_AB2 == self.elicitab2_most: p.elicitab2_payoffs = Constants.Guess_right else: p.elicitab2_payoffs = Constants.Guess_wrong class Group(BaseGroup): message = models.LongStringField(label='What message do you want to send to your A?') class Player(BasePlayer): def role(self): if self.id_in_group == 1: return "A" if self.id_in_group == 2: return "B" def set_payoffs(self): if self.id_in_group == 1: self.participant.payoff = self.taskpayoffs + self.elicita1_payoffs + self.elicita2_payoffs + \ self.elicitab1_payoffs + self.elicitab2_payoffs + self.task2payoffs if self.id_in_group == 2: self.participant.payoff = self.taskpayoffs + self.elicitb1_payoffs + self.elicitb2_payoffs + \ self.elicitb3_payoffs + self.elicitb4_payoffs + self.elicitab1_payoffs + \ self.elicitab2_payoffs + self.task2payoffs Invest = models.IntegerField(label="Please choose Invest or Out", choices=[(1,"Invest"), (0,"Out")], ) Roll = models.IntegerField( label="Please choose Roll or Don't Roll", choices=[(1,"Roll"), (0,"Dont_Roll")], ) Dice = models.IntegerField(label="The number of dice", min=(1),max=(6) ) taskpayoffs = models.CurrencyField() task2payoffs = models.CurrencyField() total_payoffs = models.CurrencyField() Elicit_A1 = models.FloatField(label="I guess that this percentage is", min=(0), max=(100)) distancea1=models.FloatField() elicita1_payoffs = models.CurrencyField() Elicit_A2 = models.FloatField(label="I guess that this percentage is", min=(0), max=(100)) distancea2=models.FloatField() elicita2_payoffs = models.CurrencyField() Elicit_A3 = models.FloatField(label="I guess that this percentage is", min=(0), max=(100)) Elicit_AB1 = models.IntegerField(label="Generally, most of people would rather cheat to satisfy others than play" " honestly to risk letting others down.", choices=[(1, "Dissagree"), (2, "Neither agree or disagree"), (3, "Agree")]) elicitab1_payoffs = models.CurrencyField() Elicit_AB2 = models.IntegerField(label="Generally, it’s OK to make a promise to succeed for most of people when " "they can cheat to succeed.", choices=[(1, "Dissagree"), (2, "Neither agree or disagree"), (3, "Agree")]) elicitab2_payoffs = models.CurrencyField() Elicit_B1 = models.FloatField(label="I guess that this percentage is", min=0, max=100) distanceb1 = models.FloatField() elicitb1_payoffs = models.CurrencyField() Elicit_B2 = models.FloatField(label="I guess that this percentage is", min=(0), max=(100)) distanceb2 = models.FloatField() elicitb2_payoffs = models.CurrencyField() Elicit_B3 = models.FloatField(label="I guess that this percentage is", min=(0), max=(100)) distanceb3 = models.FloatField() elicitb3_payoffs = models.CurrencyField() Elicit_B4 = models.FloatField(label="I guess that this percentage is", min=(0), max=(100)) distanceb4 = models.FloatField() elicitb4_payoffs = models.CurrencyField() Quiz11 = models.CurrencyField(label="1: If A chooses Out, then B chooses Don’t Roll and the number of die is 1," "A's payoff is", min=c(0)) Quiz12 = models.CurrencyField(label="B's payoff is", min=c(0)) Quiz21 = models.CurrencyField(label="2: If A chooses Out, then B chooses Roll and the number of die is 5," "A's payoff is", min=c(0)) Quiz22 = models.CurrencyField(label="B's payoff is", min=c(0)) Quiz31 = models.CurrencyField( label="3: If A chooses In, then B chooses Don’t Roll and the number of die is 1," "A's payoff is", min=c(0)) Quiz32 = models.CurrencyField(label="B's payoff is", min=c(0)) Quiz41 = models.CurrencyField(label="4: If A chooses In, then B chooses Roll and the number of die is 4," "A's payoff is", min=c(0)) Quiz42 = models.CurrencyField(label="B's payoff is", min=c(0)) Quiz51 = models.CurrencyField(label="5: If A chooses In, then B chooses Roll and the number of die is 2," "A's payoff is", min=c(0)) Quiz52 = models.CurrencyField(label="B's payoff is", min=c(0)) Quiz6 = models.StringField(label="6: The message that B sends to A is not allowed to identify him or herself by:" "A.Number B.Name C.Gender D.Contact information") Survey_C_1 = models.IntegerField(label="A white lie that makes someone else feel good is only positive", choices=[(1,"Strongly disagree"),(2,"Slightly disagree",),(3,"Slightly agree"), (4,"Strongly agree")]) Survey_C_2 = models.IntegerField(label="I could lie to help someone else even if it hurts me", choices=[(1,"Strongly disagree"),(2,"Slightly disagree",),(3,"Slightly agree"),(4,"Strongly agree")]) Survey_C_3 = models.IntegerField(label="I could lie to get revenge even if it hurts me", choices=[(1,"Strongly disagree"),(2,"Slightly disagree",),(3,"Slightly agree"),(4,"Strongly agree")]) Survey_C_4 = models.IntegerField(label="I am more inclined to lie, the more I have to gain from the lie", choices=[(1,"Strongly disagree"),(2,"Slightly disagree",),(3,"Slightly agree"),(4,"Strongly agree")]) Survey_C_5 = models.IntegerField(label="I am less inclined to lie the more others have to lose from the lie", choices=[(1,"Strongly disagree"),(2,"Slightly disagree",),(3,"Slightly agree"),(4,"Strongly agree")]) Survey_C_6 = models.IntegerField(label="I am less inclined to lie, the greater the risk of discovery", choices=[(1,"Strongly disagree"),(2,"Slightly disagree",),(3,"Slightly agree"),(4,"Strongly agree")]) Survey_C_7 = models.IntegerField(label="You either lie or you don’t, there are no degrees of lying", choices=[(1,"Strongly disagree"),(2,"Slightly disagree",),(3,"Slightly agree"),(4,"Strongly agree")]) Survey_C_8 = models.IntegerField(label="I am less inclined to lie, the greater the lie has to be for me to be believed", choices=[(1,"Strongly disagree"),(2,"Slightly disagree",),(3,"Slightly agree"),(4,"Strongly agree")]) Survey_C_9 = models.IntegerField(label="If I promise someone to tell the truth, that makes it very difficult for me to lie to that person", choices=[(1,"Strongly disagree"),(2,"Slightly disagree",),(3,"Slightly agree"),(4,"Strongly agree")]) Survey_C_10 = models.IntegerField(label="There are degrees of promises, some formulations contain a greater promise than others", choices=[(1,"Strongly disagree"),(2,"Slightly disagree",),(3,"Slightly agree"),(4,"Strongly agree")]) Survey_M_1 = models.IntegerField(label="Never tell anyone the real reason you did something unless it is useful to" " do so", min=1, max=7) Survey_M_2 = models.IntegerField(label="The best way to handle people is to tell them what they what to hear", min=1, max=7) Survey_M_3 = models.IntegerField(label="One should take action only when sure it is morally right", min=1, max=7) Survey_M_4 = models.IntegerField(label="Most people are basically good and kind", min=1, max=7) Survey_M_5 = models.IntegerField(label="It is safest to assume that all people have a vicious streak and it will " "come out when they are given a chance", min=1, max=7) Survey_M_6 = models.IntegerField(label="Honesty is the best policy in all cases", min=1, max=7) Survey_M_7 = models.IntegerField(label="There is no excuse for lying to someone else", min=1, max=7) Survey_M_8 = models.IntegerField(label="It is hard to get ahead without cutting corners here and there", min=1, max=7) Survey_M_9 = models.IntegerField(label="All in all, it is better to be humble and honest than important and " "dishonest", min=1, max=7) Survey_M_10 = models.IntegerField(label="When you ask someone to do something for you, it is best to give the real" " reasons for wanting it rather than giving reasons that carry more weight", min=1, max=7) Survey_M_11 = models.IntegerField(label="Most people who get ahead in the world lead clean, moral lives", min=1, max=7) Survey_M_12 = models.IntegerField(label="Anyone who completely trusts anyone else is asking for trouble", min=1, max=7) Survey_M_13 = models.IntegerField(label="The biggest difference between most criminals and other people is that " "criminals are stupid enough to get caught", min=1,max=7) Survey_M_14 = models.IntegerField(label="Most men are brave", min=1, max=7) Survey_M_15 = models.IntegerField(label="It is wise to flatter important people", min=1, max=7) Survey_M_16 = models.IntegerField(label="It is possible to be good in all respects", min=1, max=7) Survey_M_17 = models.IntegerField(label="Barnum was very wrong when he said that there's a sucker born every minute", min=1, max=7) Survey_M_18 = models.IntegerField(label=" Generally speaking, men won't work hard unless they're forced to do so", min=1, max=7) Survey_M_19 = models.IntegerField(label="People suffering from incurable diseases should have the choice of being " "put painlessly to death", min=1, max=7) Survey_M_20 = models.IntegerField(label="Most men forget more easily the death of their father than " "the loss of their property", min=1, max=7) Survey_D_1 = models.StringField(label="Gender", choices=[("0", "Femal"),("1","Male")]) Survey_D_2 = models.IntegerField(label="Age") Survey_D_3 = models.StringField(label="Major") Survey_D_4 = models.StringField(label="Ethnic Group") Survey_D_5 = models.StringField(label="School Year", choices=[("1","First Year"), ("2","Second Year"), ("3", "Third Year"), ("4", "Fourth Year"), ("5","Fifth Year"), ("6","Master and Above")]) Survey_D_6 = models.StringField(label="Home Town", choices=[("1","AnHui"),("2","AoMen"),("3","BeiJing"),("4","ChongQing"), ("5","Fujian"),("6","GanSu"),("7","GuangDong"),("8","GuangXi"), ("9","GuiZhou"),("10","HaiNan"),("11","HeiBei"),("12","HeNan"), ("13", "HeiLongjiang"),("14","HuBei"),("15","HuNan"),("16","JiLin"), ("17","JiangSu"),("18","JiangXi"),("19","LiaoNing"),("20","NeiMenggu"), ("21","NingXia"),("22","QingHai"),("23","ShanDong"),("24","ShanXi"), ("25","ShaanXi"),("26","ShangHai"),("27","SiChuan"),("28","TaiWan"), ("29","TianJin"),("30","XiZang"),("31","XiangGang"),("32","XinJiang"), ("33","YunNan"),("34","ZheJiang")] )