from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants import datetime from django.conf import settings from django.db.models import ExpressionWrapper, F, DurationField import time class Screen(Page): form_model = 'player' form_fields = ['submitted_answer'] # timeout_seconds = 5 def submitted_answer_choices(self): if self.round_number <= 8: return Constants.CHOICES elif 8 < self.round_number <= 16: return Constants.CHOICES_1 elif 16 < self.round_number <= 24: return Constants.CHOICES_2 else: return Constants.CHOICES_3 def vars_for_template(self): total_payoff = 0 for p in self.player.in_all_rounds(): if p.payoff_score is not None: total_payoff += p.payoff_score return { 'total_payoff': round(total_payoff), 'counter': self.round_number, 'debug': settings.DEBUG, } def before_next_page(self): self.player.score_round() if self.round_number == 1: self.player.finish_time = datetime.datetime.now() self.player.time_difference = self.player.finish_time - self.player.start_time else: self.player.finish_time = datetime.datetime.now() self.player.time_difference = self.player.finish_time - self.player.in_round(self.round_number -1).finish_time def get_timeout_seconds(self): if self.round_number >= 17: return 10 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 for p in self.player.in_all_rounds(): if p.payoff_score != None: total_payoff += p.payoff_score return { 'total_payoff': round(total_payoff), 'debug': settings.DEBUG, } page_sequence = [ Screen, ResultsWaitPage, Results ]