from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants import time class Task(Page): form_model = 'player' form_fields = ['answer'] timer_text = "Remaining time:" def is_displayed(self): return self.participant.vars['expiry'] - time.time() > 1 def get_timeout_seconds(self): return self.participant.vars['expiry'] - time.time() def vars_for_template(self): round = self.round_number return { 'round': round, } def before_next_page(self): solutions = [29, 28, 39, 36, 33, 36, 38, 38, 30, 37, 29, 40, 39, 39, 30, 39, 47, 46, 31, 35] round = self.round_number player = self.player if round == 1: player.score = 0 else: player.score = player.in_round(round - 1).score if player.answer == solutions[round - 1]: player.score += 1 if round == Constants.num_rounds or \ player.participant.vars['expiry'] - time.time() <= 1: print("Saving score to participant vars.") player.participant.vars['score'] = player.score page_sequence = [Task]