from otree.api import * import json # ------------------- # Constants # ------------------- class C(BaseConstants): NAME_IN_URL = 'comprehension' PLAYERS_PER_GROUP = None NUM_ROUNDS = 1 # ------------------- # Group / Player / Subsession # ------------------- class Group(BaseGroup): pass class Player(BasePlayer): comp_attempts1 = models.IntegerField(initial=1) comp_answer1a = models.BooleanField( blank=True, choices=[ [True, 'True'], [False, 'False'], ], widget=widgets.RadioSelect ) comp_answer1b = models.BooleanField( blank=True, choices=[ [True, 'True'], [False, 'False'],], widget=widgets.RadioSelect ) comp_answer1c = models.BooleanField( blank=True, choices=[ [True, 'True'], [False, 'False']], widget=widgets.RadioSelect ) comp_attempts2 = models.IntegerField(initial=1) comp_answer2a = models.BooleanField( blank=True, choices=[ [True, 'True'], [False, 'False'], ], widget=widgets.RadioSelect ) comp_answer2b = models.BooleanField( blank=True, choices=[ [True, 'True'], [False, 'False'],], widget=widgets.RadioSelect ) comp_answer2c = models.BooleanField( blank=True, choices=[ [True, 'True'], [False, 'False']], widget=widgets.RadioSelect ) comp_attempts3 = models.IntegerField(initial=1) comp_answer3a = models.BooleanField( blank=True, initial=False, choices=[ [True, 'True'], [False, 'False'], ], widget=widgets.RadioSelect ) comp_answer3b = models.BooleanField( blank=True, initial=False, choices=[ [True, 'True'], [False, 'False'],], widget=widgets.RadioSelect ) comp_answer3c = models.BooleanField( blank=True, initial=False, choices=[ [True, 'True'], [False, 'False']], widget=widgets.RadioSelect ) class Subsession(BaseSubsession): pass # ------------------- # Pages # ------------------- class CompQ1(Page): form_model = 'player' form_fields = ['comp_answer1a', 'comp_answer1b', 'comp_answer1c'] @staticmethod def error_message(player, values): # If any answer is False, return a single error for the page if not (values.get('comp_answer1a') and values.get('comp_answer1b') and values.get('comp_answer1c')): player.comp_attempts1 += 1 return 'At least one of your answers is incorrect. Please try again.' class CompQ2(Page): form_model = 'player' form_fields = ['comp_answer2a', 'comp_answer2b', 'comp_answer2c'] @staticmethod def error_message(player, values): # If any answer is False, return a single error for the page if not (values.get('comp_answer2a') and values.get('comp_answer2b') and values.get('comp_answer2c')): player.comp_attempts2 += 1 return 'At least one of your answers is incorrect. Please try again.' class CompQ3(Page): form_model = 'player' form_fields = ['comp_answer3a', 'comp_answer3b', 'comp_answer3c'] @staticmethod def error_message(player, values): # Check the expected pattern: only B is True if not (values['comp_answer3a'] is False and values['comp_answer3b'] is True and values['comp_answer3c'] is False): player.comp_attempts3 += 1 return 'At least one of your answers is incorrect. Please try again.' # ------------------- # Page sequence # ------------------- page_sequence = [CompQ1, CompQ2, CompQ3] # page_sequence = [CompQ3]