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 import json class Instructions_1(Page): def is_displayed(self): return self.round_number == 1 form_model = 'player' form_fields = ['Instructions_1_warnings', 'Instructions_1_time_spent' ] def js_vars(self): return dict( page_name='Instructions_1') class Instructions_2(Page): def is_displayed(self): return self.round_number == 1 form_model = 'player' form_fields = ['Instructions_2_warnings', 'Instructions_2_time_spent' ] def js_vars(self): return dict( page_name='Instructions_2') class MPL_Instructions(Page): def is_displayed(self): return self.round_number == 1 form_model = 'player' form_fields = [ 'control_q1', 'control_q2', #'control_q3', 'MPL_Instructions_warnings', 'MPL_Instructions_time_spent' ] def js_vars(self): return dict( page_name='MPL_Instructions') 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'] != 0) cond_2 = (values['control_q2'] != 1) #cond_3 = (values['control_q3'] != Constants.no_decisions) 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 MPL_high_Intro(Page): def is_displayed(self): if self.player.MPL_sequence == 'HighLow': in_round = 1 elif self.player.MPL_sequence == 'LowHigh': in_round = 2 return self.round_number == in_round def vars_for_template(self): pwd_piecerate = Constants.pwd_piecerate_high math_piecerate = Constants.math_piecerate_high max_payoff = (pwd_piecerate*Constants.num_pwd_tasks)+(math_piecerate*Constants.num_math_tasks) ex_pwd = 5 ex_math = 5 example_payoff = (pwd_piecerate*5)+(math_piecerate*5) return dict(pwd_piecerate=pwd_piecerate, math_piecerate=math_piecerate, max_payoff=max_payoff, ex_pwd=ex_pwd, ex_math=ex_math, example_payoff=example_payoff ) class MPL_high(Page): def is_displayed(self): if self.player.MPL_sequence == 'HighLow': in_round = 1 elif self.player.MPL_sequence == 'LowHigh': in_round = 2 return self.round_number == in_round form_model = 'player' form_fields = [ 'last_False_high', 'first_True_high', 'last_False_val_high', 'first_True_val_high', 'decision_list_high', 'reminder_list_high', 'no_reminder_list_high', 'MPL_high_warnings', 'MPL_high_time_spent'] def vars_for_template(self): pwd_piecerate = Constants.pwd_piecerate_high math_piecerate = Constants.math_piecerate_high max_payoff = (pwd_piecerate*Constants.num_pwd_tasks)+(math_piecerate*Constants.num_math_tasks) ex_pwd = 5 ex_math = 5 example_payoff = (pwd_piecerate*5)+(math_piecerate*5) return dict(pwd_piecerate=pwd_piecerate, math_piecerate=math_piecerate, max_payoff=max_payoff, ex_pwd=ex_pwd, ex_math=ex_math, example_payoff=example_payoff ) def js_vars(self): return dict( page_name='MPL_high', max_amount=Constants.max_amount, increments=Constants.increments, no_decisions=Constants.no_decisions ) def before_next_page(self): self.player.participant.vars['MPL_last_False_high'] = self.player.last_False_high self.player.participant.vars['MPL_first_True_high'] = self.player.first_True_high self.player.participant.vars['MPL_last_False_val_high'] = self.player.last_False_val_high self.player.participant.vars['MPL_first_True_val_high'] = self.player.first_True_val_high self.player.participant.vars['MPL_decision_list_high'] = json.loads(self.player.decision_list_high) self.player.participant.vars['MPL_reminder_list_high'] = json.loads(self.player.reminder_list_high) self.player.participant.vars['MPL_no_reminder_list_high'] = json.loads(self.player.no_reminder_list_high) class MPL_low_Intro(Page): def is_displayed(self): if self.player.MPL_sequence == 'HighLow': in_round = 2 elif self.player.MPL_sequence == 'LowHigh': in_round = 1 return self.round_number == in_round def vars_for_template(self): pwd_piecerate = Constants.pwd_piecerate_low math_piecerate = Constants.math_piecerate_low max_payoff = (pwd_piecerate*Constants.num_pwd_tasks)+(math_piecerate*Constants.num_math_tasks) return dict(pwd_piecerate=pwd_piecerate, math_piecerate=math_piecerate, max_payoff=max_payoff ) class MPL_low(Page): def is_displayed(self): if self.player.MPL_sequence == 'LowHigh': in_round = 1 elif self.player.MPL_sequence == 'HighLow': in_round = 2 return self.round_number == in_round form_model = 'player' form_fields = [ 'last_False_low', 'first_True_low', 'last_False_val_low', 'first_True_val_low', 'decision_list_low', 'reminder_list_low', 'no_reminder_list_low', 'MPL_low_warnings', 'MPL_low_time_spent'] def vars_for_template(self): pwd_piecerate = Constants.pwd_piecerate_low math_piecerate = Constants.math_piecerate_low max_payoff = (pwd_piecerate*Constants.num_pwd_tasks)+(math_piecerate*Constants.num_math_tasks) ex_pwd = 5 ex_math = 5 example_payoff = (pwd_piecerate*5)+(math_piecerate*5) return dict(pwd_piecerate=pwd_piecerate, math_piecerate=math_piecerate, max_payoff=max_payoff, ex_pwd=ex_pwd, ex_math=ex_math, example_payoff=example_payoff ) def js_vars(self): return dict( page_name='MPL_low', max_amount=Constants.max_amount, increments=Constants.increments, no_decisions=Constants.no_decisions ) def before_next_page(self): self.player.participant.vars['MPL_last_False_low'] = self.player.last_False_low self.player.participant.vars['MPL_first_True_low'] = self.player.first_True_low self.player.participant.vars['MPL_last_False_val_low'] = self.player.last_False_val_low self.player.participant.vars['MPL_first_True_val_low'] = self.player.first_True_val_low self.player.participant.vars['MPL_decision_list_low'] = json.loads(self.player.decision_list_low) self.player.participant.vars['MPL_reminder_list_low'] = json.loads(self.player.reminder_list_low) self.player.participant.vars['MPL_no_reminder_list_low'] = json.loads(self.player.no_reminder_list_low) class MPL_Outro(Page): def is_displayed(self): return self.round_number == Constants.num_rounds page_sequence = [ Instructions_1, #Instructions_2, MPL_Instructions, MPL_high, MPL_low, ]