from otree.api import Currency as c, currency_range from . import models from ._builtin import Page, WaitPage from .models import Constants, Player # variables for all templates def vars_for_all_templates(self): return { 'p_hi': "{0:.1f}".format(Constants.probability) + "%", 'p_lo': "{0:.1f}".format(100 - Constants.probability) + "%", 'hi': c(Constants.lottery_hi), 'lo': c(Constants.lottery_lo), 'group': self.participant.vars['color'].replace("'",""), 'hi_B': c(Constants.lottery_hi_B), 'lo_B': c(Constants.lottery_lo_B), } # *** CLASS INSTRUCTIONS *** # class WelcomePage_A(Page): def is_displayed(self): if self.participant.vars['color']=='A': #Welcome Page for treatment A return self.subsession.round_number == 1 else: return False def vars_for_template(self): return { 'endowment': Constants.endowment } class WelcomePage_B(Page): def is_displayed(self): if self.participant.vars['color']=='B': #Welcome Page for treatment B return self.subsession.round_number == 1 else: return False def vars_for_template(self): return { 'endowment_B': Constants.endowment_B } class Instructions(Page): # only display instruction in round 1 def is_displayed(self): return self.subsession.round_number == 1 class ConfirmationCheck(Page): # This will check if the participant is ready for the experiment form_model = 'player' form_fields =['Question1','Question2'] def is_displayed(self): return self.subsession.round_number == 1 def app_after_this_page(self, upcoming_apps): if self.player.Question1=='No' or self.player.Question2==2: return upcoming_apps[-1] # *** PAGE DECISION *** # class Decision_A(Page): # only display if previous choice was not "indifferent" def is_displayed(self): return self.participant.vars['color']=='A' # form model and form fields form_model = 'player' form_fields = ['choice'] # variables for template def vars_for_template(self): # specify info for progress bar total = Constants.num_choices page = self.subsession.round_number progress = page / total * 100 return { 'page': page, 'total': total, 'progress': progress, 'sure_payoff': self.participant.vars['icl_sure_payoffs'][page - 1] } # set sure payoffs for next choice, payoffs, and switching row def before_next_page(self): self.player.set_sure_payoffs() self.player.update_switching_row() self.player.set_payoffs() # Decision for group # class Decision_B(Page): # only display if previous choice was not "indifferent" def is_displayed(self): return self.participant.vars['color']=='B' # form model and form fields form_model = 'player' form_fields = ['choice'] # variables for template def vars_for_template(self): # specify info for progress bar total = Constants.num_choices page = self.subsession.round_number progress = page / total * 100 return { 'page': page, 'total': total, 'progress': progress, 'sure_payoff': self.participant.vars['icl_sure_payoffs_B'][page - 1], 'hi_B': Constants.lottery_hi_B, 'lo_B': Constants.lottery_lo_B, 'sure_payoff_B': self.player.participant.vars['icl_sure_payoffs_B'][page - 1], } # set sure payoffs for next choice, payoffs, and switching row def before_next_page(self): self.player.set_sure_payoffs() self.player.update_switching_row() self.player.set_payoffs() # *** PAGE RESULTS *** # class Results_A(Page): # skip results until last page def is_displayed(self): if self.participant.vars['color']=='A': return self.subsession.round_number == Constants.num_rounds else: return False # variables for template def vars_for_template(self): # payoff information choice_to_pay = self.participant.vars['icl_choice_to_pay'] option_to_pay = self.player.in_round(choice_to_pay).choice payoff_relevant = self.player.in_round(choice_to_pay).payoff_relevant sure_payoff = self.player.participant.vars['icl_sure_payoffs'][choice_to_pay - 1] return { 'sure_payoff': sure_payoff, 'option_to_pay': option_to_pay, 'payoff_relevant': payoff_relevant, 'payoff': self.player.in_round(choice_to_pay).payoff, 'group': self.participant.vars['color'], } # Results B class Results_B(Page): # skip results until last page def is_displayed(self): if self.participant.vars['color']=='B': return self.subsession.round_number == Constants.num_rounds else: return False # variables for template def vars_for_template(self): # payoff information choice_to_pay_B = self.participant.vars['icl_choice_to_pay_B'] option_to_pay_B = self.player.in_round(choice_to_pay_B).choice payoff_relevant_B = self.player.in_round(choice_to_pay_B).payoff_relevant sure_payoff_B = self.player.participant.vars['icl_sure_payoffs_B'][choice_to_pay_B - 1] return { 'sure_payoff_B': sure_payoff_B, 'option_to_pay_B': option_to_pay_B, 'payoff_relevant_B': payoff_relevant_B, 'payoff_B': self.player.in_round(choice_to_pay_B).payoff, 'group': self.participant.vars['color'], 'sure_payoff_B': self.player.participant.vars['icl_sure_payoffs_B'][choice_to_pay_B - 1], 'hi_B': Constants.lottery_hi_B, 'lo_B': Constants.lottery_lo_B, } # *** PAGE SEQUENCE *** # page_sequence = [ WelcomePage_A, WelcomePage_B, Instructions, ConfirmationCheck, Decision_A, Decision_B, Results_A, Results_B, ] # if Constants.instructions: # page_sequence.insert(0, Instructions ) # # if Constants.confirmation: # page_sequence.insert(1,ConfirmationCheck) # # if Constants.results: # page_sequence.append(Results_A) # # if Constants.results: # page_sequence.append(Results_B)