from main.models import Constants from ._builtin import Page, WaitPage class GroupingPage(WaitPage): #timeout_seconds = 300 # TODO: set maximum wait time for grouping group_by_arrival_time = True body_text = "Waiting for another worker to complete the quiz." def after_all_players_arrive(self): # TODO: possibly not thread-safe self.group.treatment = self.session.vars['next'] self.session.vars['next'] = ((self.session.vars['next'] + 0.5) % 4) + 1# geƤndert self.group.run_first_stage() def is_displayed(self) -> bool: return self.participant.vars['active'] class PeriodOne(Page): timeout_seconds = 60 def before_next_page(self): if self.timeout_happened and not self.session.config['ignore_timeouts']: self.player.timeout() def is_displayed(self) -> bool: return self.group.active class Offer(Page): timeout_seconds = 120 form_model = 'group' form_fields = ['offer'] def is_displayed(self): return self.player.role == Constants.proposer and self.group.active def before_next_page(self): if self.timeout_happened and not self.session.config['ignore_timeouts']: self.player.timeout() class ResponseWaitPage(WaitPage): body_text = "Waiting for the stranger to continue." def is_displayed(self) -> bool: return self.group.active class Response(Page): timeout_seconds = 120 form_model = 'group' form_fields = ['response'] def before_next_page(self): if self.timeout_happened and not self.session.config['ignore_timeouts']: self.player.timeout() def is_displayed(self): return self.player.role == Constants.responder and self.group.active class ResultsWaitPage(WaitPage): body_text = "Waiting for the stranger to continue." def after_all_players_arrive(self): self.group.set_payoffs() def is_displayed(self) -> bool: return self.group.active class PostQuiz(Page): timeout_seconds = 120 form_model = 'player' form_fields = ['q_own_payoff', 'q_stranger_payoff'] def before_next_page(self): if self.timeout_happened and self.session.config['ignore_timeouts']: return self.player.active = all([self.player.__dict__[field] for field in PostQuiz.form_fields]) def is_displayed(self) -> bool: return self.player.active class PostDeadEnd(Page): def is_displayed(self) -> bool: return not self.player.active class FairnessQuestion(Page): form_model = 'player' form_fields = ['fairoffer', 'lowestoffer'] def before_next_page(self): if self.timeout_happened: self.player.timeout() def is_displayed(self) -> bool: return self.player.active class Demographics(Page): form_model = 'player' form_fields = ['gender', 'age','region'] def before_next_page(self): if self.timeout_happened: self.player.timeout() def is_displayed(self) -> bool: return self.player.active class Payment(Page): def is_displayed(self) -> bool: return self.player.active class Timeout(Page): def is_displayed(self) -> bool: return not self.group.active page_sequence = [ GroupingPage, PeriodOne, Offer, ResponseWaitPage, Response, ResultsWaitPage, Timeout, FairnessQuestion, PostQuiz, PostDeadEnd, Demographics, Payment, ]