from otree.api import * doc = """ Sunk_High_Instruction """ class Constants(BaseConstants): name_in_url = 'Inst_SK_H' 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) 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 total cumulative value after deducting the exit cost of $10?', widget=widgets.RadioSelect, ) income = models.IntegerField( blank=False, choices=[[1, '$60'], [2, '$70'], [3, '$80']], label=''' 3. Assume that the realized income after Round 2 is $60. Suppose you experience a $20 increase in Round 3. What will your income be in Round 3?''', widget=widgets.RadioSelect, ) # PAGES class MainGame_intro(Page): pass 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] class G_intro(Page): pass page_sequence = [MainGame_intro, COMP, Failed, G_intro]