from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants from django.conf import settings class Screen(Page): form_model = 'player' def submitted_answer_choices(self): qd = self.player.current_question() return [ int(qd['choice1']), int(qd['choice2']), int(qd['choice3']), ] def get_form_fields(self): if self.player.round_number == 4: return ['guess_math'] elif self.player.round_number == Constants.num_rounds: return ['math_ambition'] else: return ['submitted_answer'] def vars_for_template(self): total_payoff = 0 if self.round_number > 4: for p in self.player.in_all_rounds(): if p.payoff_score is not None: total_payoff += p.payoff_score round_number = self.round_number - 4 else: round_number = self.round_number return { 'total_payoff': round(total_payoff), 'counter': self.round_number, 'round_count': (round_number - 1), 'debug': settings.DEBUG, } def before_next_page(self): if self.round_number != Constants.num_rounds: self.player.score_round() class ResultsWaitPage(WaitPage): def is_displayed(self): return self.round_number == Constants.num_rounds def after_all_players_arrive(self): pass class Results(Page): def is_displayed(self): return self.round_number == Constants.num_rounds def vars_for_template(self): total_payoff = 0 total_guess_math = 0 for p in self.player.in_all_rounds(): if p.payoff_score is not None: total_payoff += p.payoff_score if p.guess_math is not None: total_guess_math += p.guess_math if int(total_payoff) == int(total_guess_math): total_payoff += 4 return { 'total_payoff': round(total_payoff), 'quess_math': round(total_guess_math), 'total_score': round(total_payoff) } page_sequence = [ Screen, ResultsWaitPage, Results ]