from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants class WelcomePage0(Page): def is_displayed(self): return self.round_number == 1 def vars_for_template(self): return dict( this_treatment = Constants.treatment, this_test = Constants.test_round, ) class WelcomePage1(Page): def is_displayed(self): return self.round_number == 1 def vars_for_template(self): return dict( this_treatment = Constants.treatment, this_test = Constants.test_round, this_D = Constants.D, this_r = Constants.r * 100, this_s = Constants.s * 100, this_B = Constants.B, this_tsd = int(Constants.points_conversion_rate * 1000) ) class ResultsWaitPage(WaitPage): def after_all_players_arrive(self): pass class ParticipantQuiz(Page): form_model = 'player' form_fields = ['part_code', 'part_age', 'part_gender','part_income', 'part_occup', 'part_share_free', 'part_jobs_attempt', 'part_jobs_complete'] def is_displayed(self): # Don't show while testing return self.round_number == 1 and Constants.test_round != 1 def vars_for_template(self): return dict( qtype = self.player.qtype ) def before_next_page(self): self.subsession.migrate_participant() class RiskElicitPage(Page): form_model = 'player' form_fields = ['part_risk_quest'] def is_displayed(self): # Don't show while testing return self.round_number == 1 and Constants.test_round != 1 def vars_for_template(self): return dict( this_endowment = Constants.start_endowment ) def before_next_page(self): self.player.calculate_endowment() class RiskResultPage(Page): def is_displayed(self): # Don't show while testing return self.round_number == 1 and Constants.test_round != 1 def vars_for_template(self): return dict( endow_result = self.player.actual_endowment ) class PreAssessPage(Page): def is_displayed(self): return self.round_number == 1 def vars_for_template(self): return dict( qtype = self.player.qtype ) ### - Verbal Quiz class VerbQuizPage(Page): # randomize content and order per person in models, # store all structures in template and if between them form_model = 'player' form_fields = ['submitted_answer'] timeout_seconds = 30 def is_displayed(self): return True def before_next_page(self): self.player.check_correct() def vars_for_template(self): import json if self.player.qtype == 2 and self.player.qsubtype == 2: this_quest = json.loads(self.player.question) else: this_quest = None return dict( qtype = self.player.qtype, subtype = self.player.qsubtype, this_question = this_quest ) class VerbQuizResults(Page): def is_displayed(self): return self.round_number == Constants.num_rounds def vars_for_template(self): this_skill1, this_skill2 = self.player.get_ability() player_in_all_rounds = self.player.in_all_rounds() sk1 = str( int( round(this_skill1 * 100, 0 ) ) ) + "%" sk2 = str( int( round(this_skill2 * 100, 0 ) ) ) + "%" return dict( #player_in_all_rounds=player_in_all_rounds, #questions_correct=sum([p.is_correct for p in player_in_all_rounds]) skill1= sk1, skill2=sk2 ) class PostQuizWaitPage(WaitPage): def after_all_players_arrive(self): # since this is the last page of this app, self.subsession.migrate_to_session() self.subsession.back_up() def is_displayed(self): return self.round_number == Constants.num_rounds page_sequence = [ WelcomePage0, WelcomePage1, ParticipantQuiz, RiskElicitPage, RiskResultPage, PreAssessPage, VerbQuizPage, VerbQuizResults, PostQuizWaitPage ]