from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants import random class Introduction(Page): def is_displayed(self): return self.round_number == 1 class Instructions(Page): def is_displayed(self): return self.round_number == 1 class Question(Page): timeout_seconds = 30 form_model = 'player' form_fields = ['submitted_answer'] def submitted_answer_choices(self): qd = self.player.current_question() return [ qd['choice1'], qd['choice2'], qd['choice3'], qd['choice4'], ] def before_next_page(self): self.player.check_correct() class BeliefsPrior(Page): form_model = 'player' form_fields = ['num_guess', 'prob_guess'] def is_displayed(self): return self.round_number == Constants.num_rounds def before_next_page(self): self.player.get_random_questions() class Request(Page): form_model = 'player' form_fields = [ 's0', 's1', 's2', 's3', 's4', 's5', 's6', 's7', 's8', 's9', 's10', ] 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() # rand1, rand2 = self.player.get_random_questions() # print('rand1', rand1) # print('rand2', rand2) # p1 = self.player.in_round(rand1) # p1.orig_grading = bool(random.getrandbits(1)) # p1.fn_grading = p1.orig_grading # print('p1', p1) # print('p1 is correct', p1.is_correct) # print('p1_orig_grading', p1.orig_grading) # p2 = self.player.in_round(rand2) # p2.orig_grading = bool(random.getrandbits(2)) # p2.fn_grading = p2.orig_grading # print('p2', p2) # print('p2 is correct', p2.is_correct) # print('p2_orig_grading', p2.orig_grading) return { # 'player_in_all_rounds': player_in_all_rounds, # 'questions_correct': sum([p.is_correct for p in player_in_all_rounds]), 'orig_correct': sum([p.orig_grading for p in player_in_all_rounds]), } def before_next_page(self): self.player.get_random_scenario() class Results(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() print('s0', self.player.s0) print('s1', self.player.s1) print('s2', self.player.s2) print('s3', self.player.s3) print('s4', self.player.s4) print('s5', self.player.s5) print('s6', self.player.s6) print('s7', self.player.s7) print('s8', self.player.s8) print('s9', self.player.s9) print('s10', self.player.s10) return { 'player_in_all_rounds': player_in_all_rounds, 'questions_correct': sum([p.is_correct for p in player_in_all_rounds]), 'orig_correct': sum([p.orig_grading for p in player_in_all_rounds]), 'fn_correct': sum([p.fn_grading for p in player_in_all_rounds]), 'exp_payoff': self.player.exp_payoff } class Lottery(Page): def is_displayed(self): return self.round_number == Constants.num_rounds form_model = 'player' form_fields = ['lottery_choice'] def before_next_page(self): self.player.get_lottery() self.player.set_payoff() class FnResults(Page): def is_displayed(self): return self.round_number == Constants.num_rounds def vars_for_template(self): return { 'exp_payoff': self.player.exp_payoff, 'lottery_bonus': self.player.lottery_bonus, 'total_payoff': self.player.total_payoff } page_sequence = [ Introduction, Instructions, Question, BeliefsPrior, # BeliefsPosterior, Request, Results, Lottery, FnResults ]