from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants ### - 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() #self.subsession.load_new_questions() def vars_for_template(self): import json if self.player.qtype2 == 2 and self.player.qsubtype2 == 2: this_quest = json.loads(self.player.question2) else: this_quest = None if self.participant.vars['myRole'] == 1: return dict( qtype = self.player.qtype1, subtype = self.player.qsubtype1, player_role = self.participant.vars['myRole'], my_id= self.participant.vars['this_uid'], my_score=self.participant.vars['score'], megaRound=self.session.vars['megaRound'], this_question = this_quest ) elif self.participant.vars['myRole'] == 2: return dict( qtype = self.player.qtype2, subtype = self.player.qsubtype2, player_role = self.participant.vars['myRole'], my_id=self.participant.vars['this_uid'], my_score=self.participant.vars['score'], megaRound=self.session.vars['megaRound'], this_question = this_quest ) class PostQuizWaitPage(WaitPage): def after_all_players_arrive(self): self.subsession.production_function() #THIS IS THE END OF THE MEGA ROUND! self.session.vars['app2_initialised'] = False self.session.vars['app3_initialised'] = False self.subsession.migrate_to_session() self.subsession.back_up() def is_displayed(self): return self.round_number == Constants.num_rounds class VerbQuizResults(Page): def is_displayed(self): return self.round_number == Constants.num_rounds def vars_for_template(self): # player_in_all_rounds = self.player.in_all_rounds() new_score = self.player.update_score() player_matched = None if self.player.matchedPlayer == -1: player_matched = 0 elif self.player.matchedPlayer != -1: player_matched = 1 mypf = str( int( round(self.player.performance * 100, 0 ) ) ) + "%" if player_matched == 1: otpf = str( int( round(self.player.partner_performance * 100, 0 ) ) ) + "%" else: otpf = 1 return dict( is_matched=player_matched, my_performance=mypf, partner_performance = otpf, production=self.player.production, debt_repayment = int(self.player.debt_repayment), my_profit = int(self.player.revenue), my_id=self.player.uid, my_score= int( self.participant.vars['score'] ), megaRound=self.session.vars['megaRound'], this_B = self.session.vars['B'] #player_in_all_rounds=player_in_all_rounds, #questions_correct=sum([p.is_correct for p in player_in_all_rounds]), ) class PeriodPrimingPage(Page): def is_displayed(self): return self.round_number == Constants.num_rounds def vars_for_template(self): # player_in_all_rounds = self.player.in_all_rounds() prime_list = [] for p in self.subsession.get_players(): if p.uid == self.player.uid: continue player_matched = None if p.matchedPlayer == -1: player_matched = 0 elif p.matchedPlayer != -1: player_matched = 1 prime_list.append([p.uid, player_matched, int(p.revenue) ]) return dict( prime_list = prime_list, my_id=self.player.uid, my_score=self.participant.vars['score'], megaRound=self.session.vars['megaRound'] #player_in_all_rounds=player_in_all_rounds, #questions_correct=sum([p.is_correct for p in player_in_all_rounds]), ) def before_next_page(self): pass class EmptyPage(Page): def before_next_page(self): self.subsession.load_new_questions() def is_displayed(self): return self.round_number != 1 def vars_for_template(self): return None class App3LandingPage(Page): def before_next_page(self): self.subsession.on_app_start() self.subsession.load_new_questions() def is_displayed(self): return self.round_number == 1 def vars_for_template(self): return dict( my_id=self.player.uid, my_score=self.participant.vars['score'], megaRound=self.session.vars['megaRound'] ) page_sequence = [ App3LandingPage, EmptyPage, VerbQuizPage, PostQuizWaitPage, VerbQuizResults, PeriodPrimingPage ]