from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) author = 'Nanyin Yang' doc = """ Your app description """ class Constants(BaseConstants): name_in_url = 'observable_backup' players_per_group = None num_rounds = 5 class Subsession(BaseSubsession): pass class Group(BaseGroup): #pass def set_payoffs(self): for p in self.get_players(): p.set_payoff() class Player(BasePlayer): problem = models.IntegerField() private_signal = models.IntegerField() treatment_choice = models.IntegerField(widget=widgets.RadioSelect, choices=[0, 1], blank=True) # expert's choice of precision precision_choice = models.FloatField( choices = [ [0.5, "50%"], [0.6, "60%"], [0.7, "70%"], [0.8, "80%"], [0.9, "90%"], [1, "100%"], ], widget = widgets.RadioSelect, blank = True ) diagnostic_result = models.IntegerField() payment = models.FloatField() active1 = models.IntegerField( choices = [ [1, 'Make own decision & Pay 2 tokens'], [2, 'Follow the expert & Pay 0 tokens'], ], widget=widgets.RadioSelectHorizontal, label='Decision 1' ) active2 = models.IntegerField( choices = [ [1, 'Make own decision & Pay 1 tokens'], [2, 'Follow the expert & Pay 0 tokens'], ], widget=widgets.RadioSelectHorizontal, label='Decision 2' ) active3 = models.IntegerField( choices = [ [1, 'Make own decision & Pay 0 tokens'], [2, 'Follow the expert & Pay 0 tokens'], ], widget=widgets.RadioSelectHorizontal, label='Decision 3' ) active4 = models.IntegerField( choices = [ [1, 'Make own decision & Pay 0 tokens'], [2, 'Follow the expert & Pay 1 tokens'], ], widget=widgets.RadioSelectHorizontal, label='Decision 4' ) active5 = models.IntegerField( choices = [ [1, 'Make own decision & Pay 0 tokens'], [2, 'Follow the expert & Pay 2 tokens'], ], widget=widgets.RadioSelectHorizontal, label='Decision 5' ) activeness = models.IntegerField() activeness_chosen = models.IntegerField() def role(self): if self.id_in_group == 1: return 'player1' else: return 'player2' def set_payoff(self): if self.id_in_group == 1: self.payment = 12 - 10*(self.precision_choice - 0.5) ** 2 else: # patient's payment depends on his choice of treatment. And his choice of treatment depends on his activeness status. self.payment = 2+10*(1-abs((self.activeness == 1)*self.treatment_choice + (self.activeness ==2)* self.diagnostic_result - self.problem))+ (self.activeness_chosen == 1)*(abs(self.activeness - 2)*(-2)) + ((self.activeness_chosen == 1)*(abs(self.activeness - 2)*(-1))) + (self.activeness_chosen == 4)*(abs(self.activeness-1)*(-1)) + + (self.activeness_chosen == 5)*(abs(self.activeness-1)*(-2))