from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants class CreatingGroups(WaitPage): group_by_arrival_time = True template_name = 'Treatment2/CreatingGroups.html' #def is_displayed(self): #return self.round_number==1 #body_text='Creating Groups' #class CreatingGroups2(WaitPage): #body_text='Creating Groups' #def is_displayed(self): #return self.round_number>1 class Start(Page): form_model = 'player' def is_displayed(self): return self.round_number == 1 def before_next_page(self): import time # user has 10 minutes to complete as many pages as possible self.participant.vars['expiry'] = time.time() + 8*60 class Introduction(Page): form_model = 'player' timer_text = "'Time left to read this instruction:" def is_displayed(self): return self.round_number==1 def get_timeout_seconds(self): import time return self.participant.vars['expiry'] - time.time() class T2instructions(Page): form_model = 'player' def is_displayed(self): return self.round_number==1 def get_timeout_seconds(self): import time return self.participant.vars['expiry'] - time.time() class PaymentInfo(Page): form_model = 'player' def is_displayed(self): return self.round_number==1 def get_timeout_seconds(self): import time return self.participant.vars['expiry'] - time.time() class ContributeP1(Page): form_model = 'player' form_fields = ['contribution'] timeout_seconds = 60 def is_displayed(self): return self.player.id_in_group==1 def vars_for_template(self): return dict(round_number=self.round_number) class MyWaitPage23456(WaitPage): body_text = 'Waiting for the player before you to make a decision' def is_displayed(self): return self.player.id_in_group > 1 class ContributeP2(Page): form_model = 'player' form_fields = ['contribution'] timeout_seconds = 60 def is_displayed(self): return self.player.id_in_group == 2 def vars_for_template(self): return dict(round_number=self.round_number, tc2=self.group.position1().contribution) class MyWaitPage3456(WaitPage): body_text = 'Waiting for the player before you to make a decision' def is_displayed(self): return self.player.id_in_group > 2 class ContributeP3(Page): form_model = 'player' form_fields = ['contribution'] timeout_seconds = 60 def is_displayed(self): return self.player.id_in_group==3 def vars_for_template(self): return dict(round_number=self.round_number,tc3=self.group.position1().contribution+self.group.position2().contribution) class MyWaitPage456(WaitPage): body_text = 'Waiting for the player before you to make a decision' def is_displayed(self): return self.player.id_in_group > 3 class ContributeP4(Page): form_model = 'player' form_fields = ['contribution'] timeout_seconds = 60 def is_displayed(self): return self.player.id_in_group==4 def vars_for_template(self): return dict(round_number=self.round_number,tc4= self.group.position3().contribution+self.group.position2().contribution) class MyWaitPage56(WaitPage): body_text = 'Waiting for the player before you to make a decision' def is_displayed(self): return self.player.id_in_group > 4 class ContributeP5(Page): form_model = 'player' form_fields = ['contribution'] timeout_seconds = 60 def is_displayed(self): return self.player.id_in_group==5 def vars_for_template(self): return dict(round_number=self.round_number,tc5=self.group.position4().contribution+self.group.position3().contribution) class MyWaitPage6(WaitPage): body_text = 'Waiting for the player before you to make a decision' def is_displayed(self): return self.player.id_in_group > 5 class ContributeP6(Page): form_model = 'player' form_fields = ['contribution'] timeout_seconds = 60 def is_displayed(self): return self.player.id_in_group==6 def vars_for_template(self): return dict(round_number=self.round_number, tc6=self.group.position5().contribution+self.group.position4().contribution) class ResultsWaitPage(WaitPage): after_all_players_arrive = 'set_payoffs' body_text = 'Waiting for other participants to contribute.' class Results(Page): form_model = 'player' timeout_seconds = 80 def vars_for_template(self): return dict(total_earnings=self.group.total_contribution * Constants.multiplier, round_number=self.round_number) class FinalResults(Page): form_model = 'player' def is_displayed(self): return self.round_number==Constants.num_rounds def vars_for_template(self): player_in_all_rounds = self.player.in_all_rounds() return dict(your_payoff=self.participant.payoff_plus_participation_fee(), total_payoff=sum([p.payoff for p in player_in_all_rounds]), paying_round=self.session.vars['paying_round']) page_sequence = [CreatingGroups, Start, Introduction, T2instructions, PaymentInfo, ContributeP1, MyWaitPage23456, ContributeP2, MyWaitPage3456, ContributeP3, MyWaitPage456, ContributeP4, MyWaitPage56, ContributeP5, MyWaitPage6, ContributeP6, ResultsWaitPage, Results, FinalResults]