from otree.api import * c = cu doc = '' class C(BaseConstants): NAME_IN_URL = 'Loss_aversion' PLAYERS_PER_GROUP = None NUM_ROUNDS = 1 G1_LOSS = 1000 G2_LOSS = 2000 G3_LOSS = 3000 G4_LOSS = 4000 G5_LOSS = 5000 G6_LOSS = 6000 G7_LOSS = 7000 REWARD = 6000 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): Gamble_1 = models.BooleanField(choices=[[True, 'Accept'], [False, 'Reject']], label='1. With 50% chance you lose 1000 points. With 50% chance you win 6000 points..', widget=widgets.RadioSelectHorizontal) Gamble_2 = models.BooleanField(choices=[[True, 'Accept'], [False, 'Reject']], label='2. With 50% chance you lose 2000 points. With 50% chance you win 6000 points..', widget=widgets.RadioSelectHorizontal) Gamble_3 = models.BooleanField(choices=[[True, 'Accept'], [False, 'Reject']], label='3. With 50% chance you lose 3000 points. With 50% chance you win 6000 points..', widget=widgets.RadioSelectHorizontal) Gamble_4 = models.BooleanField(choices=[[True, 'Accept'], [False, 'Reject']], label='4. With 50% chance you lose 4000 points. With 50% chance you win 6000 points.', widget=widgets.RadioSelectHorizontal) Gamble_5 = models.BooleanField(choices=[[True, 'Accept'], [False, 'Reject']], label='5. With 50% chance you lose 5000 points. With 50% chance you win 6000 points..', widget=widgets.RadioSelectHorizontal) Gamble_6 = models.BooleanField(choices=[[True, 'Accept'], [False, 'Reject']], label='6. With 50% chance you lose 6000 points. With 50% chance you win 6000 points..', widget=widgets.RadioSelectHorizontal) Gamble_7 = models.BooleanField(choices=[[True, 'Accept'], [False, 'Reject']], label='7. With 50% chance you lose 7000 points. With 50% chance you win 6000 points..', widget=widgets.RadioSelectHorizontal) selected_gamble = models.IntegerField() selected_gamble_accept = models.BooleanField() win = models.BooleanField() choice_to_play = models.StringField() def sel_gamble_accept(player: Player): if player.selected_gamble == 1 and player.Gamble_1==True: player.selected_gamble_accept = True elif player.selected_gamble == 2 and player.Gamble_2 == True: player.selected_gamble_accept = True elif player.selected_gamble == 3 and player.Gamble_3== True: player.selected_gamble_accept = True elif player.selected_gamble == 4 and player.Gamble_4== True: player.selected_gamble_accept = True elif player.selected_gamble == 5 and player.Gamble_5== True: player.selected_gamble_accept = True elif player.selected_gamble == 6 and player.Gamble_6== True: player.selected_gamble_accept = True elif player.selected_gamble == 7 and player.Gamble_7== True: player.selected_gamble_accept = True else: player.selected_gamble_accept = False def sel_gamble_win(player: Player): if player.selected_gamble_accept== True and player.win == False: if player.selected_gamble == 1: player.payoff = -C.G1_LOSS if player.selected_gamble == 2: player.payoff = -C.G2_LOSS if player.selected_gamble == 3: player.payoff = -C.G3_LOSS if player.selected_gamble == 4: player.payoff = -C.G4_LOSS if player.selected_gamble == 5: player.payoff = -C.G5_LOSS if player.selected_gamble == 6: player.payoff = -C.G6_LOSS if player.selected_gamble == 7: player.payoff = -C.G7_LOSS elif player.selected_gamble_accept and player.win == True: player.payoff = C.REWARD else: player.payoff = 0 def random_realizations(player: Player): import random player.selected_gamble = random.randint(1, 7) player.win = random.randint(0,1) Player.sel_gamble_accept = sel_gamble_accept Player.sel_gamble_win = sel_gamble_win Player.random_realizations = random_realizations class Loss_aversion(Page): form_model = 'player' form_fields = ['Gamble_1', 'Gamble_2', 'Gamble_3', 'Gamble_4', 'Gamble_5', 'Gamble_6', 'Gamble_7'] @staticmethod def before_next_page(player: Player, timeout_happened): player.random_realizations() player.sel_gamble_accept() player.sel_gamble_win() if player.selected_gamble_accept == True: player.choice_to_play = "Accept" else: player.choice_to_play = "Reject" class Result(Page): form_model = 'player' page_sequence = [Loss_aversion, Result]