from otree.api import * import random doc = """ Your app description """ class Constants(BaseConstants): name_in_url = 'ai' players_per_group = None num_rounds = 1 comp1 = 'True' comp2 = 'False' comp3 = 'True' comp4 = '18' comp5 = '92' timeout = 40 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass # BUILD FUNCTIONS def likert_7(label): return models.IntegerField( choices = [ [1, ''], [2, ''], [3, ''], [4, ''], [5, ''], [6, ''], [7, ''], ], label = label, widget = widgets.RadioSelect ) def make_field_A_B(): return models.BooleanField( choices = [ [True, 'A'], [False, 'B'], ], widget=widgets.RadioSelectHorizontal, label = '' ) class Player(BasePlayer): wlp = models.IntegerField(choices=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], label="Please select a work level.") wl = models.IntegerField(initial=0) name = models.StringField(label="") wl1 = models.IntegerField(choices=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], label="Please select a work level.") wl2 = models.IntegerField(choices=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], label="Please select a work level.") wl3 = models.IntegerField(choices=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], label="Please select a work level.") wl4 = models.IntegerField(choices=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], label="Please select a work level.") wl5 = models.IntegerField(choices=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], label="Please select a work level.") wl6 = models.IntegerField(choices=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], label="Please select a work level.") wl7 = models.IntegerField(choices=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], label="Please select a work level.") wl8 = models.IntegerField(choices=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], label="Please select a work level.") wl9 = models.IntegerField(choices=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], label="Please select a work level.") wl10 = models.IntegerField(choices=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], label="Please select a work level.") Q1 = models.StringField( choices=['True', 'False'], widget=widgets.RadioSelect, label='1. The higher the work level, the higher the reward.', initial='filler' ) Q2 = models.StringField( choices=['True', 'False'], widget=widgets.RadioSelect, label='2. The higher the work level, the lower the cost.', initial='filler' ) Q3 = models.StringField( choices=['True', 'False'], widget=widgets.RadioSelect, label='3. The reporting error in this round is 27 Lira.', initial='filler' ) Q4 = models.StringField( label='4. If you select work level 2 and the reporting error DOES NOT result in your favor, how many Lira'\ ' will your actual payoff be? (Please enter your answer as a number with no spaces)', ) Q5 = models.StringField( label='5. If you select work level 10 and the reporting error DOES result in your favor, how many Lira' \ ' will your actual payoff be? (Please enter your answer as a number with no spaces)', ) r = models.IntegerField() rt = models.IntegerField(initial=0) Pay = models.IntegerField(initial=0) fm = models.StringField() peq1 = likert_7('I found the task interesting.') # Post-Experimental Question 1 peq2 = likert_7('I found the task enjoyable. ') # Post-Experimental Question 2 peq3 = likert_7('I thought carefully about my work level choices.') # Post-Experimental Question 3 ra1 = make_field_A_B() ra2 = make_field_A_B() ra3 = make_field_A_B() ra4 = make_field_A_B() ra5 = make_field_A_B() ra6 = make_field_A_B() ra7 = make_field_A_B() ra8 = make_field_A_B() ra9 = make_field_A_B() ra10 = make_field_A_B() ra11 = make_field_A_B() # FUNCTIONS def Q1_error_message(player, Q1): if Q1 != Constants.comp1: return 'Incorrect. It is TRUE. The higher the work level, the higher the reward. Answer correctly to continue.' def Q2_error_message(player, Q2): if Q2 != Constants.comp2: return 'Incorrect. It is FALSE. The higher the work level, the higher the cost. Answer correctly to continue.' def Q3_error_message(player, Q3): if Q3 != Constants.comp3: return 'Incorrect. It is TRUE. The reporting error in this round is 27 Lira. Answer correctly to continue.' def Q4_error_message(player, Q4): if Q4 != Constants.comp4: return 'Incorrect. 45-27=18. The correct answer is 18. Answer correctly to continue.' def Q5_error_message(player, Q5): if Q5 != Constants.comp5: return 'Incorrect. 65+27=92. The correct answer is 92. Answer correctly to continue.' def det_favor(player): if player.Pay < player.r: favor = True else: favor = False if favor == True: return 'The reporting error worked in your favor. The top line on the graph indicates your payoff after the reporting error.' else: return 'The reporting error did not work in your favor. The bottom line on the graph indicates your payoff after the reporting error.' def calc_payoff(player): additive = random.choice([True, False]) if additive == True: payoff = player.Pay + 27 else: payoff = player.Pay - 27 return payoff def wl_calc_Pay(player, wl): if wl == 0: player.Pay = 30 elif wl == 1: player.Pay = 38 elif wl == 2: player.Pay = 45 elif wl == 3: player.Pay = 51 elif wl == 4: player.Pay = 56 elif wl == 5: player.Pay = 60 elif wl == 6: player.Pay = 63 elif wl == 7: player.Pay = 65 elif wl == 8: player.Pay = 66 elif wl == 9: player.Pay = 66 else: player.Pay = 65 return player.Pay # PAGES class over(Page): form_model = 'player' form_fields = ['wlp'] class err(Page): pass class feed(Page): form_model = 'player' form_fields = ['name'] class compq(Page): form_model = 'player' form_fields = ['Q1', 'Q2', 'Q3', 'Q4', 'Q5'] class ready(Page): pass class p1(Page): timeout_seconds = Constants.timeout form_model = 'player' form_fields = ['wl1'] @staticmethod def before_next_page(player, timeout_happened): player.wl = player.wl1 player.Pay = wl_calc_Pay(player, player.wl) player.r = calc_payoff(player) player.fm = det_favor(player) player.rt = player.rt + player.r class r1(Page): pass @staticmethod def vars_for_template(player): return dict( r=player.r, w=player.wl, p=player.Pay, f=player.fm ) class p2(Page): timeout_seconds = Constants.timeout form_model = 'player' form_fields = ['wl2'] @staticmethod def before_next_page(player, timeout_happened): player.wl = player.wl2 player.Pay = wl_calc_Pay(player, player.wl) player.r = calc_payoff(player) player.fm = det_favor(player) player.rt = player.rt + player.r class r2(Page): pass @staticmethod def vars_for_template(player): return dict( r=player.r, w=player.wl, p=player.Pay, f=player.fm ) class p3(Page): timeout_seconds = Constants.timeout form_model = 'player' form_fields = ['wl3'] @staticmethod def before_next_page(player, timeout_happened): player.wl = player.wl3 player.Pay = wl_calc_Pay(player, player.wl) player.r = calc_payoff(player) player.fm = det_favor(player) player.rt = player.rt + player.r class r3(Page): pass @staticmethod def vars_for_template(player): return dict( r=player.r, w=player.wl, p=player.Pay, f=player.fm ) class p4(Page): timeout_seconds = Constants.timeout form_model = 'player' form_fields = ['wl4'] @staticmethod def before_next_page(player, timeout_happened): player.wl = player.wl4 player.Pay = wl_calc_Pay(player, player.wl) player.r = calc_payoff(player) player.fm = det_favor(player) player.rt = player.rt + player.r class r4(Page): pass @staticmethod def vars_for_template(player): return dict( r=player.r, w=player.wl, p=player.Pay, f=player.fm ) class p5(Page): timeout_seconds = Constants.timeout form_model = 'player' form_fields = ['wl5'] @staticmethod def before_next_page(player, timeout_happened): player.wl = player.wl5 player.Pay = wl_calc_Pay(player, player.wl) player.r = calc_payoff(player) player.fm = det_favor(player) player.rt = player.rt + player.r class r5(Page): pass @staticmethod def vars_for_template(player): return dict( r=player.r, w=player.wl, p=player.Pay, f=player.fm ) class p6(Page): timeout_seconds = Constants.timeout form_model = 'player' form_fields = ['wl6'] @staticmethod def before_next_page(player, timeout_happened): player.wl = player.wl6 player.Pay = wl_calc_Pay(player, player.wl) player.r = calc_payoff(player) player.fm = det_favor(player) player.rt = player.rt + player.r class r6(Page): pass @staticmethod def vars_for_template(player): return dict( r=player.r, w=player.wl, p=player.Pay, f=player.fm ) class p7(Page): timeout_seconds = Constants.timeout form_model = 'player' form_fields = ['wl7'] @staticmethod def before_next_page(player, timeout_happened): player.wl = player.wl7 player.Pay = wl_calc_Pay(player, player.wl) player.r = calc_payoff(player) player.fm = det_favor(player) player.rt = player.rt + player.r class r7(Page): pass @staticmethod def vars_for_template(player): return dict( r=player.r, w=player.wl, p=player.Pay, f=player.fm ) class p8(Page): timeout_seconds = Constants.timeout form_model = 'player' form_fields = ['wl8'] @staticmethod def before_next_page(player, timeout_happened): player.wl = player.wl8 player.Pay = wl_calc_Pay(player, player.wl) player.r = calc_payoff(player) player.fm = det_favor(player) player.rt = player.rt + player.r class r8(Page): pass @staticmethod def vars_for_template(player): return dict( r=player.r, w=player.wl, p=player.Pay, f=player.fm ) class p9(Page): timeout_seconds = Constants.timeout form_model = 'player' form_fields = ['wl9'] @staticmethod def before_next_page(player, timeout_happened): player.wl = player.wl9 player.Pay = wl_calc_Pay(player, player.wl) player.r = calc_payoff(player) player.fm = det_favor(player) player.rt = player.rt + player.r class r9(Page): pass @staticmethod def vars_for_template(player): return dict( r=player.r, w=player.wl, p=player.Pay, f=player.fm ) class p10(Page): timeout_seconds = Constants.timeout form_model = 'player' form_fields = ['wl10'] @staticmethod def before_next_page(player, timeout_happened): player.wl = player.wl10 player.Pay = wl_calc_Pay(player, player.wl) player.r = calc_payoff(player) player.fm = det_favor(player) player.rt = player.rt + player.r class r10(Page): pass @staticmethod def vars_for_template(player): return dict( r=player.r, w=player.wl, p=player.Pay, f=player.fm ) class peq(Page): form_model = 'player' form_fields = ['peq1', 'peq2', 'peq3'] class ab(Page): form_model = 'player' form_fields = ['ra1', 'ra2', 'ra3', 'ra4', 'ra5', 'ra6', 'ra7', 'ra8', 'ra9', 'ra10', 'ra11'] @staticmethod def app_after_this_page(player, upcoming_apps): if player.participant.treatment == "AI": return upcoming_apps[1] page_sequence = [over, err, feed, compq, ready, p1, r1, p2, r2, p3, r3, p4, r4, p5, r5, p6, r6, p7, r7, p8, r8, p9, r9, p10, r10, peq, ab]