from otree.api import * c = cu doc = '' class C(BaseConstants): NAME_IN_URL = 'Quiz' PLAYERS_PER_GROUP = None NUM_ROUNDS = 1 def get_quiz_data(): return [ dict( name='q1', solution=True, explanation="You will be regrouped at the beginning of each period", ), dict( name='q2', solution=True, explanation="Your role will remain the same throughout the study", ), dict( name='q3', solution=False, explanation="Because income of the manager = 100 + 4*Output– Total wage for the two workers, given the same output, the higher the wage, the lower the income for the manager ", ), dict( name='q4', solution=True, explanation="Income of the worker = Wage - Cost of the work level chosen, so when given the same wage, the higher the work level the higher the cost for the worker", ), dict( name='q51', solution= 31, explanation="the total wage offer is 70 dimra, so worker one gets 35 dimra, so worker one's income = 35-2*2=31", ), dict( name='q52', solution=21, explanation="the total wage offer is 70 dimra, so worker two gets 35 dimra, so worker two's income = 35-2*7=21", ), dict( name='q53', solution=66, explanation="output=4*(2+7)=36, so manager's income = 100+36-70=66", ) ] class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): q1 = models.BooleanField(choices=[[True, 'Yes'], [False, 'No']], label='1. You will be regrouped at the beginning of each period', widget=widgets.RadioSelectHorizontal) q2 = models.BooleanField(choices=[[True, 'Yes'], [False, 'No']], label='2. Your role of worker or manager will remain the same throughout the study', widget=widgets.RadioSelectHorizontal) q3 = models.BooleanField(choices=[[True, 'Yes'], [False, 'No']], label='3. Given the same output, the higher the wage, the higher the income for the manager ', widget=widgets.RadioSelectHorizontal) q4 = models.BooleanField(choices=[[True, 'Yes'], [False, 'No']], label='4. The higher the work level the higher the cost for the worker', widget=widgets.RadioSelectHorizontal) q52 = models.IntegerField(label="") q53 = models.IntegerField(label="") q51 = models.IntegerField(label="") q61 = models.IntegerField(label="") q62 = models.IntegerField(label="") q63 = models.IntegerField(label="") correct_answers = models.IntegerField(initial=0) class Part2Instruction(Page): pass class IncomeCalculation(Page): pass class QuizIntro(Page): pass class CalculationExample(Page): pass class MyWaitPage(WaitPage): pass class QuizTF(Page): form_model = 'player' form_fields = [ 'q1', 'q2', 'q3', 'q4','q51', 'q52', 'q53'] timer_text = 'Below is the time left to complete this section, please do not drop' @staticmethod def error_message(player: Player, values): pass @staticmethod def vars_for_template(player: Player): fields = get_quiz_data() return dict(fields=fields, show_solutions=False) def before_next_page(self): for d in fields: d['is_correct'] = getattr(player, d['name']) == d['solution'] return dict(fields=fields, show_solutions=True) class PART2Intro(Page): pass class Results1(Page): form_model = 'player' form_fields = ['q1', 'q2', 'q3', 'q4','q51', 'q52', 'q53'] @staticmethod def vars_for_template(player: Player): fields = get_quiz_data() # we add an extra entry 'is_correct' (True/False) to each field for d in fields: d['is_correct'] = getattr(player, d['name']) == d['solution'] return dict(fields=fields, show_solutions=True) @staticmethod def error_message(player: Player, values): for field in values: if getattr(player, field) != values[field]: return "A field was somehow changed but this page is read-only." class QuizEnd(Page): def before_next_page(player, timeout_happened): import itertools is_manager = itertools.cycle([False, True, False, False, False, True]) for player in player.subsession.get_players(): participant = player.participant participant.is_manager = next(is_manager) page_sequence = [PART2Intro, Part2Instruction, IncomeCalculation, CalculationExample, QuizIntro, QuizTF, Results1, QuizEnd ]