from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, ) import random import itertools author = 'Elisa Macchi' doc = """ MTurk Survey to Test for BMI Perception: First Order and Second Order Beliefs """ class Constants(BaseConstants): name_in_url = 'survey_mturk_bmi_core' players_per_group = None num_rounds = 3 # Parameters n_sections = 5 n_questions = 9 n_pics = 3 # Payoffs: participation_fee = c(3) bonus = c(0.03) max_bonus = c(3) # load mode answers from csv # ..... dict_wealth = {'2_w_thin.jpg': 2, '3_w_thin.jpg': 2, '2_w_fat.jpg': 2, '3_w_fat.jpg': 2, '1_w_thin.jpg': 2, '4_w_fat.jpg': 2, '1_w_fat.jpg': 2, '4_w_thin.jpg': 2, '2_thin.jpg': 2, '3_thin.jpg': 2, '4_thin.jpg': 2, '7_thin.jpg': 2, '2_fat.jpg': 2, '3_fat.jpg': 2, '4_fat.jpg': 2, '7_fat.jpg': 2, '6_thin.jpg': 2, '9_thin.jpg': 2, '6_fat.jpg': 2, '9_fat.jpg': 2, '5_thin.jpg':2 , '10_thin.jpg': 2, '5_fat.jpg':2 , '10_fat.jpg': 2} dict_beauty = {'2_w_thin.jpg': 2, '3_w_thin.jpg': 2, '2_w_fat.jpg': 2, '3_w_fat.jpg': 2, '1_w_thin.jpg': 2, '4_w_fat.jpg': 2, '1_w_fat.jpg': 2, '4_w_thin.jpg': 2, '2_thin.jpg': 2, '3_thin.jpg': 2, '4_thin.jpg': 2, '7_thin.jpg': 2, '2_fat.jpg': 2, '3_fat.jpg': 2, '4_fat.jpg': 2, '7_fat.jpg': 2, '6_thin.jpg': 2, '9_thin.jpg': 2, '6_fat.jpg': 2, '9_fat.jpg': 2, '5_thin.jpg':2 , '10_thin.jpg': 2, '5_fat.jpg':2 , '10_fat.jpg': 2} dict_health = {'2_w_thin.jpg': 2, '3_w_thin.jpg': 28, '2_w_fat.jpg': 2, '3_w_fat.jpg': 2, '1_w_thin.jpg': 2, '4_w_fat.jpg': 2, '1_w_fat.jpg': 2, '4_w_thin.jpg': 2, '2_thin.jpg': 2, '3_thin.jpg': 2, '4_thin.jpg': 2, '7_thin.jpg': 2, '2_fat.jpg': 2, '3_fat.jpg': 2, '4_fat.jpg': 2, '7_fat.jpg': 2} dict_life = {'2_w_thin.jpg': 2, '3_w_thin.jpg': 2, '2_w_fat.jpg': 2, '3_w_fat.jpg': 2, '1_w_thin.jpg': 2, '4_w_fat.jpg': 2, '1_w_fat.jpg': 2, '4_w_thin.jpg': 2, '2_thin.jpg': 2, '3_thin.jpg': 2, '4_thin.jpg': 2, '7_thin.jpg': 2, '2_fat.jpg': 2, '3_fat.jpg': 2, '4_fat.jpg': 2, '7_fat.jpg': 2, '6_thin.jpg': 2, '9_thin.jpg': 2, '6_fat.jpg': 2, '9_fat.jpg': 2, '5_thin.jpg':2 , '10_thin.jpg': 2, '5_fat.jpg':2 , '10_fat.jpg': 2} dict_self = {'2_w_thin.jpg': 2, '3_w_thin.jpg': 2, '2_w_fat.jpg': 2, '3_w_fat.jpg': 2, '1_w_thin.jpg': 2, '4_w_fat.jpg': 2, '1_w_fat.jpg': 2, '4_w_thin.jpg': 2, '2_thin.jpg': 2, '3_thin.jpg': 2, '4_thin.jpg': 2, '7_thin.jpg': 2, '2_fat.jpg': 2, '3_fat.jpg': 2, '4_fat.jpg': 2, '7_fat.jpg': 2, '6_thin.jpg': 2, '9_thin.jpg': 2, '6_fat.jpg': 2, '9_fat.jpg': 2, '5_thin.jpg':2 , '10_thin.jpg': 2, '5_fat.jpg':2 , '10_fat.jpg': 2} dict_ability = {'2_w_thin.jpg': 2, '3_w_thin.jpg': 2, '2_w_fat.jpg': 2, '3_w_fat.jpg': 2, '1_w_thin.jpg': 2, '4_w_fat.jpg': 2, '1_w_fat.jpg': 2, '4_w_thin.jpg': 2, '2_thin.jpg': 2, '3_thin.jpg': 2, '4_thin.jpg': 2, '7_thin.jpg': 2, '2_fat.jpg': 2, '3_fat.jpg': 2, '4_fat.jpg': 2, '7_fat.jpg': 2, '6_thin.jpg': 2, '9_thin.jpg': 2, '6_fat.jpg': 2, '9_fat.jpg': 2, '5_thin.jpg':2 , '10_thin.jpg': 2, '5_fat.jpg':2 , '10_fat.jpg': 2} dict_trust = {'2_w_thin.jpg': 2, '3_w_thin.jpg': 2, '2_w_fat.jpg': 2, '3_w_fat.jpg': 2, '1_w_thin.jpg': 2, '4_w_fat.jpg': 2, '1_w_fat.jpg': 2, '4_w_thin.jpg': 2, '2_thin.jpg': 2, '3_thin.jpg': 2, '4_thin.jpg': 2, '7_thin.jpg': 2, '2_fat.jpg': 2, '3_fat.jpg': 2, '4_fat.jpg': 2, '7_fat.jpg': 2, '6_thin.jpg': 2, '9_thin.jpg': 2, '6_fat.jpg': 2, '9_fat.jpg': 2, '5_thin.jpg':2 , '10_thin.jpg': 2, '5_fat.jpg':2 , '10_fat.jpg': 2} dict_credit = {'2_w_thin.jpg': 2, '3_w_thin.jpg': 2, '2_w_fat.jpg': 2, '3_w_fat.jpg': 2, '1_w_thin.jpg': 2, '4_w_fat.jpg': 2, '1_w_fat.jpg': 2, '4_w_thin.jpg': 2, '2_thin.jpg': 2, '3_thin.jpg': 2, '4_thin.jpg': 2, '7_thin.jpg': 2, '2_fat.jpg': 2, '3_fat.jpg': 2, '4_fat.jpg': 2, '7_fat.jpg': 2, '6_thin.jpg': 2, '9_thin.jpg': 2, '6_fat.jpg': 2, '9_fat.jpg': 2, '5_thin.jpg': 2, '10_thin.jpg': 2, '5_fat.jpg': 2, '10_fat.jpg': 2} dict_lend = {'2_w_thin.jpg': 2, '3_w_thin.jpg': 2, '2_w_fat.jpg': 2, '3_w_fat.jpg': 2, '1_w_thin.jpg': 2, '4_w_fat.jpg': 2, '1_w_fat.jpg': 2, '4_w_thin.jpg': 2, '2_thin.jpg': 2, '3_thin.jpg': 2, '4_thin.jpg': 2, '7_thin.jpg': 2, '2_fat.jpg': 2, '3_fat.jpg': 2, '4_fat.jpg': 2, '7_fat.jpg': 2, '6_thin.jpg': 2, '9_thin.jpg': 2, '6_fat.jpg': 2, '9_fat.jpg': 2, '5_thin.jpg': 2, '10_thin.jpg': 2, '5_fat.jpg': 2, '10_fat.jpg': 2} mode_answers = {'b2_wealth': dict_wealth, 'b2_beauty': dict_beauty, 'b2_health': dict_health, 'b2_life': dict_life, 'b2_self': dict_self, 'b2_ability': dict_ability, 'b2_trust': dict_trust, 'b2_credit': dict_credit, 'b2_lend': dict_lend } # dictionary storing gender and race for each picture (for analysis) kampala_images = {'img_thin_b_f': ['6_thin.jpg', '9_thin.jpg'], 'img_fat_b_f': ['6_fat.jpg', '9_fat.jpg'], 'img_thin_b_m': ['5_thin.jpg', '10_thin.jpg'], 'img_fat_b_m': ['5_fat.jpg', '10_fat.jpg']} images = { 'img_thin_w_f': ['2_w_thin.jpg', '3_w_thin.jpg'], 'img_fat_w_f': ['2_w_fat.jpg', '3_w_fat.jpg'], 'img_thin_w_m': ['1_w_thin.jpg', '4_w_thin.jpg'], 'img_fat_w_m': ['1_w_fat.jpg', '4_w_fat.jpg'], 'img_thin_b_f': ['3_thin.jpg', '7_thin.jpg'], 'img_fat_b_f': ['3_fat.jpg', '7_fat.jpg'], 'img_thin_b_m': ['2_thin.jpg', '4_thin.jpg'], 'img_fat_b_m': ['2_fat.jpg', '4_fat.jpg'] } ages = { '2_w_thin.jpg': 57, '3_w_thin.jpg': 28, '2_w_fat.jpg': 57, '3_w_fat.jpg': 28, '1_w_thin.jpg': 31, '4_w_fat.jpg': 62, '1_w_fat.jpg': 31, '4_w_thin.jpg': 62, '2_thin.jpg': 58, '3_thin.jpg': 47, '4_thin.jpg': 32, '7_thin.jpg': 52, '2_fat.jpg': 58, '3_fat.jpg': 47, '4_fat.jpg': 32, '7_fat.jpg': 52, '5_thin.jpg': 52, '6_thin.jpg': 40, '9_thin.jpg': 38, '10_thin.jpg': 33, '5_fat.jpg': 52, '6_fat.jpg': 40, '9_fat.jpg': 38, '10_fat.jpg': 33 } images_chr = { 'img_thin_w_f': ['thin', 'white', 'wom'], 'img_fat_w_f': ['fat', 'white', 'wom'], 'img_thin_w_m': ['thin', 'white', 'man'], 'img_fat_w_m': ['fat', 'white', 'man'], 'img_thin_b_f': ['thin', 'black', 'wom'], 'img_fat_b_f': ['fat', 'black', 'wom'], 'img_thin_b_m': ['thin', 'black', 'man'], 'img_fat_b_m': ['fat', 'black', 'wom'] } # need to save second order beliefs and first order beliefs --> match and define the payoff based on that # first three people that complete class Subsession(BaseSubsession): def creating_session(self): # Random assign gender, body mass and information: pic_bm_gender = ['img_thin_w_f', 'img_fat_w_f', 'img_thin_w_m', 'img_fat_w_m', 'img_thin_b_f', 'img_fat_b_f', 'img_thin_b_m', 'img_fat_b_m'] pic_bm_gender_kla = ['img_thin_b_f', 'img_fat_b_f', 'img_thin_b_m', 'img_fat_b_m'] random.shuffle(pic_bm_gender) random.shuffle(pic_bm_gender_kla) pic_bm_gender_cycle = itertools.cycle(pic_bm_gender) pic_bm_gender_kla_cycle = itertools.cycle(pic_bm_gender_kla) for p in self.get_players(): # Randomize image 1 and image 2: if self.round_number == 1: treatment = next(pic_bm_gender_cycle) p.participant.vars['treatment_r1'] = treatment elif self.round_number == 3: treatment = next(pic_bm_gender_kla_cycle) else: treatment = next(pic_bm_gender_cycle) if p.participant.vars.get('treatment_r1') == treatment: random.shuffle(pic_bm_gender) pic_bm_gender_cycle = itertools.cycle(pic_bm_gender) treatment = next(pic_bm_gender_cycle) p.treatment = treatment p.image = random.choice(Constants.images[treatment]) # store images characteristics p.img_age = Constants.ages[[p.image][0]] p.img_bmi = Constants.images_chr[[treatment][0]][0] p.img_race = Constants.images_chr[[treatment][0]][1] p.img_sex = Constants.images_chr[[treatment][0]][2] class Group(BaseGroup): pass class Player(BasePlayer): def set_payoff(self): points = 0 for var in ['b2_wealth', 'b2_beauty', 'b2_health', 'b2_life', 'b2_self', 'b2_ability', 'b2_trust']: answer = getattr(self, var) for k, v in Constants.mode_answers[var].items(): if self.round_number > 1: if self.image == k and answer == v: points += Constants.bonus self.payoff = self.in_round(self.round_number - 1).payoff + points else: if self.image == k and answer == v: points += Constants.bonus self.payoff = c(points) # Treatment vars treatment = models.StringField() image = models.StringField() # store images characteristics img_age = models.IntegerField() img_bmi = models.StringField() img_race = models.StringField() img_sex = models.StringField() # First order beliefs: b1_wealth = models.IntegerField(choices=[[1, "1"], [2, "2"], [3, "3"], [4, "4"]], widget=widgets.RadioSelectHorizontal, default=None, label=''' How would you rate this person's wealth? ; 1= Not at all wealthy; 4 = Very wealthy ''') b1_beauty = models.IntegerField(choices=[[1, " 1"], [2, "2"], [3, "3"], [4, "4"]], widget=widgets.RadioSelectHorizontal, default=None, label=''' How would you rate this person's beauty? ; 1= Not at all beautiful; 4 = Very beautiful ''') b1_health = models.IntegerField(choices=[[1, "1"], [2, "2"], [3, "3"], [4, "4"]], widget=widgets.RadioSelectHorizontal, default=None, label=''' How would you rate this person's health?; 1= Not at all healthy; 4 = Very healthy ''') b1_life = models.IntegerField(choices=[[1, "1"], [2, "2"], [3, "3"], [4, "4"]], widget=widgets.RadioSelectHorizontal, default=None, label=''' How would you rate this person's overall life expectancy?
; 1= Will not at live a long life at all ; 4 = Will live a very long life. ''') b1_self = models.IntegerField(choices=[[1, "1"], [2, "2"], [3, "3"], [4, "4"]], widget=widgets.RadioSelectHorizontal, default=None, label=''' How would you rate this person's ability to resist temptation? ; 1= Not at all high; 4 = Very high ''') b1_ability = models.IntegerField(choices=[[1, "1"], [2, "2"], [3, "3"], [4, "4"]], widget=widgets.RadioSelectHorizontal, default=None, label=''' How would you rate this person's ability to get things done? ; 1= Not at all high; 4 = Very high ''') b1_trust = models.IntegerField(choices=[[1, "1"], [2, "2"], [3, "3"], [4, "4"]], widget=widgets.RadioSelectHorizontal, default=None, label=''' How would you rate this persons' trustworthiness? ; 1= Not at all trustworthy; 4 = Very trustworthy ''') b1_credit = models.IntegerField(choices=[[1, "1"], [2, "2"], [3, "3"], [4, "4"]], widget=widgets.RadioSelectHorizontal, default=None, label=''' "Creditworthiness describes how likely a person is to repay a financial obligation according to the terms of the agreement.” How would you rate the person’s creditworthiness?; 1= Not at all creditworthy; 4 = Very creditworthy ''') b1_lend = models.IntegerField(choices=[[1, "1"], [2, "2"], [3, "3"], [4, "4"]], widget=widgets.RadioSelectHorizontal(), default=None, label=''' If this person's needed $100, how likely would you be to lend him/her the money?; 1= Not at all likely; 4 = Very likely; ''') # Second order beliefs: b2_wealth = models.IntegerField(choices=[[1, "1"], [2, "2"], [3, "3"], [4, "4"]], widget=widgets.RadioSelectHorizontal, default=None, label=''' How did the other workers rate this person's wealth? ; 1= Not at all wealthy; 4 = Very wealthy ''') # income b2_beauty = models.IntegerField(choices=[[1, "1"], [2, "2"], [3, "3"], [4, "4"]], widget=widgets.RadioSelectHorizontal, default=None, label=''' How did the other workers you rate this person's beauty? ; 1= Not at all beautiful; 4 = Very beautiful ''') b2_health = models.IntegerField(choices=[[1, "1"], [2, "2"], [3, "3"], [4, "4"]], widget=widgets.RadioSelectHorizontal, default=None, label=''' How did the other workers rate this person's health? ; 1= Not at all healthy; 4 = Very healthy ''') b2_life = models.IntegerField(choices=[[1, "1"], [2, "2"], [3, "3"], [4, "4"]], widget=widgets.RadioSelectHorizontal, default=None, label=''' How did the other workers rate this person's life expectancy? ; 1= Not at all long; 4 = Very long ''') b2_self = models.IntegerField(choices=[[1, "1"], [2, "2"], [3, "3"], [4, "4"]], widget=widgets.RadioSelectHorizontal, default=None, label=''' How did the other workers rate this person's ability to resist temptation? ; 1= Not at all high; 4 = Very high ''') b2_ability = models.IntegerField(choices=[[1, "1"], [2, "2"], [3, "3"], [4, "4"]], widget=widgets.RadioSelectHorizontal, default=None, label=''' How did the other workers rate this person's ability to get things done? ; 1= Not at all high; 4 = Very high ''') b2_trust = models.IntegerField(choices=[[1, "1"], [2, "2"], [3, "3"], [4, "4"]], widget=widgets.RadioSelectHorizontal, default=None, label=''' How did the other workers rate this persons' trustworthiness? ; 1= Not at all trustworthy; 4 = Very trustworthy ''') b2_credit = models.IntegerField(choices=[[1, "1"], [2, "2"], [3, "3"], [4, "4"]], widget=widgets.RadioSelectHorizontal, default=None, label=''' "Creditworthiness describes how likely a person is to repay a financial obligation according to the terms of the agreement.” How did the other workers rate this persons' creditworthiness?; 1= Not at all creditworthy; 4 = Very creditworthy. ''') b2_lend = models.IntegerField(choices=[[1, "0"],[2, "1"], [3, "2"], [4, "3"]], widget=widgets.RadioSelectHorizontal, default=None, label=''' How many, out of 3 randomly selected workers, would be very likely to lend this person $100, if the person's needed it?; 0 = None of them; 3 = All of them ''')