from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants #class Welcome(Page): #def is_displayed(self): #return self.round_number == 1 #class StartWaitPage(WaitPage): #def is_displayed(self): #return not self.player.participant.vars['agreed'] class Start(Page): def is_displayed(self): return self.round_number == 1 form_model = 'player' form_fields = ['password'] class CommWaitPage(WaitPage): def is_displayed(self): return not self.player.participant.vars['agreed'] class Countdown(Page): timeout_seconds = 10 timer_text = 'Time left until communication stage:' def is_displayed(self): return not self.player.participant.vars['agreed'] class Offers(Page): def is_displayed(self): return not self.player.participant.vars['agreed'] timeout_seconds = 240 timer_text = 'Time left to make offers:' def vars_for_template(self): if self.player.id_in_group == 1: one = True else: one = False if self.player.id_in_group == 2: two = True else: two = False if self.player.id_in_group == 3: three = True else: three = False if self.player.id_in_group == 4: four = True else: four = False pie = Constants.pie[self.round_number - 1] return dict( one=one, two=two, three=three, four=four, pie=pie, ) def js_vars(self): pie = Constants.pie[self.round_number-1] return dict( player_id=self.player.id_in_group, pie=pie, ) live_method = 'live_offers' class MidWaitPage(WaitPage): def is_displayed(self): return not self.player.participant.vars['agreed'] after_all_players_arrive = 'set_agreement' class End(Page): def is_displayed(self): return not self.player.participant.vars['agreed'] def vars_for_template(self): pie = Constants.pie[self.round_number] if self.player.id_in_group == 1: one = True else: one = False if self.player.id_in_group == 2: two = True else: two = False if self.player.id_in_group == 3: three = True else: three = False if self.player.id_in_group == 4: four = True else: four = False return dict( one=one, two=two, three=three, four=four, payoff1=self.group.get_player_by_id(1).final_share, payoff2=self.group.get_player_by_id(2).final_share, payoff3=self.group.get_player_by_id(3).final_share, pie=pie ) def before_next_page(self): if self.group.agreement: self.player.participant.vars['agreed'] = True self.player.payoff = self.player.final_share else: self.player.payoff = 0 class Return(Page): def is_displayed(self): return self.round_number == Constants.num_rounds def vars_for_template(self): total_payoff = sum(p.payoff for p in self.player.in_all_rounds()) showup = Constants.participation_fee self.player.participant.vars['from_1'] = total_payoff+showup return dict( earning=total_payoff+showup ) page_sequence = [Start, CommWaitPage, Countdown, Offers, MidWaitPage, End, Return]