from otree.api import * doc = """ Comprehension Check """ class Constants(BaseConstants): name_in_url = 'COMP' players_per_group = None num_rounds = 1 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): num_failed_attempts = models.IntegerField(initial=0) failed_too_many = models.BooleanField(initial=False) remaining_attempts = models.IntegerField(initial=0) commit = models.IntegerField( blank=False, choices=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], widget=widgets.RadioSelect, ) task = models.IntegerField( blank=False, choices=[[1, 'Find the best investment option'], [2, 'Make exit decisions'], [3, 'Show that I understand statistics']], label='1. What is your task in this experiment?', widget=widgets.RadioSelect, ) cost = models.IntegerField( blank=False, choices=[[1, '-$5'], [2, '-$2.5'], [3, '$0']], label='2. If you earn $10 in Round 1, 0 in Round 2, -$5 in Round 3, and decide to exit in Round 4, ' 'what is your terminal value after deducting the exit cost of $10?', widget=widgets.RadioSelect, ) income = models.IntegerField( blank=False, choices=[[1, '$52.5'], [2, '$55'], [3, '$57.5']], label=''' 3. Assume that the realized income after Round 2 is $60. Suppose it is expected to increase by $20 with a probability of 50% or decrease by 25 with a probability of 50% in Round 3. What will be the cumulative expected income in Round 3?''', widget=widgets.RadioSelect, ) # PAGES class COMP(Page): form_model = 'player' form_fields = ['task', 'cost', 'income', 'commit'] @staticmethod def error_message(player, values): solutions = dict( task=2, cost=1, income=3 ) error_messages = dict( task='Please try again.', cost='Please try again.', income='Please try again.', ) errors = {name: error_messages[name] for name in solutions if values[name] != solutions[name]} if errors: player.num_failed_attempts += 1 if player.num_failed_attempts >= 3: player.failed_too_many = True else: return errors @staticmethod def vars_for_template(player: Player): return dict( remaining_attempt=3 - player.num_failed_attempts, ) class Failed(Page): @staticmethod def is_displayed(player: Player): return player.failed_too_many @staticmethod def app_after_this_page(player, upcoming_apps): return upcoming_apps[0] # @staticmethod # def error_message(player: Player, values): # solutions = dict(task=2, cost=10, income=3) # if values != solutions: # return "One or more answers were incorrect." page_sequence = [COMP, Failed]