from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants class Give_Mem(Page): timeout_seconds = 5 def is_displayed(self): return self.subsession.round_number != Constants.num_rounds def vars_for_template(self): mem_num = self.session.vars['high_draws'][self.subsession.round_number - 1] return dict( mem_num=mem_num ) def before_next_page(self): self.player.set_income() class Cons(Page): form_model = 'player' form_fields = [ 'consumption' ] def vars_for_template(self): period = self.subsession.round_number total_periods = Constants.num_rounds income = self.player.income savings = self.player.get_total_savings() return dict( period=period, total_periods=total_periods, income=income, savings=savings ) def is_displayed(self): return self.subsession.round_number != Constants.num_rounds def before_next_page(self): if self.subsession.round_number != Constants.num_rounds: self.player.utility_calc() self.player.savings_calc() self.player.update_savings() else: self.player.last_period_calcs() timeout_seconds = 30 class Blank_Page(Page): def is_displayed(self): return self.subsession.round_number == Constants.num_rounds def before_next_page(self): if self.subsession.round_number == Constants.num_rounds: self.player.set_income() self.player.last_period_calcs() self.player.mem_frac_correct() self.player.frac_utility() self.player.update_utility() timeout_seconds = 30 class Get_Mem(Page): timeout_seconds = 10 def is_displayed(self): return self.subsession.round_number != Constants.num_rounds form_model = 'player' form_fields = [ 'high_memorization_number' ] def before_next_page(self): if self.subsession.round_number != Constants.num_rounds: self.player.mem_frac_correct() self.player.frac_utility() self.player.update_utility() class NewPeriod(Page): timeout_seconds = 5 class Intro(Page): def is_displayed(self): return self.subsession.round_number == 1 timeout_seconds = 5 class Results(Page): def vars_for_template(self): income = self.player.income period = self.subsession.round_number comp_mem_num = self.session.vars['high_draws'][self.subsession.round_number - 1] your_mem_num = self.player.high_memorization_number your_mem_correct = self.player.mem_num_correct possible_correct = 2 consumption = self.player.consumption utility = self.player.temp_utility frac_utility = self.player.current_utility savings = self.player.current_savings total_savings = self.player.total_savings total_utility = self.player.total_utility return dict( period=period, income=income, comp_mem_num=comp_mem_num, your_mem_num=your_mem_num, your_mem_correct=your_mem_correct, possible_correct=possible_correct, consumption=consumption, utility=utility, frac_utility=frac_utility, savings=savings, total_savings=total_savings, total_utility=total_utility ) def before_next_page(self): if self.subsession.round_number == Constants.num_rounds: self.participant.vars['payoff_2'] = self.player.total_utility timeout_seconds = 5 class Task_Results(Page): timeout_seconds = 5 def is_displayed(self): return self.subsession.round_number == Constants.num_rounds def vars_for_template(self): task_points = self.participant.vars['payoff_2'] return dict( task_points=task_points ) page_sequence = [Intro, NewPeriod, Give_Mem, Cons, Blank_Page, Get_Mem, Results, Task_Results]