from otree.api import Currency as c, currency_range from otree.api import safe_json from ._builtin import Page, WaitPage from .models import Constants import random as random class Main_Instructions(Page): def is_displayed(self): return self.round_number == 1 form_model = 'player' form_fields = ['Main_Instructions_time_spent','Main_Instructions_warnings','control_q1','control_q2','control_q3'] def js_vars(self): return dict( page_name='Main_Instructions', ) def vars_for_template(self): # conversion = self.session.config['real_world_currency_per_point'] total_pwd = (Constants.pwd_rate * Constants.num_pwd_tasks) pwd_example = 6 pwd_example_earnings = (pwd_example * Constants.pwd_piecerate) math_example = 4 math_example_earnings = (Constants.math_piecerate * math_example) total_example_earnings = math_example_earnings + pwd_example_earnings return dict(total_pwd=total_pwd, pwd_example = pwd_example, pwd_example_earnings = pwd_example_earnings, math_example = math_example, math_example_earnings = math_example_earnings, total_example_earnings = total_example_earnings) def error_message(self,values): """Customized error message for control question 2. The error message is not actually displayed. This function simply validates the form for us. For the actual error message code look at the html code of the page. """ cond_1 = (values['control_q1'] != 30) cond_2 = (values['control_q2'] != 60) cond_3 = (values['control_q3'] != 90) if cond_1: return 'Your input is incorrect! Please read the instructions again.' elif cond_2: return 'Your input is incorrect! Please read the instructions again.' elif cond_3: return 'Your input is incorrect! Please read the instructions again.' class StartRound(Page): # oTree Timer timer_text = 'Time left until the round starts:' timeout_seconds = 5 def vars_for_template(self): return dict(round_num=self.round_number) def js_vars(self): return dict( page_name='StartRound', ) form_model = 'player' form_fields = ['StartRound_warnings'] class MathMemory(Page): # oTree Timer timer_text = 'Time left in this round:' timeout_seconds = Constants.timeout def before_next_page(self): self.player.set_payoff() if self.round_number == Constants.num_rounds: self.player.write_math_time() def vars_for_template(self): p = self.player label = Constants.addition_task[self.round_number-1][0] if p.production_profile == 'Linear': pwd_label = Constants.linear_task[self.round_number-1][0] elif p.production_profile == 'Convex': pwd_label = Constants.convex_task[self.round_number-1][0] filler = ' = ' return dict( math_1_label=label[0]+filler, math_2_label=label[1]+filler, math_3_label=label[2]+filler, math_4_label=label[3]+filler, math_5_label=label[4]+filler, math_6_label=label[5]+filler, math_7_label=label[6]+filler, math_8_label=label[7]+filler, math_9_label=label[8]+filler, math_10_label=label[9]+filler, pwd_1_label=pwd_label[0], pwd_2_label=pwd_label[1], pwd_3_label=pwd_label[2], pwd_4_label=pwd_label[3], pwd_5_label=pwd_label[4], pwd_6_label=pwd_label[5], pwd_7_label=pwd_label[6], pwd_8_label=pwd_label[7], pwd_9_label=pwd_label[8], pwd_10_label=pwd_label[9] ) form_model = 'player' form_fields = [ 'timer_task1', 'new_timer_task1', 'timer_task2', 'new_timer_task2', 'pwd_time', 'total_time', 'prompt_counter', 'switch_counter', 'Task_time_spent', 'Task_warnings', 'math_1', 'math_2', 'math_3', 'math_4', 'math_5', 'math_6', 'math_7', 'math_8', 'math_9', 'math_10', 'math_time', 'math_1_time', 'math_2_time', 'math_3_time', 'math_4_time', 'math_5_time', 'math_6_time', 'math_7_time', 'math_8_time', 'math_9_time', 'math_10_time', 'math_1_tries', 'math_2_tries', 'math_3_tries', 'math_4_tries', 'math_5_tries', 'math_6_tries', 'math_7_tries', 'math_8_tries', 'math_9_tries', 'math_10_tries', 'switch_time_1', 'switch_time_2', 'switch_time_3', 'switch_time_4', 'switch_time_5', 'switch_time_6', 'switch_time_7', 'switch_time_8', 'switch_time_9', 'switch_time_10', 'switch_1_math_perf', 'switch_2_math_perf', 'switch_3_math_perf', 'switch_4_math_perf', 'switch_5_math_perf', 'switch_6_math_perf', 'switch_7_math_perf', 'switch_8_math_perf', 'switch_9_math_perf', 'switch_10_math_perf', 'switch_1_pwd_perf', 'switch_2_pwd_perf', 'switch_3_pwd_perf', 'switch_4_pwd_perf', 'switch_5_pwd_perf', 'switch_6_pwd_perf', 'switch_7_pwd_perf', 'switch_8_pwd_perf', 'switch_9_pwd_perf', 'switch_10_pwd_perf', 'pwd_1', 'pwd_2', 'pwd_3', 'pwd_4', 'pwd_5', 'pwd_6', 'pwd_7', 'pwd_8', 'pwd_9', 'pwd_10', 'pwd_time', 'pwd_1_time', 'pwd_2_time', 'pwd_3_time', 'pwd_4_time', 'pwd_5_time', 'pwd_6_time', 'pwd_7_time', 'pwd_8_time', 'pwd_9_time', 'pwd_10_time', 'pwd_1_tries', 'pwd_2_tries', 'pwd_3_tries', 'pwd_4_tries', 'pwd_5_tries', 'pwd_6_tries', 'pwd_7_tries', 'pwd_8_tries', 'pwd_9_tries', 'pwd_10_tries', 'pwd_1_toggles', 'pwd_2_toggles', 'pwd_3_toggles', 'pwd_4_toggles', 'pwd_5_toggles', 'pwd_6_toggles', 'pwd_7_toggles', 'pwd_8_toggles', 'pwd_9_toggles', 'pwd_10_toggles', ] class A(MathMemory): #def is_displayed(self): # cond1 = (self.player.order_tasks == 'AB') & (self.round_number <= 8) # cond2 = (self.player.order_tasks == 'BA') & (self.round_number > 8) # return (cond1 | cond2) pass def js_vars(self): p = self.player if p.production_profile == 'Linear': pwd_sol = Constants.linear_task[self.round_number-1][0] elif p.production_profile == 'Convex': pwd_sol = Constants.convex_task[self.round_number-1][0] math_sol = Constants.addition_task[self.round_number-1][1] return dict( pwd_solutions_array=pwd_sol, math_solutions_array=math_sol, page_name='Task', num_pwd_tasks=Constants.num_pwd_tasks, num_math_tasks=Constants.num_math_tasks ) class Exit_Q1(Page): def is_displayed(self): return self.round_number == Constants.num_rounds def js_vars(self): return dict( page_name='Exit_Q1', ) form_model = 'player' form_fields = ['Exit_Q1_warnings', 'Exit_Q1_time_spent', 'q_subjective_sophistication_1'] class Exit_Q2(Page): def is_displayed(self): return self.round_number == Constants.num_rounds def js_vars(self): return dict( page_name='Exit_Q2', ) form_model = 'player' form_fields = ['Exit_Q2_warnings', 'Exit_Q2_time_spent', 'q_subjective_optimality_1'] def error_message(self,values): """Customized error message for control question 2. The error message is not actually displayed. This function simply validates the form for us. For the actual error message code look at the html code of the page. """ if values['q_subjective_optimality_1'] == None: return "Please indicate your answer by clicking on the slider." page_sequence = [ Main_Instructions, StartRound, A, Exit_Q1, Exit_Q2 ]