from otree.api import * c = cu doc = '' class Constants(BaseConstants): name_in_url = 'first_price_10group' players_per_group = 8 num_rounds = 10 def before_session(subsession): session = subsession.session if subsession.round_number == 1: subsession.group_randomly() else: subsession.group_like_round(1) class Subsession(BaseSubsession): pass def set_payoff(group): highest = 0 winner_collection = [] for p in group.get_players(): if p.bid > highest: highest = p.bid for p in group.get_players(): if p.bid == highest: p.winner = True winner_collection.append(p.id_in_group) else: p.winner = False if len(winner_collection) > 1: group.mult_win = True for p in group.get_players(): if p.winner == True: p.payoff = p.cert_price - highest p.endowment = p.endowment + p.participant.payoff group.winner = p.id_in_group group.winning_bid = p.bid else: p.payoff = 0 p.endowment = p.endowment + p.participant.payoff def assiign_value(group): for p in group.get_players(): set_cert(p) class Group(BaseGroup): winner = models.IntegerField() mult_win = models.BooleanField() winning_bid = models.CurrencyField() def set_cert(player): import random player.cert_price = random.randrange(0,100,1) class Player(BasePlayer): bid = models.CurrencyField(max=100, min=0) cert_price = models.CurrencyField() winner = models.BooleanField() id_n = models.IntegerField(label='What is your ID number for this class?') endowment = models.CurrencyField(initial=100) class Instructions(Page): form_model = 'player' @staticmethod def is_displayed(player): if player.round_number==1: return True class IDPage(Page): form_model = 'player' form_fields = ['id_n'] @staticmethod def is_displayed(player): if player.round_number==1: return True class Value(WaitPage): after_all_players_arrive = assiign_value class Bid(Page): form_model = 'player' form_fields = ['bid'] class ResultsWaitPage(WaitPage): after_all_players_arrive = set_payoff class Results(Page): form_model = 'player' class Final_results(Page): form_model = 'player' @staticmethod def is_displayed(player): if player.round_number==Constants.num_rounds: return True page_sequence = [Instructions, IDPage, Value, Bid, ResultsWaitPage, Results, Final_results]