from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants import time from django.conf import settings class Screen(Page): form_model = 'player' def get_form_fields(self): if self.player.round_number == 4: return ['guess_german'] elif self.player.round_number == (Constants.num_rounds): return ['german_ambition'] else: return ['submitted_answer'] def submitted_answer_choices(self): qd = self.player.current_question() return [ str(qd['choice1']), str(qd['choice2']), str(qd['choice3']), ] 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 != 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_german = 0 for p in self.player.in_all_rounds(): if p.payoff_score != None: total_payoff += p.payoff_score if p.guess_german != None: total_guess_german += p.guess_german if int(total_payoff) == int(total_guess_german): total_payoff += 4 return { 'total_payoff': round(total_payoff), 'quess_german': round(total_guess_german), 'total_score': round(total_payoff + total_guess_german) } page_sequence = [ Screen, ResultsWaitPage, Results ]