from ._builtin import Page, WaitPage from .models import Constants class ArrivalWaitPage(WaitPage): body_text = "Bitte warten Sie auf die anderen Teilnehmer." wait_for_all_groups = True def after_all_players_arrive(self): # Separate active from inactive players and assign treatments self.subsession.initialize_treatments() def is_displayed(self) -> bool: # Don't change groups or treatments in other rounds return self.round_number == 1 class StartPage(Page): def is_displayed(self) -> bool: return self.round_number == 1 and self.participant.vars['status'] == 1 def vars_for_template(self) -> dict: return { "nr_rounds": "vier" } class ChoiceWaitPage(WaitPage): body_text = "Bitte warten Sie auf die anderen Teilnehmer." def is_displayed(self) -> bool: return self.participant.vars['status'] == 1 class Choice(Page): form_model = 'player' form_fields = ['choice', 'clicks'] def before_next_page(self): # Store choice for payoff calculation if self.round_number == 1: self.participant.vars['choices'] = dict() self.participant.vars['choices'][self.round_number] = self.player.choice if self.round_number == Constants.num_rounds: self.player.set_payoff() def is_displayed(self) -> bool: return self.participant.vars['status'] == 1 def vars_for_template(self) -> dict: return { 'weekday': Constants.weekdays[self.round_number % 7], 'img_path': self.session.vars['trip_pics'][str(self.round_number)][str(self.player.side)][ "full" if self.player.info_level else "lim"], 'you': { 'budget': self.player.budget, 'indiv': {'cost': self.player.indiv_cost, 'time': self.player.indiv_time}, 'shared': {'cost': self.player.shared_cost, 'time': self.player.shared_time}, 'diff': {'cost': self.player.diff_cost, 'time': self.player.diff_time}, }, 'stranger': { 'indiv': {'cost': self.player.other_indiv_cost, 'time': self.player.other_indiv_time}, 'shared': {'cost': self.player.other_shared_cost, 'time': self.player.other_shared_time}, 'diff': {'cost': self.player.other_diff_cost, 'time': self.player.other_diff_time}, }, } page_sequence = [ ArrivalWaitPage, StartPage, Choice, ChoiceWaitPage, ]