from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) import random # from numpy.random import choice from math import floor author = 'Wang Song' doc = """ NTUEXP: Holt Laury Risk Elicitation """ class Constants(BaseConstants): name_in_url = 'holtlaury_t7' players_per_group = None num_rounds = 1 # dollar_per_ecu = 0.05 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): d0 = models.IntegerField( blank=True, choices=[ [1, '100 points'], [2, '300 points with 0% chance, 0 point with 100% chance.'], ], widget=widgets.RadioSelect, ) d1 = models.IntegerField( blank=True, choices=[ [1, '100 points'], [2, '300 points with 10% chance, 0 point with 90% chance.'], ], widget=widgets.RadioSelect, ) d2 = models.IntegerField( blank=True, choices=[ [1, '100 points'], [2, '300 points with 20% chance, 0 point with 80% chance.'], ], widget=widgets.RadioSelect, ) d3 = models.IntegerField( blank=True, choices=[ [1, '100 points'], [2, '300 points with 30% chance, 0 point with 70% chance.'], ], widget=widgets.RadioSelect, ) d4 = models.IntegerField( blank=True, choices=[ [1, '100 points'], [2, '300 points with 40% chance, 0 point with 60% chance.'], ], widget=widgets.RadioSelect, ) d5 = models.IntegerField( blank=True, choices=[ [1, '100 points'], [2, '300 points with 50% chance, 0 point with 50% chance.'], ], widget=widgets.RadioSelect, ) d6 = models.IntegerField( blank=True, choices=[ [1, '100 points'], [2, '300 points with 60% chance, 0 point with 40% chance.'], ], widget=widgets.RadioSelect, ) d7 = models.IntegerField( blank=True, choices=[ [1, '100 points'], [2, '300 points with 70% chance, 0 point with 30% chance.'], ], widget=widgets.RadioSelect, ) d8 = models.IntegerField( blank=True, choices=[ [1, '100 points'], [2, '300 points with 80% chance, 0 point with 20% chance.'], ], widget=widgets.RadioSelect, ) d9 = models.IntegerField( blank=True, choices=[ [1, '100 points'], [2, '300 points with 90% chance, 0 point with 10% chance.'], ], widget=widgets.RadioSelect, ) picked_d = models.IntegerField() decision = models.IntegerField() def set_payoff(self): self.picked_d = random.randint(0, 9) if self.picked_d == 0: d = self.d0 elif self.picked_d == 1: d = self.d1 elif self.picked_d == 2: d = self.d2 elif self.picked_d == 3: d = self.d3 elif self.picked_d == 4: d = self.d4 elif self.picked_d == 5: d = self.d5 elif self.picked_d == 6: d = self.d6 elif self.picked_d == 7: d = self.d7 elif self.picked_d == 8: d = self.d8 else: d = self.d9 self.decision = d if d == 1: self.payoff = c(100) # *Constants.dollar_per_ecu else: prob = self.picked_d*0.1 # draw = choice([60, 0], p=[prob, 1-prob]) r = random.random() if r < prob: draw = c(300) else: draw = c(0) self.payoff = draw # *Constants.dollar_per_ecu self.participant.vars['PayoffT7'] = self.payoff # TESTING: rounding at Holt Laury # participant_payoff = self.participant.payoff # if participant_payoff - floor(participant_payoff) >= 0.5: # self.participant.payoff = floor(participant_payoff) + 1 # else: # self.participant.payoff = floor(participant_payoff)