from otree.api import * doc = """ Разыгрывается бесплатный комплексный обед в столовой Вышки, цена которого {{ Constants.price }}. Все делают ставки в закрытую. Бесплатный обед получает тот, кто назовет наибольшую сумму. Платит всю ставку тот, кто назовет вторую по величине сумму. Деньги сверх цены на обед пойдут «на улучшение сервиса столовой». Если ставки не хватит, то получатель обеда оставшуюся часть покроет сам (аки «обед со скидкой»). """ class Constants(BaseConstants): price = cu(175) name_in_url = 'auction_1000' players_per_group = 100 num_rounds = 1 instructions_template = 'auction_1000/instructions.html' class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): bid = models.CurrencyField(min=0) winning_id = models.IntegerField() winning_bid = models.CurrencyField() losing_id = models.IntegerField() losing_bid = models.CurrencyField() # FUNCTIONS def set_payoffs(group: Group): players = group.get_players() first_max_idx = 0 second_max_idx = 1 for i in range(1, len(players)): if players[i].bid > players[first_max_idx].bid: second_max_idx = first_max_idx first_max_idx = i elif players[i].bid > players[second_max_idx].bid: second_max_idx = i for i in range(len(players)): players[i].payoff = 0 players[i].winning_id = players[first_max_idx].id_in_group players[i].winning_bid = players[first_max_idx].bid players[i].losing_id = players[second_max_idx].id_in_group players[i].losing_bid = players[second_max_idx].bid players[first_max_idx].payoff = min(Constants.price, players[second_max_idx].bid) players[second_max_idx].payoff = -players[second_max_idx].bid def other_player(player: Player): return player.get_others_in_group()[0] # PAGES class Introduction(Page): pass class Decision(Page): form_model = 'player' form_fields = ['bid'] class BeforeWait(Page): pass class ResultsWaitPage(WaitPage): after_all_players_arrive = set_payoffs class Results(Page): pass page_sequence = [Introduction, Decision, BeforeWait, ResultsWaitPage, Results]