from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) doc = """ This is a standard 2-player Economic_experimentcm game where the amount sent by player 1 gets tripled. The Economic_experimentcm game was first proposed by Berg, Dickhaut, and McCabe (1995) . """ class Constants(BaseConstants): name_in_url = 'Economic_experiment0004' players_per_group = 2 num_rounds = 1 instructions_template = 'Economic_experimentcm/instructions.html' # payoff if player A chooses out, A_out_payoff = 21 B_out_payoff = 21 # payoff if B don't roll A_dontroll_payoff = 9 B_dontroll_payoff = 42 # payoff if B roll A_succeed_payoff = 45 B_roll_payoff = 30 A_failed_payoff = 9 # Guess Right Guess_right = 2 Guess_wrong = 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): if self.num_broll !=0: 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.Dice == 2 or p.Dice ==1] self.num_bsucceed = len(bsucceed) self.brate_succeed = 100 * len(bsucceed) / len(broll) elif self.num_broll ==0: self.brate_succeed=1000 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) if self.len_A_in !=0: self.elicita1_inavg = sum(elicita1) / self.len_A_in elif self.len_A_in == 0: self.elicita1_inavg = 1000 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) if self.len_A_in != 0: self.elicita2_inavg = sum(elicita2) / self.len_A_in elif self.len_A_in ==0: self.elicita2_inavg =1000 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) if self.len_A_in !=0: self.elicita3_inavg = sum(elicita3) / self.len_A_in elif self.len_A_in==0: self.elicita3_inavg=1000 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='请编辑信息',blank=True) group_Invest=models.IntegerField() group_Roll = models.IntegerField() group_Dice = models.IntegerField() def set_group_result(self): pa = self.get_player_by_id(1) pb = self.get_player_by_id(2) self.group_Invest = pa.Invest self.group_Roll = pb.Roll self.group_Dice = pb.Dice def set_taskpayoffs(self): pa = self.get_player_by_id(1) pb = self.get_player_by_id(2) if self.group_Invest == 0: pa.taskpayoffs = Constants.A_out_payoff pb.taskpayoffs = Constants.B_out_payoff else: if self.group_Roll == 0: pa.taskpayoffs = Constants.A_dontroll_payoff pb.taskpayoffs = Constants.B_dontroll_payoff else: if self.group_Dice < 3: pa.taskpayoffs = Constants.A_succeed_payoff pb.taskpayoffs = Constants.B_roll_payoff else: pa.taskpayoffs = Constants.A_failed_payoff pb.taskpayoffs = Constants.B_roll_payoff def set_guess_payoffs(self): for p in self.get_players(): if p.id_in_group == 1: p.guess_payoffs = p.elicita1_payoffs + p.elicita2_payoffs + \ p.elicitab1_payoffs + p.elicitab2_payoffs elif p.id_in_group == 2: p.guess_payoffs = p.elicitb1_payoffs + p.elicitb2_payoffs + \ p.elicitb3_payoffs + p.elicitb4_payoffs + p.elicitab1_payoffs + \ p.elicitab2_payoffs def set_total_payoffs(self): for p in self.get_players(): if p.id_in_group == 1: p.total_payoffs = p.taskpayoffs + p.elicita1_payoffs + p.elicita2_payoffs + \ p.elicitab1_payoffs + p.elicitab2_payoffs elif p.id_in_group == 2: p.total_payoffs = p.taskpayoffs + p.elicitb1_payoffs + p.elicitb2_payoffs + \ p.elicitb3_payoffs + p.elicitb4_payoffs + p.elicitab1_payoffs + \ p.elicitab2_payoffs def set_correct_guess(self): for p in self.get_players(): p.correct_guess = int(p.guess_payoffs / 2) class Player(BasePlayer): def role(self): if self.id_in_group == 1: return "A" if self.id_in_group == 2: return "B" Invest = models.IntegerField(label="你的选择是", choices=[(1,"投资"), (0,"退出")], ) Roll = models.IntegerField( label="你的选择是", choices=[(1,"掷骰子"), (0,"不掷骰子")], ) Dice = models.IntegerField(label="请输入掷骰子的结果", min=(1),max=(6) ) taskpayoffs = models.IntegerField() total_payoffs = models.IntegerField() guess_payoffs = models.IntegerField() correct_guess = models.IntegerField() Elicit_A1 = models.FloatField(label="你猜测的比例是(%)", min=(0), max=(100)) distancea1=models.FloatField() elicita1_payoffs = models.IntegerField() Elicit_A2 = models.FloatField(label="你猜测的比例是(%)", min=(0), max=(100)) distancea2=models.FloatField() elicita2_payoffs = models.IntegerField() Elicit_A3 = models.FloatField(label="你猜测的比例是(%)", min=(0), max=(100)) Elicit_Adecision = models.LongStringField(label="6. 在本实验中,你选择“投资”或者“退出”是因为") Elicit_AB1 = models.IntegerField(label="你的选择是", choices=[(1, "反对"), (2, "既不赞成也不反对"), (3, "赞成")], widget=widgets.RadioSelectHorizontal) elicitab1_payoffs = models.IntegerField() Elicit_AB2 = models.IntegerField(label="你的选择是", choices=[(1, "反对"), (2, "既不赞成也不反对"), (3, "赞成")], widget=widgets.RadioSelectHorizontal) elicitab2_payoffs = models.IntegerField() Elicit_B1 = models.FloatField(label="你猜测的比例是(%)", min=0, max=100) distanceb1 = models.FloatField() elicitb1_payoffs = models.IntegerField() Elicit_B2 = models.FloatField(label="你猜测的比例是(%)", min=(0), max=(100)) distanceb2 = models.FloatField() elicitb2_payoffs = models.IntegerField() Elicit_B3 = models.FloatField(label="你猜测的比例是(%)", min=(0), max=(100)) distanceb3 = models.FloatField() elicitb3_payoffs = models.IntegerField() Elicit_B4 = models.FloatField(label="你猜测的比例是(%)", min=(0), max=(100)) distanceb4 = models.FloatField() elicitb4_payoffs = models.IntegerField() Elicit_Bdecision = models.LongStringField(label="7. 在本实验中,你选择“掷骰子”或者“不掷骰子”是因为") Quiz11 = models.CurrencyField(label="1. 如果A选择“退出”,B选择“不掷骰子”,并且掷骰子的结果为1,那么A的任务报酬为", min=c(0)) Quiz12 = models.CurrencyField(label="B的任务报酬为", min=c(0)) Quiz21 = models.CurrencyField(label="2. 如果A选择“退出”,B选择“掷骰子”,并且掷骰子的结果为5,那么A的任务报酬为", min=c(0)) Quiz22 = models.CurrencyField(label="B的任务报酬为", min=c(0)) Quiz31 = models.CurrencyField( label="3. 如果A选择“投资”,B选择“不掷骰子”,并且掷骰子的结果为1,那么A的任务报酬为", min=c(0)) Quiz32 = models.CurrencyField(label="B的任务报酬为", min=c(0)) Quiz41 = models.CurrencyField(label="4. 如果A选择“投资”,B选择“掷骰子”,并且掷骰子的结果为4,那么A的任务报酬为", min=c(0)) Quiz42 = models.CurrencyField(label="B的任务报酬为", min=c(0)) Quiz51 = models.CurrencyField(label="5. 如果A选择“投资”,B选择“掷骰子”,并且掷骰子的结果为2,那么A的任务报酬为", min=c(0)) Quiz52 = models.CurrencyField(label="B的任务报酬为", min=c(0)) Survey_C_1 = models.IntegerField(label="1. 一个善意的谎言能够使人感觉良好,是积极的", choices=[1,2,3,4], widget=widgets.RadioSelectHorizontal) Survey_C_2 = models.IntegerField(label="2. 我可以为了帮助别人而说谎,即使这样会伤害我", choices=[1,2,3,4], widget=widgets.RadioSelectHorizontal) Survey_C_3 = models.IntegerField(label="3. 我可以为了报复别人而说谎,即使这样伤害了我", choices=[1,2,3,4], widget=widgets.RadioSelectHorizontal) Survey_C_4 = models.IntegerField(label="4. 如果让我更倾向于撒谎,那么我从谎言中得到的好处就需要越多", choices=[1,2,3,4], widget=widgets.RadioSelectHorizontal) Survey_C_5 = models.IntegerField(label="5. 我不倾向于撒谎,因为别人从谎言中损失越多", choices=[1,2,3,4], widget=widgets.RadioSelectHorizontal) Survey_C_6 = models.IntegerField(label="6. 我不倾向于撒谎,因为被发现的风险很大", choices=[1,2,3,4], widget=widgets.RadioSelectHorizontal) Survey_C_7 = models.IntegerField(label="7. 你要么说谎要么不说谎,谎言是没有等级之分的", choices=[1,2,3,4], widget=widgets.RadioSelectHorizontal) Survey_C_8 = models.IntegerField(label="8. 我不倾向于撒谎,因为只有谎言越大,我才能被人相信", choices=[1,2,3,4], widget=widgets.RadioSelectHorizontal) Survey_C_9 = models.IntegerField(label="9. 如果我承诺对某人说实话,这使我很难对这个人撒谎", choices=[1,2,3,4], widget=widgets.RadioSelectHorizontal) Survey_C_10 = models.IntegerField(label="10. 承诺是有程度区分的,一些承诺的表达方式涵盖了一个更大范围的承诺", choices=[1, 2, 3, 4], widget=widgets.RadioSelectHorizontal) Survey_M_1 = models.IntegerField(label="1. 除非有必要,否则不要告诉他人你做一件事的真正原因", choices=[1, 2, 3, 4, 5, 6, 7], widget=widgets.RadioSelectHorizontal) Survey_M_2 = models.IntegerField(label="2. 处理人际关系最好的办法是说他们想听的话", choices=[1, 2, 3, 4, 5, 6, 7], widget=widgets.RadioSelectHorizontal) Survey_M_3 = models.IntegerField(label="3. 人们只应该做那些在道德上是绝对正确的事", choices=[1, 2, 3, 4, 5, 6, 7], widget=widgets.RadioSelectHorizontal) Survey_M_4 = models.IntegerField(label="4. 大多数人的本质都是善良随和的", choices=[1, 2, 3, 4, 5, 6, 7], widget=widgets.RadioSelectHorizontal) Survey_M_5 = models.IntegerField(label="5. 所有人都有邪恶的念头并且一旦有机会就会表现出来", choices=[1, 2, 3, 4, 5, 6, 7], widget=widgets.RadioSelectHorizontal) Survey_M_6 = models.IntegerField(label="6. 坦诚是所有情境里的最佳准则", choices=[1, 2, 3, 4, 5, 6, 7], widget=widgets.RadioSelectHorizontal) Survey_M_7 = models.IntegerField(label="7. 撒谎是没有任何借口的", choices=[1, 2, 3, 4, 5, 6, 7], widget=widgets.RadioSelectHorizontal) Survey_M_8 = models.IntegerField(label="8. 如果不经常抄近路就很难超越别人", choices=[1, 2, 3, 4, 5, 6, 7], widget=widgets.RadioSelectHorizontal) Survey_M_9 = models.IntegerField(label="9. 总的来说,表现的谦虚和真诚总比狂妄和虚伪好", choices=[1, 2, 3, 4, 5, 6, 7], widget=widgets.RadioSelectHorizontal) Survey_M_10 = models.IntegerField(label="10. 当想请别人为你做某事时,最好告诉其真实原因,而不是显得重要的原因", choices=[1, 2, 3, 4, 5, 6, 7], widget=widgets.RadioSelectHorizontal) Survey_M_11 = models.IntegerField(label="11. 世界上大多数成功的人都过着干净、道德的生活", choices=[1, 2, 3, 4, 5, 6, 7], widget=widgets.RadioSelectHorizontal) Survey_M_12 = models.IntegerField(label="12. 任何完全相信别人的人都是在自找麻烦", choices=[1, 2, 3, 4, 5, 6, 7], widget=widgets.RadioSelectHorizontal) Survey_M_13 = models.IntegerField(label="13. 罪犯和其他人的最大不同在于罪犯太愚蠢以至于被逮到了", choices=[1, 2, 3, 4, 5, 6, 7], widget=widgets.RadioSelectHorizontal) Survey_M_14 = models.IntegerField(label="14. 大多数人都是勇敢的", choices=[1, 2, 3, 4, 5, 6, 7], widget=widgets.RadioSelectHorizontal) Survey_M_15 = models.IntegerField(label="15. 对重要人物,必要的奉承是明智之举", choices=[1, 2, 3, 4, 5, 6, 7], widget=widgets.RadioSelectHorizontal) Survey_M_16 = models.IntegerField(label="16. 在各个方面都表现的很好是有可能的", choices=[1, 2, 3, 4, 5, 6, 7], widget=widgets.RadioSelectHorizontal) Survey_M_17 = models.IntegerField(label="17. 每分钟都有一个傻瓜出生的说法是非常错误的", choices=[1, 2, 3, 4, 5, 6, 7], widget=widgets.RadioSelectHorizontal) Survey_M_18 = models.IntegerField(label="18. 一般来说,不受到强迫人们不会努力工作", choices=[1, 2, 3, 4, 5, 6, 7], widget=widgets.RadioSelectHorizontal) Survey_M_19 = models.IntegerField(label="19. 患有不治之症的人有选择安乐死的权利", choices=[1, 2, 3, 4, 5, 6, 7], widget=widgets.RadioSelectHorizontal) Survey_M_20 = models.IntegerField(label="20. 大多数人对自己财产的损失比丧父之痛记得更清楚", choices=[1, 2, 3, 4, 5, 6, 7], widget=widgets.RadioSelectHorizontal) Survey_D_1 = models.IntegerField(label="性别", choices=[(0, "女"),(1,"男")]) Survey_D_2 = models.IntegerField(label="年龄", min=(13)) Survey_D_3 = models.StringField(label="专业") Survey_D_4 = models.StringField(label="民族") Survey_D_5 = models.IntegerField(label="年级", choices=[(1,"大学一年级"), (2,"大学二年级"), (3, "大学三年级"), (4, "大学四年级"), (5,"大学五年级"), (6,"硕士及以上")]) Survey_D_6 = models.IntegerField(label="籍贯", choices=[(1, "安徽省"), (2, "澳门特别行政区"), (3, "北京市"), (4, "重庆市"), (5, "福建省" ), (6, "甘肃省"), (7, "广东省"), (8, "广西壮族自治区"), (9, "贵州省"), (10, "海南省"), (11, "河北省"), (12, "河南省"), (13, "黑龙江省"), (14, "湖北省"), (15, "湖南省"), (16, "吉林省"), (17, "江苏省"), (18,"江西省"), (19,"辽宁省"), (20,"内蒙古省"), (21, "宁夏回族自治区"), (22, "青海省"), (23, "山东省"), (24, "山西省"), (25, "陕西省"), (26, "上海市"), (27, "四川省"), (28, "台湾省"), (29, "天津市"), (30, "西藏藏族自治区"), (31, "香港特别行政区"), (32, "新疆维吾尔自治区"), (33, "云南省"), (34, "浙江省")] ) Survey_D_7 = models.IntegerField(label="近期你是否有参与过类似今天的双人配对实验", choices=[(0, "未参与过"), (1, "参与过")])