from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants from otree.api import Currency as c, currency_range from ._builtin import Page from .models import Constants import datetime, json, time import random import math import numpy as np def paying_round(): #choice3 = 5 choice3 = random.randint(1, 5) return choice3 class introduction_adding_numbers(Page): form_model = 'player' def is_displayed(self): return self.round_number == 1 def vars_for_template(self): if self.round_number == 1: self.player.paying_round = paying_round() self.participant.vars['paying_round'] = self.player.paying_round return dict( paying_round=self.participant.vars['paying_round'], ) def js_vars(self): return { 'paying_round': self.participant.vars['paying_round'], } class disclaimer(Page): form_model = 'player' def is_displayed(self): return self.round_number == 1 class pre_questionnaire(Page): form_model = 'player' def is_displayed(self): return self.round_number == 1 class questionnaire1(Page): form_model = 'player' form_fields = ['h1', 'h2', 'h3', 'h4', 'h5', 'h17'] def is_displayed(self): return self.round_number == 1 class questionnaire2(Page): form_model = 'player' form_fields = ['h6', 'h7', 'h8', 'h9', 'h10', 'h16'] def is_displayed(self): return self.round_number == 1 class questionnaire3(Page): form_model = 'player' form_fields = ['h11', 'h12', 'h13', 'h14', 'h15', 'h18', 'h19'] def is_displayed(self): return self.round_number == 1 class general_instructions(Page): form_model = 'player' def is_displayed(self): return self.round_number == 1 class instructions_earnings1(Page): form_model = 'player' def is_displayed(self): return self.round_number == 3 class instructions_earnings2(Page): form_model = 'player' def is_displayed(self): return self.round_number == 3 practice = [ #[91, 75, 69, 44, 64, 16, 35, 62, 33, 49], [94, 31, 56, 71, 72, 62, 16, 42, 63, 39], [79, 44, 12, 34, 21, 52, 13, 27, 57, 68], [88, 19, 22, 55, 35, 24, 23, 64, 76, 49] ] class practice_game(Page): form_model = 'player' form_fields = ['correct'] timeout_seconds = 300 def vars_for_template(self): if self.round_number == 1: self.participant.vars['set'] = practice self.participant.vars['roundnumber'] = 1 if self.round_number == 2: self.participant.vars['set'] = practice self.participant.vars['roundnumber'] = 2 if self.round_number == 3: self.participant.vars['set'] = practice self.participant.vars['roundnumber'] = 3 if self.round_number == 1: return dict( n=[self.participant.vars['set'][0][h] for h in range(0, 10)], roundnumber=self.participant.vars['roundnumber'], ) if self.round_number == 2: return dict( n=[self.participant.vars['set'][1][h] for h in range(0, 10)], roundnumber=self.participant.vars['roundnumber'], ) if self.round_number == 3: return dict( n=[self.participant.vars['set'][2][h] for h in range(0, 10)], roundnumber=self.participant.vars['roundnumber'], ) def js_vars(self): if self.round_number == 1: return { 'n': [self.participant.vars['set'][0][h] for h in range(0, 10)], } if self.round_number == 2: return { 'n': [self.participant.vars['set'][1][h] for h in range(0, 10)], } if self.round_number == 3: return { 'n': [self.participant.vars['set'][2][h] for h in range(0, 10)], } class results(Page): form_model = 'player' form_fields = ['paying_round'] def vars_for_template(self): return dict( paying_round=self.participant.vars['paying_round'], roundnumber=self.participant.vars['roundnumber'], ) def js_vars(self): return { 'paying_round': self.participant.vars['paying_round'], 'roundnumber': self.participant.vars['roundnumber'], } class finish_practice(Page): form_model = 'player' def is_displayed(self): return self.round_number == 3 class bank_account(Page): form_model = 'player' form_fields = ['bank_account'] def is_displayed(self): return self.round_number == 3 page_sequence = [introduction_adding_numbers, disclaimer, pre_questionnaire, questionnaire1, questionnaire2, questionnaire3, general_instructions, practice_game, results, finish_practice, bank_account, instructions_earnings1, ]