from ._builtin import Page, WaitPage from otree.api import Currency as c, currency_range from .models import Constants class Introduction(Page): def is_displayed(self): return self.round_number == 1 timeout_seconds = 600 def before_next_page(self): if self.timeout_happened: self.player.skip = True class Instruction(Page): def is_displayed(self): return self.round_number == 1 form_model = 'player' form_fields = ['quiz1'] timeout_seconds = 600 def before_next_page(self): if self.timeout_happened: self.player.skip = True class ParticipantsWaitPage(WaitPage): wait_for_all_groups = True body_text = "全プレイヤーが集まるまでしばらくお待ちください。" class Game_contribute_P1(Page): def is_displayed(self): return self.player.id_in_group == 1 def vars_for_template(self): return dict( round_number=self.round_number ) form_model = 'group' form_fields = ['contribution1'] timeout_seconds = 20 def before_next_page(self): if self.timeout_happened: self.player.skip = True if self.round_number == 1: self.group.contribution1 = Constants.endowment_1 / 2 else: self.group.contribution1 = self.subsession.in_round(self.round_number - 1).contribution1_average_history class Game_contribute_P2(Page): def is_displayed(self): return self.player.id_in_group == 2 def vars_for_template(self): return dict( round_number=self.round_number ) form_model = 'group' form_fields = ['contribution2'] timeout_seconds = 20 def before_next_page(self): if self.timeout_happened: self.player.skip = True if self.round_number == 1: self.group.contribution2 = Constants.endowment_2 / 2 else: self.group.contribution2 = self.subsession.in_round(self.round_number - 1).contribution2_average_history class ResultsWaitPage(WaitPage): wait_for_all_groups = True def after_all_players_arrive(self): for g in self.subsession.get_groups(): g.set_payoffs() body_text = "相手の参加者が投資額を決定中です。" class Results(Page): def vars_for_template(self): me = self.player me.totalpayoff = sum([me.payoff for me in me.in_all_rounds()]) group = self.group return dict( round_number=self.round_number, payoff1=(Constants.endowment_1 - group.contribution1) + group.individual_share, payoff2=(Constants.endowment_2 - group.contribution2) + group.individual_share ) timeout_seconds = 60 def before_next_page(self): if self.timeout_happened: self.player.skip = True def before_next_page(self): self.subsession.contributions_average() class Pose(Page): def is_displayed(self): return self.round_number != 3 timeout_seconds = 10 class End(Page): def is_displayed(self): return self.round_number == 3 def vars_for_template(self): me = self.player me.totalpayoff = sum([me.payoff for me in me.in_all_rounds()]) return dict( totalpayoff=me.totalpayoff, money=me.totalpayoff * 4 ) timeout_seconds = 600 def before_next_page(self): if self.timeout_happened: self.player.skip = True page_sequence = [ Introduction, ParticipantsWaitPage, Game_contribute_P1, Game_contribute_P2, ResultsWaitPage, Results, Pose, End ]