from otree.api import ( Page, WaitPage, models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) import random #c = Currency doc = """ Control Group """ class Constants(BaseConstants): name_in_url = 'project' players_per_group = None num_rounds = 5 #instructions_template = 'project/instructions.html' 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() 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() # FUNCTIONS def creating_session(subsession: Subsession): pass #for g in subsession.get_groups(): #import random #item_value = random.uniform( #Constants.min_allowable_bid, Constants.max_allowable_bid #) #g.item_value = round(item_value, 1) def generate_value_estimate(group: Group): pass #import random #minimum = group.item_value - Constants.estimate_error_margin #maximum = group.item_value + Constants.estimate_error_margin #estimate = random.uniform(minimum, maximum) #estimate = round(estimate, 1) #if estimate < Constants.min_allowable_bid: #estimate = Constants.min_allowable_bid #if estimate > Constants.max_allowable_bid: #estimate = Constants.max_allowable_bid #return estimate def set_payoff(player: Player): player.payoff = 10*(player.bid_amount + player.bid_amount) - player.bid_amount * player.bid_amount def vars_for_template(player: Player): pass # PAGES class instructions(Page): pass #@staticmethod #def before_next_page(player: Player, timeout_happened): #group = player.group #player.item_value_estimate = generate_value_estimate(group) class Bid(Page): form_model = 'player' form_fields = ['bid_amount'] class Results(Page): #@staticmethod def vars_for_template(player: Player): set_payoff(player) player.benefits = 10 * player.bid_amount + 50 if player.benefits > 100: player.benefits = 100 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]