from otree.api import ( Page, WaitPage, models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) doc = """ Trial for Treatment 1 """ class Constants(BaseConstants): name_in_url = 'project_treat1trial' players_per_group = 2 num_rounds = 3 min_allowable_bid = c(0) max_allowable_bid = c(10) # Error margin for the value estimates shown to the players # estimate_error_margin = c(1) class Subsession(BaseSubsession): pass class Group(BaseGroup): item_value = models.CurrencyField( doc="""Common value of the item to be auctioned, random for treatment""" ) highest_bid = models.CurrencyField() benefits = models.CurrencyField() total_benefits = models.CurrencyField() good_doctors_best_rate = models.CurrencyField() bad_doctors_best_rate = models.CurrencyField() num_winner = models.CurrencyField() best_rate = models.CurrencyField() class Player(BasePlayer): #item_value_estimate = models.CurrencyField( #doc="""Estimate of the common value, may be different for each player""" #) bid_amount = models.IntegerField( min=Constants.min_allowable_bid, max=Constants.max_allowable_bid, doc="""Amount prescribed by the player""", label="Treatment amount", ) is_winner = models.BooleanField( initial=False, doc="""Indicates whether the player is the winner""" ) benefits = models.CurrencyField() total_benefits = models.CurrencyField() money = models.CurrencyField() total_money = models.CurrencyField() good_doctors_best_rate = models.CurrencyField() bad_doctors_best_rate = models.CurrencyField() # FUNCTIONS def creating_session(subsession: Subsession): pass def set_winner(group: Group): pass def generate_value_estimate(group: Group): pass def set_payoff(player: Player): group = player.group if player.round_number==1: if player.bid_amount > 3: player.payoff = 2 * (10 * (player.bid_amount + player.bid_amount) - player.bid_amount * player.bid_amount) group.num_winner = 1 if player.bid_amount < 3: player.payoff =0 if player.bid_amount == 3: player.payoff = 10 * (player.bid_amount + player.bid_amount) - player.bid_amount * player.bid_amount group.num_winner = 2 if player.round_number==2: if player.bid_amount > 5: player.payoff = 0 if player.bid_amount < 5: player.payoff = 0 if player.bid_amount == 5: player.payoff = 10 * (player.bid_amount + player.bid_amount) - player.bid_amount * player.bid_amount group.num_winner = 2 if player.round_number == 3: if player.bid_amount > 7: player.payoff = 0 if player.bid_amount < 5: player.payoff = 0 if player.bid_amount == 5: player.payoff = 2 * (10 * (player.bid_amount + player.bid_amount) - player.bid_amount * player.bid_amount) group.num_winner = 1 if player.bid_amount == 6: player.payoff = 2 * (10 * (player.bid_amount + player.bid_amount) - player.bid_amount * player.bid_amount) group.num_winner = 1 if player.bid_amount == 7: player.payoff = 10 * (player.bid_amount + player.bid_amount) - player.bid_amount * player.bid_amount group.num_winner = 2 # PAGES class Introduction(Page): pass class Bid(Page): form_model = 'player' form_fields = ['bid_amount'] class ResultsWaitPage(WaitPage): after_all_players_arrive = 'set_winner' class Results(Page): #@staticmethod def vars_for_template(player: Player): set_payoff(player) group = player.group if player.payoff>0: if group.num_winner == 1: player.benefits = 2 * (10 * player.bid_amount + 50) if player.benefits > 200: player.benefits = 200 else: player.benefits = 10 * player.bid_amount + 50 if player.benefits > 100: player.benefits = 100 else: player.benefits = 0 player.total_benefits = player.benefits if player.round_number>1: player.total_benefits = player.benefits + sum([p.benefits for p in player.in_previous_rounds()]) player.money = player.payoff player.total_money = player.money if player.round_number > 1: player.total_money = player.money + sum([p.money for p in player.in_previous_rounds()]) page_sequence = [Bid, Results]