from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants from random import random class Introduction(Page): def is_displayed(self): return self.round_number == 1 after_all_players_arrive = 'role' def before_next_page(self): self.player.individual_cost = round(random() * Constants.Cost_Constant) class IntroductionWaitPage(WaitPage): wait_for_all_groups = True class AdditionalRounds(Page): timeout_seconds = 30 def is_displayed(self): return self.round_number != 1 def before_next_page(self): self.player.individual_cost = round(random() * Constants.Cost_Constant) class AdditionalWaitPage(WaitPage): wait_for_all_groups = True class Participation(Page): timeout_seconds = 90 form_model = 'player' form_fields = ['participate'] class Vote(Page): timeout_seconds = 120 form_model = 'player' form_fields = ['vote'] def is_displayed(self): return self.player.participate == 1 class ResultsWaitPage(WaitPage): after_all_players_arrive = 'voting_outcome' class PayoffWaitPage(WaitPage): after_all_players_arrive = 'calculate_payoff' class Results(Page): timeout_seconds = 60 class History(Page): timeout_seconds = 60 def vars_for_template(self): return dict( player_in_all_rounds_rev=reversed(self.player.in_all_rounds()) ) def before_next_page(self): self.player.round_select = round(random() * 9) + 1 self.player.payoff_select = self.player.in_round(self.player.round_select).payoff self.participant.payoff = self.player.payoff_select self.player.dollar_select = int(self.participant.payoff_plus_participation_fee() - 7) class HistoryWaitPage(WaitPage): wait_for_all_groups = True class PayoffScreen(Page): timeout_seconds = 300 def vars_for_template(self): return dict( player_in_all_rounds_rev=reversed(self.player.in_all_rounds()) ) def is_displayed(self): return self.round_number == 10 def before_next_page(self): self.participant.vars['PluralPayoff'] = self.player.dollar_select page_sequence = [Introduction, IntroductionWaitPage, AdditionalRounds, AdditionalWaitPage, Participation, Vote, ResultsWaitPage, PayoffWaitPage, Results, History, HistoryWaitPage, PayoffScreen]