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 * # variables for all templates # -------------------------------------------------------------------------------------------------------------------- def vars_for_all_templates(self): return { 'lottery_a_lo': c(Constants.lottery_a_lo), 'lottery_a_hi': c(Constants.lottery_a_hi), 'lottery_b_lo': c(Constants.lottery_b_lo), 'lottery_b_hi': c(Constants.lottery_b_hi) } # ******************************************************************************************************************** # # *** CLASS INSTRUCTIONS *** # # ******************************************************************************************************************** # class Instructions(Page): # only display instruction in round 1 # ---------------------------------------------------------------------------------------------------------------- def is_displayed(self): return self.subsession.round_number == 1 # variables for template # ---------------------------------------------------------------------------------------------------------------- def vars_for_template(self): return { 'num_choices': len(self.participant.vars['mpl_choices']) } # ******************************************************************************************************************** # # *** PAGE DECISION *** # # ******************************************************************************************************************** # 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_time1'])][1] return form_fields # variables for template # ---------------------------------------------------------------------------------------------------------------- def vars_for_template(self): return { 'choices': self.player.participant.vars['mpl_choices_time1'] } # disallow choices that 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['choice1_' + str(i)] == 'A') and (values['choice1_' + str(j)] == 'B')) if (cond1): return "Please review your choices to see if they reflect your true preferences." cond2 = ((values['choice1_' + str(i)] == 'B') and (values['choice1_' + str(j)] == 'A')) if (cond2 and (j != Constants.num_choices + 1)): for k in range(j + 1, Constants.num_choices + 1): cond3 = (values['choice1_' + str(k)] == 'B') if (cond3): return "Please review your choices to see if they reflect your true preferences." class Decision2(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_time2'])][1] return form_fields # variables for template # ---------------------------------------------------------------------------------------------------------------- def vars_for_template(self): return { 'choices': self.player.participant.vars['mpl_choices_time2'] } # 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['choice2_' + str(i)] == 'A') and (values['choice2_' + str(j)] == 'B')) if (cond1): return "Please review your choices to see if they reflect your true preferences." cond2 = ((values['choice2_' + str(i)] == 'B') and (values['choice2_' + str(j)] == 'A')) if (cond2 and (j != Constants.num_choices + 1)): for k in range(j + 1, Constants.num_choices + 1): cond3 = (values['choice2_' + str(k)] == 'B') if (cond3): return "Please review your choices to see if they reflect your true preferences." def before_next_page(self): self.player.participant.vars['finished'] = True self.player.participant.vars['payoff'] = self.player.participant.vars['payoff'] class debrief(Page): # form model # ---------------------------------------------------------------------------------------------------------------- form_model = 'player' def vars_for_template(self): risk_5yr = self.player.participant.vars['brisk_five'] risk_life = self.player.participant.vars['brisk_life'] payoff = self.player.participant.vars['payoff']+4 return dict( risk_5yr=risk_5yr, risk_life=risk_life, payoff=payoff ) def js_vars(self): return dict( completionlink= self.player.subsession.session.config['prolific_completion_url'] ) pass # ******************************************************************************************************************** # # *** PAGE SEQUENCE *** # # ******************************************************************************************************************** # page_sequence = [Decision1, Decision2, debrief]