from ._builtin import Page, WaitPage from otree.api import Currency as c, currency_range from .models import Constants # variables for all templates # -------------------------------------------------------------------------------------------------------------------- def vars_for_all_templates(self): x = self.participant.vars['replacement'] return { 'num_choices': Constants.num_choices, 'probability': "{0:.0f}".format(Constants.probability) + "%", 'winningamout':Constants.winningamount, 'num_rounds':Constants.num_rounds, 'num_balls':Constants.num_balls, 'replacement': Constants.textA if x == 1 else Constants.textB, } class instructions(Page): def is_displayed(self): return self.round_number == 1 def vars_for_template(self): return { 'choices': self.player.participant.vars['firstchoice'], } class instructions2(Page): def is_displayed(self): return self.round_number == 1 class instructions3(Page): def is_displayed(self): return self.round_number == 1 form_model = 'player' form_fields = ['quiz_1','quiz_2'] def before_next_page(self): self.player.check_quiz() class quizfail(Page): def is_displayed(self): return self.round_number == 1 and self.player.quiz == False form_model = 'player' form_fields = ['quiz_1','quiz_2'] def before_next_page(self): self.player.check_quiz() class quizfail2(Page): def is_displayed(self): return self.round_number == 1 and self.player.quiz == False class quizpass(Page): def is_displayed(self): return self.round_number == 1 and self.player.quiz == True form_model = 'player' form_fields = ['color','gender','age','prolific'] def before_next_page(self): self.player.getcolor() 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['firstchoice'])][1] return form_fields # variables for template # ---------------------------------------------------------------------------------------------------------------- def vars_for_template(self): x = self.subsession.round_number bags = self.participant.vars['bags'][x - 1] samplesize = bags[1] return { 'choices': self.player.participant.vars['firstchoice'], 'num_round': self.subsession.round_number, 'samplesize':samplesize, 'winningcolor':bags[2], 'unit': round(samplesize/3), } # set payoff, and set switching row # ---------------------------------------------------------------------------------------------------------------- def before_next_page(self): form_fields = [list(t) for t in zip(*self.participant.vars['firstchoice'])][1] indices = [list(t) for t in zip(*self.participant.vars['firstchoice'])][0] # replace choices in for j, choice in zip(indices, form_fields): choice_i = getattr(self.player, choice) self.participant.vars['firstchoice_made'][j - 1] = choice_i # set switching row self.player.set_switching_row_1() # set the second choice self.player.set_secondchoice() # set bag parameters self.player.set_bags() self.player.set_payoffs1() class decision2(Page): def is_displayed(self): return self.participant.vars['noswitch'] == False # 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['secondchoice'])][1] return form_fields # variables for template def vars_for_template(self): x = self.subsession.round_number bag = self.participant.vars['bags'][x - 1] samplesize = bag[1] return { 'choices': self.player.participant.vars['secondchoice'], 'num_round': self.subsession.round_number, 'samplesize':samplesize, 'winningcolor':bag[2], 'unit': round(samplesize/3), } # set payoff, determine consistency, and set switching row # ---------------------------------------------------------------------------------------------------------------- def before_next_page(self): # unzip indices and form fields from list round_number = self.subsession.round_number form_fields = [list(t) for t in zip(*self.participant.vars['secondchoice'])][1] indices = [list(t) for t in zip(*self.participant.vars['secondchoice'])][0] # replace choices in for j, choice in zip(indices, form_fields): choice_i = getattr(self.player, choice) self.participant.vars['secondchoice_made'][j - 1] = choice_i # set switching row self.player.set_switching_row_2() # set payoff self.player.set_payoffs2() # ******************************************************************************************************************** # # *** PAGE RESULTS *** # # ******************************************************************************************************************** # class result(Page): # skip results until last page # ---------------------------------------------------------------------------------------------------------------- def is_displayed(self): return self.round_number == Constants.num_rounds # variables for template # ---------------------------------------------------------------------------------------------------------------- def vars_for_template(self): # payoff information round_to_pay = self.session.vars['paying_round'] index_to_pay = self.player.in_round(round_to_pay).index_to_pay bag = self.participant.vars['bags'][round_to_pay - 1] samplesize = bag[1] if self.player.in_round(round_to_pay).random_draw == 1 or self.player.in_round(round_to_pay).switching_row_1 == 1 or self.player.in_round(round_to_pay).switching_row_1 == 12: choice_to_pay = self.participant.vars['firstchoice'][index_to_pay-1] p = [choice_to_pay][0][2] else: choice_to_pay = self.participant.vars['secondchoice_allrounds'][round_to_pay-1][1][index_to_pay-1] p = [choice_to_pay][0][2] return { 'choice_to_pay': [choice_to_pay], 'option_to_pay': self.player.in_round(round_to_pay).option_to_pay, 'payoff': self.player.in_round(round_to_pay).payoff, 'probability':"{0:.0f}".format(p) + "%", 'samplesize': samplesize, 'winningcolor': bag[2], 'unit': round(samplesize / 3), 'result':'win' if self.player.in_round(round_to_pay).payoff != 0 else 'lost', } def before_next_page(self): self.player.set_final_payoff() class result2(Page): # skip results until last page # ---------------------------------------------------------------------------------------------------------------- def is_displayed(self): return self.round_number == Constants.num_rounds # variables for template # ---------------------------------------------------------------------------------------------------------------- def vars_for_template(self): # payoff information round_to_pay = self.session.vars['paying_round'] index_to_pay = self.player.in_round(round_to_pay).index_to_pay bag = self.participant.vars['bags'][round_to_pay - 1] samplesize = bag[1] if self.player.in_round(round_to_pay).random_draw == 1 or self.player.in_round(round_to_pay).switching_row_1 == 1 or self.player.in_round(round_to_pay).switching_row_1 == 12: choice_to_pay = self.participant.vars['firstchoice'][index_to_pay-1] p = [choice_to_pay][0][2] else: choice_to_pay = self.participant.vars['secondchoice_allrounds'][round_to_pay - 1][1][index_to_pay - 1] p = [choice_to_pay][0][2] return { 'choice_to_pay': [choice_to_pay], 'option_to_pay': self.player.in_round(round_to_pay).option_to_pay, 'payoff': self.player.in_round(round_to_pay).payoff, 'probability':"{0:.0f}".format(p) + "%", 'samplesize': samplesize, 'winningcolor': bag[2], 'unit': round(samplesize / 3), 'result':'win' if self.player.in_round(round_to_pay).payoff != 0 else 'lost', 'round to pay': round_to_pay, } page_sequence = [instructions, instructions2, instructions3, quizfail, quizfail2, quizpass, decision1, decision2,result, result2]