from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) from PATIENCE_STAIRCASE.config import * import random author = 'Felix Holzmeister' doc = """ Staircase risk elicitation task as proposed by Falk et al. (2016), Working Paper. """ # ******************************************************************************************************************** # # *** CLASS SUBSESSION # ******************************************************************************************************************** # class Subsession(BaseSubsession): # initiate list of sure payoffs and implied switching row in first round # ------------------------------------------------------------------------------------------------------------ def creating_session(self): # creating index denoting new App (e.g., Part 'index') if self.round_number == 1: for p in self.get_players(): p.participant.vars['icl_time_sure_payoffs'] = [Constants.sure_payoff] p.participant.vars['icl_switching_row'] = 2 ** Constants.num_choices # create Part index to show in templates' title (i.e., "Part ") # ------------------------------------------------------------------------------------------------------ if "p.participant.vars['part_index']" not in globals(): p.participant.vars['part_index'] = 1 # ******************************************************************************************************************** # # *** CLASS GROUP # ******************************************************************************************************************** # class Group(BaseGroup): pass # ******************************************************************************************************************** # # *** CLASS PLAYER # ******************************************************************************************************************** # class Player(BasePlayer): # add model fields to class player # ---------------------------------------------------------------------------------------------------------------- sure_payoff = models.FloatField() choice = models.StringField() switching_row = models.IntegerField() #payoff_ecu = models.FloatField() # set sure payoff for next choice # ---------------------------------------------------------------------------------------------------------------- def set_sure_payoffs(self): # add current round's sure payoff to model field # ------------------------------------------------------------------------------------------------------------ self.sure_payoff = self.participant.vars['icl_time_sure_payoffs'][self.round_number - 1] # determine sure payoff for next choice and append list of sure payoffs # ------------------------------------------------------------------------------------------------------------ if not self.round_number == Constants.num_choices: if self.choice == 'A': self.participant.vars['icl_time_sure_payoffs'].append( self.participant.vars['icl_time_sure_payoffs'][self.round_number - 1] + Constants.delta / 2 ** (self.round_number - 1) + 2.75 / 2 ** (self.round_number - 1) ) print(self.participant.vars['icl_time_sure_payoffs']) elif self.choice == 'B': self.participant.vars['icl_time_sure_payoffs'].append( self.participant.vars['icl_time_sure_payoffs'][self.round_number - 1] - Constants.delta / 2 ** (self.round_number - 1) ) print(self.participant.vars['icl_time_sure_payoffs']) else: pass # update implied switching row each round # ---------------------------------------------------------------------------------------------------------------- def update_switching_row(self): if self.choice == 'B': self.participant.vars['icl_switching_row'] -= 2 ** (Constants.num_choices - self.round_number) elif self.choice == 'I': self.participant.vars['icl_switching_row'] /= 2 # create function to increase part index by 1 when App changes # ------------------------------------------------------------------------------------------------------------------ def update_part_index(self): self.participant.vars['part_index'] += 1