from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) import itertools import random author = 'Elisa' class Constants(BaseConstants): name_in_url = 'rating' players_per_group = None num_rounds = 1 n_applications = 5 # Bonus max_bonus = c(5000) # Randomize application received from Arm 1: # Random order list_applications_A = ['app_A_arm2_n1.png','app_A_arm2_n2.png', 'app_A_arm2_n3.png', 'app_A_arm2_n4.png', 'app_A_arm2_n5.png', 'app_A_arm2_n6.png', 'app_A_arm2_n7.png', 'app_A_arm2_n8.png'] list_applications_B = ['app_B_arm2_n1.png','app_B_arm2_n2.png', 'app_B_arm2_n3.png', 'app_B_arm2_n4.png', 'app_B_arm2_n5.png', 'app_B_arm2_n6.png', 'app_B_arm2_n7.png', 'app_B_arm2_n8.png'] evaluations = { 'loanapp_A_1_arm1.jpg': 1, 'loanapp_A_2_arm1.jpg': 2, 'loanapp_A_3_arm1.jpg': 5, 'loanapp_B_1_arm1.jpg': 4, 'loanapp_B_2_arm1.jpg': 0, 'loanapp_B_3_arm1.jpg': 1 } class Subsession(BaseSubsession): def creating_session(self): # Randomize double treatment order = itertools.cycle(['A', 'B']) for p in self.get_players(): # double treatment (rich/poor) p.order = next(order) if p.order == 'A': applications_set = random.sample(Constants.list_applications_A, k=Constants.n_applications) elif p.order == 'B': applications_set = random.sample(Constants.list_applications_B, k=Constants.n_applications) p.application1 = applications_set[0] p.application2 = applications_set[1] p.application3 = applications_set[2] p.application4 = applications_set[3] p.application5 = applications_set[4] class Group(BaseGroup): def set_payoff(self): players = self.get_players() for p in players: p.points = 0 for k, v in Constants.evaluations.items(): if p.application1 == k: if round(p.r1) == v: p.points += 1 else: p.points += 0 if p.application2 == k: if round(p.r2) == v: p.points += 1 else: p.points += 0 if p.application3 == k: if round(p.r3) == v: p.points += 1 else: p.points += 0 if p.application4 == k: if round(p.r4) == v: p.points += 1 else: p.points += 0 p.payoff = 1250 * p.points class Player(BasePlayer): # Treatments order = models.StringField() # Applications seen application1 = models.StringField() application2 = models.StringField() application3 = models.StringField() application4 = models.StringField() application5 = models.StringField() # Store response: r1A = models.IntegerField(choices=[[1,""],[2,""],[3,""],[4,""],[5,""]], widget=widgets.RadioSelectHorizontal, default=None, label='''On average, how did the loan officers rate the applicant's likelihood to receive the requested loan?; Not at all likely; Extremely likely''') r1B = models.IntegerField(choices=[[1,"Yes"],[2,"No"]], widget=widgets.RadioSelectHorizontal, default=None, label='Should the person ' 'apply for the loan or not?;;') r2A = models.IntegerField(choices=[[1,""],[2,""],[3,""],[4,""],[5,""]], widget=widgets.RadioSelectHorizontal, default=None, label='''On average, how did the loan officers rate the applicant's likelihood to receive the requested loan?; Not at all likely; Extremely likely''') r2B = models.IntegerField(choices=[[1,"Yes"],[2,"No"]], widget=widgets.RadioSelectHorizontal, default=None, label='Should the person ' 'apply for the loan or not?;;') r3A = models.IntegerField(choices=[[1,""],[2,""],[3,""],[4,""],[5,""]], widget=widgets.RadioSelectHorizontal, default=None, label='''On average, how did the loan officers rate the applicant's likelihood to receive the requested loan?; Not at all likely; Extremely likely''') r3B = models.IntegerField(choices=[[1,"Yes"],[2,"No"]], widget=widgets.RadioSelectHorizontal, default=None, label='Should the person ' 'apply for the loan or not?;;') r4A = models.IntegerField(choices=[[1,""],[2,""],[3,""],[4,""],[5,""]], widget=widgets.RadioSelectHorizontal, default=None, label='''On average, how did the loan officers rate the applicant's likelihood to receive the requested loan?; Not at all likely; Extremely likely''') r4B = models.IntegerField(choices=[[1,"Yes"],[2,"No"]], widget=widgets.RadioSelectHorizontal, default=None, label='Should the person ' 'apply for the loan or not?;;') r5A = models.IntegerField(choices=[[1,""],[2,""],[3,""],[4,""],[5,""]], widget=widgets.RadioSelectHorizontal, default=None, label='''On average, how did the loan officers rate the applicant's likelihood to receive the requested loan?; Not at all likely; Extremely likely''') r5B = models.BooleanField(choices=[[1,"Yes"],[2,"No"]], widget=widgets.RadioSelectHorizontal, default=None, label='Should the person ' 'apply for the loan or not?;;') # Check answers: points = models.IntegerField()