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 = """ Holt Laury Risk Elicitation """ class Constants(BaseConstants): name_in_url = 'holtlaury' 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, '20 ECUs'], [2, '60 ECUs with 0% chance, 0 ECUs with 100% chance.'], ], widget=widgets.RadioSelect, ) d1 = models.IntegerField( blank=True, choices=[ [1, '20 ECUs'], [2, '60 ECUs with 10% chance, 0 ECUs with 90% chance.'], ], widget=widgets.RadioSelect, ) d2 = models.IntegerField( blank=True, choices=[ [1, '20 ECUs'], [2, '60 ECUs with 20% chance, 0 ECUs with 80% chance.'], ], widget=widgets.RadioSelect, ) d3 = models.IntegerField( blank=True, choices=[ [1, '20 ECUs'], [2, '60 ECUs with 30% chance, 0 ECUs with 70% chance.'], ], widget=widgets.RadioSelect, ) d4 = models.IntegerField( blank=True, choices=[ [1, '20 ECUs'], [2, '60 ECUs with 40% chance, 0 ECUs with 60% chance.'], ], widget=widgets.RadioSelect, ) d5 = models.IntegerField( blank=True, choices=[ [1, '20 ECUs'], [2, '60 ECUs with 50% chance, 0 ECUs with 50% chance.'], ], widget=widgets.RadioSelect, ) d6 = models.IntegerField( blank=True, choices=[ [1, '20 ECUs'], [2, '60 ECUs with 60% chance, 0 ECUs with 40% chance.'], ], widget=widgets.RadioSelect, ) d7 = models.IntegerField( blank=True, choices=[ [1, '20 ECUs'], [2, '60 ECUs with 70% chance, 0 ECUs with 30% chance.'], ], widget=widgets.RadioSelect, ) d8 = models.IntegerField( blank=True, choices=[ [1, '20 ECUs'], [2, '60 ECUs with 80% chance, 0 ECUs with 20% chance.'], ], widget=widgets.RadioSelect, ) d9 = models.IntegerField( blank=True, choices=[ [1, '20 ECUs'], [2, '60 ECUs with 90% chance, 0 ECUs 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 = 20*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 = 60 else: draw = 0 self.payoff = draw*Constants.dollar_per_ecu # comment out in case server break down: #self.participant.payoff = self.payoff + self.participant.vars['game1_payoff'] + self.participant.vars['game2_payoff'] self.participant.vars['game3_payoff'] = self.payoff # TESTING: rounding at Holt Laury #self.participant.payoff = ceil(self.participant.payoff) 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)