from . import models from ._builtin import Page, WaitPage from otree.api import Currency as c, currency_range from .models import Constants from django.conf import settings import time import random class start(Page): form_model = models.Player form_fields = ['Enter'] def is_displayed(self): return self.round_number == 1 def before_next_page(self): # user has ret_timer seconds to complete as many pages as possible # self.participant.vars['expiry_timestamp'] = time.time() + self.player.task_timer # this caused an error self.participant.vars['expiry_timestamp'] = time.time() + 120 def vars_for_template(self): return { 'debug': settings.DEBUG, } class task(Page): form_model = models.Player form_fields = ['user_total'] # timeout_seconds = self.player.ret_timer # time? no, only works on specific pages def get_timeout_seconds(self): return self.participant.vars['expiry_timestamp'] - time.time() def is_displayed(self): return self.participant.vars['expiry_timestamp'] - time.time() > 3 def vars_for_template(self): self.player.int1 = Constants.INTS_T1[self.round_number - 1][0] self.player.int2 = Constants.INTS_T1[self.round_number - 1][1] self.player.int3 = Constants.INTS_T1[self.round_number - 1][2] self.player.int4 = Constants.INTS_T1[self.round_number - 1][3] self.player.int5 = Constants.INTS_T1[self.round_number - 1][4] self.player.solution = self.player.int1 + self.player.int2 + self.player.int3 + self.player.int4 + self.player.int5 # current number of correctly done tasks total_payoff = 0 for p in self.player.in_all_rounds(): if p.payoff_score != None: total_payoff += p.payoff_score # set up messgaes in transcription task if self.round_number == 1: #on very first task correct_last_round = "
" else: #all subsequent tasks if self.player.in_previous_rounds()[-1].is_correct: correct_last_round = "Your last sum was correct" else: correct_last_round = "Your last sum was incorrect" return { 'total_payoff': round(total_payoff), 'round_count':(self.round_number - 1), 'debug': settings.DEBUG, 'correct_last_round': correct_last_round, } def before_next_page(self): 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 for p in self.player.in_all_rounds(): if p.payoff_score != None: total_payoff += p.payoff_score self.participant.vars['task_1_score'] = total_payoff # only keep obs if YourEntry player_sum, is not None. table_rows = [] for prev_player in self.player.in_all_rounds(): if (prev_player.user_total != None): if (prev_player.user_total > 0): row = { 'round_number': prev_player.round_number, 'int1': prev_player.int1, 'int2': prev_player.int2, 'int3': prev_player.int3, 'int4': prev_player.int4, 'int5': prev_player.int5, 'Ints_sum': prev_player.solution, 'player_sum': round(prev_player.user_total), 'is_correct':prev_player.is_correct, 'payoff': round(prev_player.payoff_score), } table_rows.append(row) self.participant.vars['t1_results'] = table_rows return { 'table_rows': table_rows, 'total_payoff':round(total_payoff), } # def before_next_page(self): # self.participant.vars['start_time'] = None page_sequence = [ start, task, ResultsWaitPage # Results ]