from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants import random import json from decimal import Decimal class Patience_Intro(Page): # timeout_seconds = 60 * 10 # form model # ---------------------------------------------------------------------------------------------------------------- form_model = 'player' pass class a_Pat_MPL_1(Page): # timeout_seconds = 60 * 3 # 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_pat_1_choices'])][1] return form_fields # variables for template # ---------------------------------------------------------------------------------------------------------------- def vars_for_template(self): return { 'choices': self.player.participant.vars['mpl_pat_1_choices'] } # # show hints # # ---------------------------------------------------------------------------------------------------------------- # def timepref_pat_mpl_1_choice_10_error_message(self, value): # print('value is', value) # if value == 'patient' and not self.player.timepref_pat_mpl_1_error: # self.player.timepref_pat_mpl_1_error = True # return 'Hinweis: Sie haben in der letzten Reihe angegeben, dass Sie 4000 Punkte in einem Monat bevorzugen würden gegenüber 4500 Punkte heute. Sind Sie sicher, dass Sie das wollen?' # # set player's payoff # ---------------------------------------------------------------------------------------------------------------- def before_next_page(self): # unzip indices and form fields from list form_fields_1 = [list(t) for t in zip(*self.participant.vars['mpl_pat_1_choices'])][1] indices_1 = [list(t) for t in zip(*self.participant.vars['mpl_pat_1_choices'])][0] # replace choices in for j, choice in zip(indices_1, form_fields_1): choice_i = getattr(self.player, choice) self.participant.vars['timepref_pat_mpl_1_choices_made'][j - 1] = choice_i # set payoff if self.participant.vars['timepref_pat_mpl_to_pay'] == 1: self.player.set_payoffs() # determine counts of patient / impatient options self.player.set_consistency() self.player.set_count_patient_option_mpl_1() self.player.set_count_impatient_option_mpl_1() class b_Pat_MPL_2(Page): # timeout_seconds = 60 * 3 # 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_pat_2_choices'])][1] return form_fields # variables for template # ---------------------------------------------------------------------------------------------------------------- def vars_for_template(self): return { 'choices': self.player.participant.vars['mpl_pat_2_choices'] } # # show hints # # ---------------------------------------------------------------------------------------------------------------- # def timepref_pat_mpl_2_choice_14_error_message(self, value): # print('value is', value) # if value == 'patient' and not self.player.timepref_pat_mpl_2_error: # self.player.timepref_pat_mpl_2_error = True # return 'Hinweis: Sie haben in der letzten Reihe angegeben, dass Sie 6000 Punkte in einem Jahr bevorzugen würden gegenüber 6500 Punkte heute. Sind Sie sicher, dass Sie das wollen?' # # # set player's payoff # ---------------------------------------------------------------------------------------------------------------- def before_next_page(self): # unzip indices and form fields from list form_fields_2 = [list(t) for t in zip(*self.participant.vars['mpl_pat_2_choices'])][1] indices_2 = [list(t) for t in zip(*self.participant.vars['mpl_pat_2_choices'])][0] # replace choices in for j, choice in zip(indices_2, form_fields_2): choice_i = getattr(self.player, choice) self.participant.vars['timepref_pat_mpl_2_choices_made'][j - 1] = choice_i # set payoff if self.participant.vars['timepref_pat_mpl_to_pay'] == 2: self.player.set_payoffs() # determine counts of patient / impatient options self.player.set_consistency() self.player.set_count_patient_option_mpl_2() self.player.set_count_impatient_option_mpl_2() class c_Pat_MPL_3(Page): # timeout_seconds = 60 * 3 # 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_pat_3_choices'])][1] return form_fields # variables for template # ---------------------------------------------------------------------------------------------------------------- def vars_for_template(self): return { 'choices': self.player.participant.vars['mpl_pat_3_choices'] } # # show hints # # ---------------------------------------------------------------------------------------------------------------- # def timepref_pat_mpl_3_choice_16_error_message(self, value): # print('value is', value) # if value == 'impatient' and not self.player.timepref_pat_mpl_3_error: # self.player.timepref_pat_mpl_2_error = True # return 'Hinweis: Sie haben in der letzten Reihe angegeben, dass Sie -7500 Punkte in 365 Tagen bevorzugen würden gegenüber -7000 Punkte 395. Sind Sie sicher, dass Sie das wollen?' # # # set player's payoff # ---------------------------------------------------------------------------------------------------------------- def before_next_page(self): # unzip indices and form fields from list form_fields_3 = [list(t) for t in zip(*self.participant.vars['mpl_pat_3_choices'])][1] indices_3 = [list(t) for t in zip(*self.participant.vars['mpl_pat_3_choices'])][0] # replace choices in for j, choice in zip(indices_3, form_fields_3): choice_i = getattr(self.player, choice) self.participant.vars['timepref_pat_mpl_3_choices_made'][j - 1] = choice_i # set payoff if self.participant.vars['timepref_pat_mpl_to_pay'] == 3: self.player.set_payoffs() # determine counts of patient / impatient options self.player.set_consistency() self.player.set_count_patient_option_mpl_3() self.player.set_count_impatient_option_mpl_3() class d_Pat_MPL_4(Page): # timeout_seconds = 60 * 3 # 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_pat_4_choices'])][1] return form_fields # variables for template # ---------------------------------------------------------------------------------------------------------------- def vars_for_template(self): return { 'choices': self.player.participant.vars['mpl_pat_4_choices'] } # # show hints # # ---------------------------------------------------------------------------------------------------------------- # def timepref_pat_mpl_4_choice_9_error_message(self, value): # print('value is', value) # if value == 'impatient' and not self.player.timepref_pat_mpl_4_error: # self.player.timepref_pat_mpl_2_error = True # return 'Hinweis: Sie haben in der letzten Reihe angegeben, dass Sie -4000 Punkte in 30 Tagen bevorzugen würden gegenüber -3500 Punkte in 60 Tagen. Sind Sie sicher, dass Sie das wollen?' # # # set player's payoff # ---------------------------------------------------------------------------------------------------------------- def before_next_page(self): # unzip indices and form fields from list form_fields_4 = [list(t) for t in zip(*self.participant.vars['mpl_pat_4_choices'])][1] indices_4 = [list(t) for t in zip(*self.participant.vars['mpl_pat_4_choices'])][0] # replace choices in for j, choice in zip(indices_4, form_fields_4): choice_i = getattr(self.player, choice) self.participant.vars['timepref_pat_mpl_4_choices_made'][j - 1] = choice_i # set payoff if self.participant.vars['timepref_pat_mpl_to_pay'] == 4: self.player.set_payoffs() # determine counts of patient / impatient options self.player.set_consistency() self.player.set_count_patient_option_mpl_4() self.player.set_count_impatient_option_mpl_4() start_pages = [Patience_Intro] end_pages = [] initial_page_sequence = [ a_Pat_MPL_1, b_Pat_MPL_2, c_Pat_MPL_3, d_Pat_MPL_4 ] page_sequence = [] class MyPage(Page): def inner_dispatch(self): page_seq = int(self.__class__.__name__.split('_')[1]) page_to_show = json.loads(self.player.page_sequence)[page_seq] self._is_frozen = False self.__class__ = globals()[page_to_show] return super(globals()[page_to_show], self).inner_dispatch() for i, _ in enumerate(initial_page_sequence): NewClassName = "Page_{}".format(i) A = type(NewClassName, (MyPage,), {}) locals()[NewClassName] = A page_sequence.append(locals()[NewClassName]) page_sequence = start_pages + page_sequence + end_pages