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):
def is_displayed(self):
return self.round_number == 1
def before_next_page(self):
self.participant.vars['expiry_timestamp'] = time.time() + self.player.task_timer
def vars_for_template(self):
self.player.task_timer = self.session.config['task_timer']
return {
'debug': settings.DEBUG,
}
class task(Page):
form_model = models.Player
form_fields = ['user_total']
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.task_timer = self.session.config['task_timer']
self.player.additional_tokens = self.session.config['additional_tokens']
self.player.additional_tokens_calculation = self.session.config['additional_tokens_calculation']
self.player.additional_token_reduction = self.session.config['additional_token_reduction']
self.player.int1 = Constants.INTS_T1[self.round_number - 1][0]
self.player.int2 = Constants.INTS_T1[self.round_number - 1][1]
self.player.solution = self.player.int1 + self.player.int2
total_payoff = 0
for p in self.player.in_all_rounds():
if p.payoff_score != None:
total_payoff += p.payoff_score
if self.round_number == 1:
correct_last_round = "
"
else:
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 Results(Page):
form_model = models.Player
form_fields = ['belief']
def is_displayed(self):
return self.round_number == Constants.num_rounds
def vars_for_template(self):
self.player.additional_tokens = self.session.config['additional_tokens']
self.player.additional_tokens_calculation = self.session.config['additional_tokens_calculation']
self.player.additional_token_reduction = self.session.config['additional_token_reduction']
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_A_score'] = total_payoff
return {
'total_payoff' : total_payoff
}
def before_next_page(self):
self.participant.vars['task_A_belief'] = self.player.belief
page_sequence = [
start,
task,
Results
]