from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants class RoundWaitPage(WaitPage): template_name = 'BaNu_n/RoundWaitPage.html' group_by_arrival_time = True def is_displayed(self): return self.player.active def vars_for_template(self): return dict( arrival = int(self.participant.vars['wait_page_arrival']*1000) ) class Instruction(Page): def is_displayed(self): return self.player.active timeout_seconds = 10 timer_text = 'Time left before negotiation starts:' def vars_for_template(self): matching_group = self.group.get_player_by_id(1).matching_group return dict( endowB=Constants.endowmentsB[matching_group - 1][self.round_number - 1], endowA=Constants.endowmentsA[matching_group - 1][self.round_number - 1], ) def before_next_page(self): matching_group = self.group.get_player_by_id(1).matching_group self.group.endowA = Constants.endowmentsA[matching_group - 1][self.round_number-1] self.group.endowB = Constants.endowmentsB[matching_group - 1][self.round_number-1] class MyWaitPage(WaitPage): title_text = "Please wait for the other person." body_text = "Once you have both seen the disagreement payoffs, negotiation will start." def is_displayed(self): return self.player.active after_all_players_arrive = 'set_time' class Slider(Page): timeout_seconds = 63 def is_displayed(self): return self.player.active def before_next_page(self): if self.timeout_happened: self.group.failed = True class Nuclear(Page): form_model = 'group' form_fields = ['nuclear'] def is_displayed(self): return self.player.active and (self.player.role() == 'B' and self.group.failed) timeout_seconds = 33 def vars_for_template(self): return dict( offerA = 100 - self.group.currentA, offerB = 100- self.group.currentB, arrival=int(self.group.arrival), ) def before_next_page(self): self.group.set_payoffs() import time self.participant.vars['wait_page_arrival'] = time.time() if self.timeout_happened: self.participant.vars['active'] = False self.participant.vars['drop_out'] = True class RoundEnd(Page): def is_displayed(self): return self.player.active and (not self.group.failed or self.player.role() == 'A') timeout_seconds = 33 def vars_for_template(self): return dict( payoffB = 100 - self.group.final_offer, arrival=int(self.group.arrival), ) def before_next_page(self): self.group.set_payoffs() import time self.participant.vars['wait_page_arrival'] = time.time() if self.timeout_happened: self.participant.vars['active'] = False self.participant.vars['drop_out'] = True def app_after_this_page(self, upcoming_apps): if self.round_number == Constants.num_rounds: return "BaNu_questionnaire" class Out(Page): def is_displayed(self): return self.round_number == Constants.num_rounds and not self.player.active and not self.player.participant.vars['first_out'] page_sequence = [ #MatchingWaitPage, RoundWaitPage, Instruction, MyWaitPage, Slider, Nuclear, RoundEnd, Out, ]