from ._builtin import Page from .models import Constants class LandingPage(Page): pass class ClientInput(Page): form_model = 'player' form_fields = ['client_number'] def before_next_page(self): self.participant.label = f'Client {self.player.client_number}' if self.player.client_number == -999: self.participant.vars['status'] = 0 else: self.participant.vars['status'] = 1 cfg = self.session.config if cfg['nr_full_info'] > 0: self.participant.vars['full_info'] = True cfg['nr_full_info'] -= 1 else: self.participant.vars['full_info'] = False class Instructions(Page): def is_displayed(self) -> bool: return self.participant.vars['status'] == 1 class QuizQuestion1(Page): form_model = 'player' form_fields = ['q_indiv', 'q_time_diff', 'legend_clicks_1'] def is_displayed(self) -> bool: return self.participant.vars['status'] == 1 def vars_for_template(self) -> dict: return { 'img_path': self.session.vars['trip_pics']['ex']['1'], 'you': { 'budget': 5, 'indiv': {'cost': 3, 'time': 6}, 'shared': {'cost': 2.5, 'time': 20}, 'diff': {'cost': 0.5, 'time': 14}, }, 'stranger': { 'indiv': {'cost': 10.5, 'time': 11}, 'shared': {'cost': 9, 'time': 13}, 'diff': {'cost': 1.5, 'time': 2}, }, } def before_next_page(self): self.player.info_level = True def error_message(self, values): correct = True if values['q_indiv'] != Constants.correct_answer: self.player.q_indiv_fails += 1 correct = False if values['q_time_diff'] != (Constants.correct_answer + self.player.info_level): self.player.q_time_diff_fails += 1 correct = False if not correct: self.player.attempts -= 1 if self.player.attempts > 0: return "error" else: self.participant.vars['status'] = -1 self.participant.payoff = 4 else: self.player.attempts = 2 class QuizQuestion2(Page): form_model = 'player' form_fields = ['q_shared', 'q_cost_diff', 'legend_clicks_2'] def is_displayed(self) -> bool: return self.participant.vars['status'] == 1 def vars_for_template(self) -> dict: return { 'img_path': self.session.vars['trip_pics']['ex']['2'], 'you': { 'budget': 25, 'indiv': {'cost': 10, 'time': 4}, 'shared': {'cost': 5, 'time': 7}, 'diff': {'cost': 5, 'time': 3}, }, 'stranger': { 'indiv': {'cost': 12, 'time': 5}, 'shared': {'cost': 6, 'time': 8}, 'diff': {'cost': 6, 'time': 3}, } } def error_message(self, values): correct = True if values['q_shared'] != Constants.correct_answer: self.player.q_shared_fails += 1 correct = False if values['q_cost_diff'] != (Constants.correct_answer + self.player.info_level): self.player.q_cost_diff_fails += 1 correct = False if not correct: self.player.attempts -= 1 if self.player.attempts > 0: return "error" else: self.participant.vars['status'] = -1 self.participant.payoff = 4 else: self.player.attempts = 2 page_sequence = [ LandingPage, ClientInput, Instructions, QuizQuestion1, QuizQuestion2, ]