from otree.api import Currency as c, currency_range from . import models from ._builtin import Page, WaitPage from .models import Constants from mpl.config import * # ******************************************************************************************************************** # # *** PAGE DECISION *** # # ******************************************************************************************************************** # class part4(Page): # form model # ---------------------------------------------------------------------------------------------------------------- form_model = 'player' class Decision1(Page): # form model # ---------------------------------------------------------------------------------------------------------------- form_model = 'player' # form fields # ---------------------------------------------------------------------------------------------------------------- def get_form_fields(self): # unzip list of form_fields from list form_fields = [list(t) for t in zip(*self.participant.vars['mpl_choices'])][1] form_fields.append('test_next_month') form_fields.append('follow_cdc') # provide form field associated with pagination or full list return form_fields # variables for template # ---------------------------------------------------------------------------------------------------------------- def vars_for_template(self): # specify info for progress bar total = len(self.participant.vars['mpl_choices']) page = self.subsession.round_number progress = page / total * 100 return { 'choices': self.player.participant.vars['mpl_choices'] } # disallow choices thata are not consistent with individuals' preferances def error_message(self, values): for i in range(1, Constants.num_choices): for j in range(i + 1, Constants.num_choices + 1): cond1 = ((values['choice_' + str(i)] == 'B') and (values['choice_' + str(j)] == 'A')) if (cond1): return "Please review your choices to see if they reflect your true preferences." cond2 = ((values['choice_' + str(i)] == 'A') and (values['choice_' + str(j)] == 'B')) if (cond2 and (j != Constants.num_choices + 1)): for k in range(j + 1, Constants.num_choices + 1): cond3 = (values['choice_' + str(k)] == 'A') if (cond3): return "Please review your choices to see if they reflect your true preferences." # class belief_range(Page): # # # form model # # ---------------------------------------------------------------------------------------------------------------- # form_model = 'player' # form_fields = ['five_year_risk', 'life_time_risk', 'five_year_risk_s', 'life_time_risk_s'] # # # class belief_range2(Page): # # # form model # # ---------------------------------------------------------------------------------------------------------------- # form_model = 'player' # form_fields = ['five_year_risk_uncer', 'life_time_risk_uncer', 'five_year_risk_s_uncer', 'life_time_risk_s_uncer'] # # def vars_for_template(self): # risk_5yr = self.player.five_year_risk # risk_life = self.player.life_time_risk # risk_5yr_s = self.player.five_year_risk_s # risk_life_s = self.player.life_time_risk_s # risk_5yr_low = max(risk_5yr-10, 0) # risk_5yr_high = min(risk_5yr+10, 100) # risk_life_low = max(risk_life - 10, 0) # risk_life_high = min(risk_life + 10, 100) # risk_5yr_low_s = max(risk_5yr_s - 10, 0) # risk_5yr_high_s = min(risk_5yr_s + 10, 100) # risk_life_low_s = max(risk_life_s - 10, 0) # risk_life_high_s = min(risk_life_s + 10, 100) # # return dict( # risk_5yr=risk_5yr, # risk_life=risk_life, # risk_5yr_low=risk_5yr_low, # risk_life_low=risk_life_low, # risk_5yr_high=risk_5yr_high, # risk_life_high=risk_life_high, # risk_5yr_s=risk_5yr_s, # risk_life_s=risk_life_s, # risk_5yr_low_s=risk_5yr_low_s, # risk_life_low_s=risk_life_low_s, # risk_5yr_high_s=risk_5yr_high_s, # risk_life_high_s=risk_life_high_s # ) class belief_updated1(Page): # form model # ---------------------------------------------------------------------------------------------------------------- form_model = 'player' form_fields = ['five_year_risk', 'five_year_risk_estimate', 'five_year_risk_lower', 'five_year_risk_upper', \ 'five_year_risk_uncer', 'five_year_risk_s_uncer'] def error_message(self, values): if values['five_year_risk_lower'] > values['five_year_risk_estimate']: return "Please note that your answer to question 4 should be lower than or equal to your answer " \ "to question 3." if values['five_year_risk_upper'] < values['five_year_risk_estimate']: return "Please note that your answer to question 5 should be greater than or equal to your answer " \ "to question 3." class belief_updated2(Page): # form model # ---------------------------------------------------------------------------------------------------------------- form_model = 'player' form_fields = ['life_time_risk', 'life_time_risk_estimate', 'life_time_risk_lower', 'life_time_risk_upper', 'life_time_risk_uncer', 'life_time_risk_s_uncer'] def error_message(self, values): if values['life_time_risk_lower'] > values['life_time_risk_estimate']: return "Please note that your answer to question 4 should be lower than or equal to your answer " \ "to question 3." if values['life_time_risk_upper'] < values['life_time_risk_estimate']: return "Please note that your answer to question 5 should be greater than or equal to your answer " \ "to question 3." # ******************************************************************************************************************** # # *** PAGE SEQUENCE *** # # ******************************************************************************************************************** # page_sequence = [part4, belief_updated1, belief_updated2, Decision1]