from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants import random import time class Pre_1(Page): time_exp = 30 timeout_seconds = time_exp def vars_for_template(self): time = self.time_exp return { 'time': time } def before_next_page(self): if self.timeout_happened: self.participant.vars['drop'] = 1 self.participant.vars['n_drp'] = 2 def app_after_this_page(self, upcoming_apps): if self.timeout_happened: return "return" class Instructions(Page): time_exp = 200 timeout_seconds = time_exp def vars_for_template(self): time = self.time_exp return { 'time': time } def before_next_page(self): if self.timeout_happened: self.participant.vars['drop'] = 1 self.participant.vars['n_drp'] = 3 def app_after_this_page(self, upcoming_apps): if self.timeout_happened: return "return" class Decision(Page): form_model = 'player' form_fields = ['offer'] time_exp = 60 timeout_seconds = time_exp def vars_for_template(self): time = self.time_exp return { 'time': time } def before_next_page(self): self.player.info_value = random.randint(0,100) if self.timeout_happened: self.participant.vars['drop'] = 1 self.participant.vars['n_drp'] = 4 def app_after_this_page(self, upcoming_apps): if self.timeout_happened: return "return" class Results(Page): time_exp = 90 timeout_seconds = time_exp def vars_for_template(self): time = self.time_exp return { 'time': time } def before_next_page(self): self.player.set_payments() self.player.w_audio = random.randint(1 , 2) if self.timeout_happened: self.participant.vars['drop'] = 1 self.participant.vars['n_drp'] = 5 def app_after_this_page(self, upcoming_apps): if self.timeout_happened: return "return" class QuestionnaireA1(Page): form_model = 'player' form_fields = [ 'audio1'] time_exp = 90 timeout_seconds = time_exp def vars_for_template(self): time = self.time_exp return { 'time': time } def before_next_page(self): if self.timeout_happened: self.player.audio1 = random.randint(0,1) self.participant.vars['drop'] = 1 self.participant.vars['n_drp'] = 6 self.participant.vars['category'] = self.player.audio1 def is_displayed(self): return self.player.w_audio == 1 and self.session.config['treatment'] == 'sound' def app_after_this_page(self, upcoming_apps): if self.timeout_happened: return "return" class QuestionnaireA2(Page): form_model = 'player' form_fields = [ 'audio2'] time_exp = 90 timeout_seconds = time_exp def vars_for_template(self): time = self.time_exp return { 'time': time } def before_next_page(self): if self.timeout_happened: self.player.audio2 = random.randint(0,1) self.participant.vars['drop'] = 1 self.participant.vars['n_drp'] = 7 self.participant.vars['category'] = self.player.audio2 def is_displayed(self): return self.player.w_audio == 2 and self.session.config['treatment'] == 'sound' def app_after_this_page(self, upcoming_apps): if self.timeout_happened: return "return" class QuestionnaireP(Page): form_model = 'player' form_fields = [ 'q1' , 'q2', 'q3'] time_exp = 150 timeout_seconds = time_exp def vars_for_template(self): time = self.time_exp return { 'time': time } def before_next_page(self): if self.timeout_happened: self.player.q1 = random.randint(0,1) self.player.q2 = random.randint(0,1) self.player.q3 = 1 self.participant.vars['drop'] = 1 self.participant.vars['n_drp'] = 8 self.participant.vars['category'] = self.player.q3 def is_displayed(self): return self.session.config['treatment'] == 'pol' def app_after_this_page(self, upcoming_apps): if self.timeout_happened: return "return" class Quest_C(Page): form_model = 'player' form_fields = ['check_q'] time_exp = 90 timeout_seconds = time_exp def vars_for_template(self): time = self.time_exp return { 'time': time } def before_next_page(self): if len(self.player.check_q) == 10: self.participant.vars['length'] = 1 print("I did it!") else: self.participant.vars['length'] = 0 print("I didn't work :(") if self.timeout_happened: self.participant.vars['drop'] = 1 self.participant.vars['n_drp'] = 9 def app_after_this_page(self, upcoming_apps): if self.timeout_happened: return "return" class Pre_2(Page): time_exp = 30 timeout_seconds = time_exp def vars_for_template(self): time = self.time_exp return { 'time': time } def before_next_page(self): if self.timeout_happened: self.participant.vars['drop'] = 1 self.participant.vars['n_drp'] = 10 self.participant.vars['wait_page_arrival'] = time.time() def app_after_this_page(self, upcoming_apps): if self.timeout_happened: return "return" page_sequence = [Pre_1, Instructions, Decision, Results, QuestionnaireA1, QuestionnaireA2, QuestionnaireP, Quest_C, Pre_2]