from otree.api import * class C(BaseConstants): NAME_IN_URL = 'aa_task' PLAYERS_PER_GROUP = None NUM_ROUNDS = 1 PRIZE = 100 # points class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): # Red elicitation AA_red_q1 = models.StringField( choices=[['K', 'Box K'], ['I', 'Indifferent'], ['U', 'Box U']], label='') AA_red_p2 = models.FloatField(initial=0) AA_red_q2 = models.StringField( choices=[['K', 'Box K'], ['I', 'Indifferent'], ['U', 'Box U']], label='') AA_red_p3 = models.FloatField(initial=0) AA_red_q3 = models.StringField( choices=[['K', 'Box K'], ['I', 'Indifferent'], ['U', 'Box U']], label='') AA_red_matching_prob = models.FloatField(initial=0) # Black elicitation AA_black_q1 = models.StringField( choices=[['K', 'Box K'], ['I', 'Indifferent'], ['U', 'Box U']], label='') AA_black_p2 = models.FloatField(initial=0) AA_black_q2 = models.StringField( choices=[['K', 'Box K'], ['I', 'Indifferent'], ['U', 'Box U']], label='') AA_black_p3 = models.FloatField(initial=0) AA_black_q3 = models.StringField( choices=[['K', 'Box K'], ['I', 'Indifferent'], ['U', 'Box U']], label='') AA_black_matching_prob = models.FloatField(initial=0) # Index: >0 averse, <0 seeking, =0 neutral AA_ambiguity_index = models.FloatField(initial=0) # FUNCTIONS def next_prob(current, choice, step): if choice == 'K': return current - step elif choice == 'U': return current + step else: # Indifferent return current def fmt_pct(p): pct = p * 100 return str(int(pct)) if pct == int(pct) else f"{pct:.1f}" # PAGES class AA_Instructions(Page): pass class AA_Red_Q1(Page): form_model = 'player' form_fields = ['AA_red_q1'] template_name = 'Ellsberg/AA_Question.html' @staticmethod def vars_for_template(player): return dict( color_en='red', color_de='rote', prob_pct='50', question_num=1, part=1, overall_num=1, field_name='AA_red_q1', ) @staticmethod def before_next_page(player, timeout_happened): player.AA_red_p2 = next_prob(0.5, player.AA_red_q1, 0.25) class AA_Red_Q2(Page): form_model = 'player' form_fields = ['AA_red_q2'] template_name = 'Ellsberg/AA_Question.html' @staticmethod def vars_for_template(player): return dict( color_en='red', color_de='rote', prob_pct=fmt_pct(player.AA_red_p2), question_num=2, part=1, overall_num=2, field_name='AA_red_q2', ) @staticmethod def before_next_page(player, timeout_happened): player.AA_red_p3 = next_prob(player.AA_red_p2, player.AA_red_q2, 0.125) class AA_Red_Q3(Page): form_model = 'player' form_fields = ['AA_red_q3'] template_name = 'Ellsberg/AA_Question.html' @staticmethod def vars_for_template(player): return dict( color_en='red', color_de='rote', prob_pct=fmt_pct(player.AA_red_p3), question_num=3, part=1, overall_num=3, field_name='AA_red_q3', ) @staticmethod def before_next_page(player, timeout_happened): player.AA_red_matching_prob = next_prob( player.AA_red_p3, player.AA_red_q3, 0.0625) class AA_Black_Q1(Page): form_model = 'player' form_fields = ['AA_black_q1'] template_name = 'Ellsberg/AA_Question.html' @staticmethod def vars_for_template(player): return dict( color_en='black', color_de='schwarze', prob_pct='50', question_num=1, part=2, overall_num=4, field_name='AA_black_q1', ) @staticmethod def before_next_page(player, timeout_happened): player.AA_black_p2 = next_prob(0.5, player.AA_black_q1, 0.25) class AA_Black_Q2(Page): form_model = 'player' form_fields = ['AA_black_q2'] template_name = 'Ellsberg/AA_Question.html' @staticmethod def vars_for_template(player): return dict( color_en='black', color_de='schwarze', prob_pct=fmt_pct(player.AA_black_p2), question_num=2, part=2, overall_num=5, field_name='AA_black_q2', ) @staticmethod def before_next_page(player, timeout_happened): player.AA_black_p3 = next_prob( player.AA_black_p2, player.AA_black_q2, 0.125) class AA_Black_Q3(Page): form_model = 'player' form_fields = ['AA_black_q3'] template_name = 'Ellsberg/AA_Question.html' @staticmethod def vars_for_template(player): return dict( color_en='black', color_de='schwarze', prob_pct=fmt_pct(player.AA_black_p3), question_num=3, part=2, overall_num=6, field_name='AA_black_q3', ) @staticmethod def before_next_page(player, timeout_happened): player.AA_black_matching_prob = next_prob( player.AA_black_p3, player.AA_black_q3, 0.0625) player.AA_ambiguity_index = ( 1 - player.AA_red_matching_prob - player.AA_black_matching_prob ) page_sequence = [ AA_Instructions, AA_Red_Q1, AA_Red_Q2, AA_Red_Q3, AA_Black_Q1, AA_Black_Q2, AA_Black_Q3, ]