from otree.api import * c = cu doc = '' class C(BaseConstants): NAME_IN_URL = 'Risk_HL_Euros' PLAYERS_PER_GROUP = None NUM_ROUNDS = 1 PAYOFF_A_HIGH = 2 PAYOFF_A_LOW = 1.6 PAYOFF_B_HIGH = 3.85 PAYOFF_B_LOW = 0.1 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): HL_1 = models.IntegerField(choices=[[1, 'Option A: 10% chance €2 and 90% chance €1,6'], [2, 'Option B: 10% chance €3,85 and 90% chance €0,10']], label='Decision 1:', widget=widgets.RadioSelectHorizontal) HL_2 = models.IntegerField(choices=[[1, 'Option A: 20% chance €2 and 80% chance €1,6'], [2, 'Option B: 20% chance €3,85 and 80% chance €0,10']], label='Decision 2:', widget=widgets.RadioSelectHorizontal) HL_3 = models.IntegerField(choices=[[1, 'Option A: 30% chance €2 and 70% chance €1,6'], [2, 'Option B: 30% chance €3,85 and 70% chance €0,10']], label='Decision 3:', widget=widgets.RadioSelectHorizontal) HL_4 = models.IntegerField(choices=[[1, 'Option A: 40% chance €2 and 60% chance €1,6'], [2, 'Option B: 40% chance €3,85 and 60% chance €0,10']], label='Decision 4:', widget=widgets.RadioSelectHorizontal) HL_5 = models.IntegerField(choices=[[1, 'Option A: 50% chance €2 and 50% chance €1,6'], [2, 'Option B: 50% chance €3,85 and 50% chance €0,10']], label='Decision 5:', widget=widgets.RadioSelectHorizontal) HL_6 = models.IntegerField(choices=[[1, 'Option A: 60% chance €2 and 40% chance €1,6'], [2, 'Option B: 60% chance €3,85 and 40% chance €0,10']], label='Decision 6:', widget=widgets.RadioSelectHorizontal) HL_7 = models.IntegerField(choices=[[1, 'Option A: 70% chance €2 and 30% chance €1,6'], [2, 'Option B: 70% chance €3,85 and 30% chance €0,10']], label='Decision 7:', widget=widgets.RadioSelectHorizontal) HL_8 = models.IntegerField(choices=[[1, 'Option A: 80% chance €2 and 20% chance €1,6'], [2, 'Option B: 80% chance €3,85 and 20% chance €0,10']], label='Decision 8:', widget=widgets.RadioSelectHorizontal) HL_9 = models.IntegerField(choices=[[1, 'Option A: 90% chance €2 and 10% chance €1,6'], [2, 'Option B: 90% chance €3,85 and 10% chance €0,10']], label='Decision 9:', widget=widgets.RadioSelectHorizontal) HL_10 = models.IntegerField(choices=[[1, 'Option A: 100% chance €2 and 0% chance €1,6'], [2, 'Option B: 100% chance €3,85 and 0% chance €0,10']], label='Decision 10:', widget=widgets.RadioSelectHorizontal) HL_random = models.IntegerField() HL_decision = models.IntegerField() HL_option_choice = models.IntegerField() def set_payoff_HL(player: Player): participant = player.participant import random #******************************************* # select random row and random outcome #******************************************* # select one decision randomly for payment (from module random) player.HL_decision = random.randint(1,10) # select the number x that defines the outcome of the lottery (if x<=p, outcome is left A_H or B:_H, otherwise A_L or B_L) # write it to player.HL_random player.HL_random = random.randint(1,10) #******************************************* # select choices in correspondence to random decision #******************************************* # create a list with all choices of the player choices = [player.HL_1,player.HL_2,player.HL_3,player.HL_4,player.HL_5,player.HL_6,player.HL_7,player.HL_8,player.HL_9,player.HL_10] # select from the list the choice that correspondence to the randomly drawn decision (notice the offset) # write it to participant.HL_choice player.HL_option_choice = choices[player.HL_decision-1] #******************************************* # Compute here the payoffs #******************************************* # if the random number is smaller equal than the random decision if player.HL_random <= player.HL_decision: # if the choice was A if player.HL_option_choice == 1: #A # because HL_decision is the same as p in the MPL player.payoff = C.PAYOFF_A_HIGH else : # if the choice was B player.payoff = C.PAYOFF_B_HIGH else: # if the random number is larger than the random decision # if the choice was A if player.HL_option_choice == 1 :#A player.payoff = C.PAYOFF_A_LOW # because HL_row is the same as p in the MPL else : player.payoff = C.PAYOFF_B_LOW def get_option_choice_display_name(player: Player): return "Option A" if player.HL_option_choice == 1 else "Option B" class Risk_Aversion_HL(Page): form_model = 'player' form_fields = ['HL_1', 'HL_2', 'HL_3', 'HL_4', 'HL_5', 'HL_6', 'HL_7', 'HL_8', 'HL_9', 'HL_10'] @staticmethod def before_next_page(player: Player, timeout_happened): set_payoff_HL(player) class Result(Page): form_model = 'player' @staticmethod def vars_for_template(player: Player): return dict(display_option=get_option_choice_display_name(player)) page_sequence = [Risk_Aversion_HL, Result]