from otree.api import Currency as c, currency_range from otree.models import subsession from .models import Subsession from ._builtin import Page, WaitPage from .models import Constants class Instructions(Page): def is_displayed(self): return self.round_number == 1 class Decision(Page): # form model # ---------------------------------------------------------------------------------------------------------------- form_model = 'player' # form fields # ---------------------------------------------------------------------------------------------------------------- def get_form_fields(self): form_fields_ambig = self.participant.vars['form_fields_ambig'] form_fields_ambig.append('success_color') return form_fields_ambig def vars_for_template(self): mpl_ambig_transp = [list(i) for i in zip(*self.player.participant.vars['mpl'])] self.player.participant.vars['mpl_ambig_transp'] = mpl_ambig_transp return { 'high_a': c(Constants.high_a), 'low_a' : c(Constants.low_a), 'form_fields': self.player.participant.vars['form_fields_ambig'], 'mpl': self.player.participant.vars['mpl_ambig_transp'], 'num_choices': Constants.num_choices, 'color': self.player.participant.vars['success_color'], 'num_table': self.round_number, } def before_next_page(self): # extract choices from form_fields before we move on form_fields_ambig = self.participant.vars['form_fields_ambig'] # replace choices in for j, choice in zip(Constants.index_choices, form_fields_ambig): choice_i = getattr(self.player, choice) self.participant.vars['ambig_choices_made'][j - 1] = choice_i form_field_color = self.participant.vars['success_color'] self.player.participant.vars['color_choice'] = getattr(self.player, form_field_color) self.player.set_success_color() # set consistency and switching row self.player.set_consistency() self.player.set_switching_row() # set payoff self.player.set_payoffs() class Results(Page): # variables for template # ---------------------------------------------------------------------------------------------------------------- def vars_for_template(self): return { 'choice_to_pay': self.player.choice_to_pay, 'option_to_pay': self.player.option_to_pay, 'payoff': self.player.payoff, 'high_a': Constants.high_a, 'low_a': Constants.low_a, 'high_b': self.participant.vars['mpl'][0][self.player.index_to_pay - 1] if self.player.selected == 1 else None, 'low_b': self.participant.vars['mpl'][1][self.player.index_to_pay - 1] if self.player.selected == 1 else None, 'selected': self.player.selected, 'success_color': self.player.participant.vars['color_choice'], 'green': self.player.green, 'blue': self.player.blue, 'ball_color': self.player.ball_color } page_sequence = [ Instructions, Decision, Results, ]