from otree.api import * import numpy as np doc = """ Table where each row has a left/right choice, like the strategy method. This app enforces a single switching point """ class C(BaseConstants): NAME_IN_URL = 'mpl' PLAYERS_PER_GROUP = None NUM_ROUNDS = 1 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): left_side_amount = models.IntegerField(initial=10) c0 = models.StringField() c50 = models.StringField() c100 = models.StringField() c150 = models.StringField() c200 = models.StringField() c250 = models.StringField() c300 = models.StringField() c350 = models.StringField() c400 = models.StringField() c450 = models.StringField() c500 = models.StringField() c550 = models.StringField() c600 = models.StringField() c650 = models.StringField() c700 = models.StringField() c750 = models.StringField() c800 = models.StringField() c850 = models.StringField() c900 = models.StringField() c950 = models.StringField() c1000 = models.StringField() payout = models.IntegerField() message = models.LongStringField() # PAGES class Decide(Page): form_model = 'player' form_fields = ['c0', 'c50', 'c100', 'c150', 'c200', 'c250', 'c300', 'c350', 'c400', 'c450', 'c500', 'c550', 'c600', 'c650', 'c700', 'c750', 'c800', 'c850', 'c900', 'c950', 'c1000'] @staticmethod def vars_for_template(player: Player): keys = range(0, 1050, 50) values = [x / 100 for x in keys] right_side_amounts = {keys[i]: values[i] for i in range(len(keys))} return {'right_side_amounts' : right_side_amounts} # def vars_for_template(player: Player): # return dict(right_side_amounts = range(0, 1050, 50)) def before_next_page(player: Player, timeout_happened): r_dict = {'c0': 1, 'c50': 0.769, 'c100': 0.699, 'c150': 0.635, 'c200': 0.569, 'c250': 0.5, 'c300': 0.424, 'c350': 0.34, 'c400': 0.244, 'c450': 0.132, 'c500': -0.0, 'c550': -0.159, 'c600': -0.357, 'c650': -0.609, 'c700': -0.943, 'c750': -1.409, 'c800': -2.106, 'c850': -3.265, 'c900': -5.579, 'c950': -12.513, 'c1000': -20} participant = player.participant # define risk aversion param to pass on to steering_app for i in range(0, 1050, 50): field_name = "c" + str(i) if getattr(player, field_name) == "left": continue else: participant.r = r_dict[field_name] break # randomly select row as prize for subject, draw lottery in case it choice was left p_range = [i for i in range(0, 1050, 50)] selected_choice = "c" + str(np.random.choice(p_range)) if getattr(player, selected_choice) == "right": participant.payoff1 = int(selected_choice[1:]) participant.message1 = "The randomly selected choice was the choice between the lottery '50%: 10€, 50%:0€' and the safe option " + selected_choice[1:] + "€. You chose the safe option, therefore your payoff from this part of the experiment is " + selected_choice[1:] +"€." else: po = np.random.choice([10, 0]) participant.payoff1 = po participant.message1 = "The randomly selected choice was the choice between the lottery '50%: 10€, 50%:0€' and the safe option " + selected_choice[1:] + "€. You chose the lottery. The lottery was drawn to be " + str(po) + "€, therefore your payoff from this part of the experiment is " + str(po) + "€." class Result(Page): pass class Intro(Page): pass class OverallIntro(Page): pass page_sequence = [OverallIntro, Intro, Decide]