from . import models from ._builtin import Page, WaitPage from otree.api import Currency as c, currency_range from .models import Constants class Introduction(Page): pass class Bid(Page): form_model = models.Player form_fields = ['reserve_price', 'chosen_capacity'] timeout_seconds = 240 def error_message(self, values): if values['chosen_capacity'] > self.player.maximal_capacity: return 'Выбранный объем больше, чем Ваши мощности могут произвести' if values['reserve_price'] < self.player.marginal_cost: return 'Продавать дешевле себестоимости невыгодно' if values['reserve_price'] > Constants.total_capacity/Constants.marginal_price: return 'Цена слишком высокая: никто не будет покупать Вашу энергию' def vars_for_template(self): p = self.player return { 'your_maximal_capacity': p.maximal_capacity, 'your_marginal_cost': p.marginal_cost, } def before_next_page(self): if self.timeout_happened: self.player.reserve_price = 0 self.player.maximal_capacity = 0 class ResultsWaitPage(WaitPage): body_text = "Подождем других..." def after_all_players_arrive(self): self.group.set_payoffs() class Results(Page): def vars_for_template(self): return { 'jumps': self.session.vars['jumps'], 'r_plus': self.session.vars['r_plus'], 'r_minus': self.session.vars['r_minus'], 'capacities': self.session.vars['capacities'], 'my_price': self.player.reserve_price, 'my_capacity': self.player.chosen_capacity, 'my_payoff': self.player.payoff, 'my_units': self.player.units, 'market_price': self.group.price, 'my_cost': self.player.marginal_cost, 'total_production': self.group.total_units } page_sequence = [Introduction, Bid, ResultsWaitPage, Results]