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 * import time # ******************************************************************************************************************** # # *** PAGE DECISION *** # # ******************************************************************************************************************** # class part3(Page): 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_range_2(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 slider_practice(Page): # form model # ---------------------------------------------------------------------------------------------------------------- form_model = 'player' form_fields = ['slider_prac', 'slider_prac_uncer'] def error_message(self, values): cond1 = (values['slider_prac'] != 6) cond2 = (values['slider_prac_uncer'] != 75) if (cond1): return "Please move your slider again to correct your answer for the first question" elif (cond2): return "Please move your slider again to correct your answer to the second question" # ******************************************************************************************************************** # # *** PAGE SEQUENCE *** # # ******************************************************************************************************************** # page_sequence = [part3, belief_range, belief_range_2, Decision1]