from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants class Instructions(Page): def is_displayed(self): return self.round_number == 1 def vars_for_template(self): return{ 'tasks_for_today': self.participant.vars['w1'], 'tasks_for_tomorrow': self.participant.vars['w2'], 'total_tasks_for_today': self.participant.vars['w1'] + Constants.required_tasks, 'total_tasks_for_tomorrow': self.participant.vars['w2'] + Constants.required_tasks, 'payoff': self.participant.vars['payoff'], 'rewarded_w1': self.participant.vars['w_rewarded'][0] + Constants.required_tasks, 'rewarded_w2': self.participant.vars['w_rewarded'][1] + Constants.required_tasks } def before_next_page(self): self.participant.vars['correct_answers'] = 0 self.participant.vars['finished'] = False class Task(Page): form_model = 'player' form_fields = ['answer'] def is_displayed(self): return self.participant.vars['correct_answers'] < self.participant.vars['w2'] + Constants.required_tasks def vars_for_template(self): x = self.player.matrix_id_in_round self.participant.vars['correct_answers'] = sum([p.answer_correct for p in self.player.in_previous_rounds()]) if self.round_number > 1: return{ 'matrix_id': x, 'image_path': 'elicitation/matrix_{}.gif'.format(x), 'solution': Constants.Matrix[x], 'matrix_number': self.participant.vars['correct_answers'] + 1, 'correct_answers': self.participant.vars['correct_answers'], 'total_tasks_for_tomorrow': self.participant.vars['w2'] + Constants.required_tasks, 'previous_correct': self.player.in_round(self.round_number - 1).answer_correct } else: return{ 'matrix_id': x, 'image_path': 'elicitation/matrix_{}.gif'.format(x), 'solution': Constants.Matrix[x], 'matrix_number': self.participant.vars['correct_answers'] + 1, 'correct_answers': self.participant.vars['correct_answers'], 'total_tasks_for_tomorrow': self.participant.vars['w2'] + Constants.required_tasks } def before_next_page(self): x = self.player.matrix_id_in_round self.player.answer_correct = (self.player.answer == Constants.Matrix[x]) self.participant.vars['correct_answers'] = sum([p.answer_correct for p in self.player.in_all_rounds()]) class Finish(Page): def is_displayed(self): return self.participant.vars['correct_answers'] == self.participant.vars['w2'] + Constants.required_tasks \ and not self.participant.vars['finished'] def vars_for_template(self): return{ 'tasks_for_tomorrow': self.participant.vars['w2'], 'total_tasks_for_tomorrow': self.participant.vars['w2'] + Constants.required_tasks, 'payoff': self.participant.vars['payoff'], 'chosen_payment_scheme': self.participant.vars['chosen_scheme'][0], 'rewarded_w1': self.participant.vars['w_rewarded'][0] + Constants.required_tasks, 'rewarded_w2': self.participant.vars['w_rewarded'][1] + Constants.required_tasks } def before_next_page(self): self.participant.vars['finished'] = True print('Participant vars are', self.participant.vars) page_sequence = [ Instructions, Task, Finish ]