from otree.api import * doc = """ Your app description """ class Constants(BaseConstants): name_in_url = 'investment_validation' players_per_group = None num_rounds = 1 budget = 100 investment_factor_1 = 1.2 investment_factor_2 = 1.5 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): amount_invested_1 = models.FloatField(label="How much do you want to invest in asset 1?") amount_invested_2 = models.FloatField(label="How much do you want to invest in asset 2?") money_after_investment = models.FloatField() # PAGES class Investment(Page): form_model = "player" form_fields = ["amount_invested_1", "amount_invested_2"] @staticmethod def before_next_page(player: Player, timeout_happened): player.money_after_investment = Constants.budget + player.amount_invested_1 * (Constants.investment_factor_1 - 1) + player.amount_invested_2 * (Constants.investment_factor_2 - 1) @staticmethod def error_message(player: Player, values): total_investment = values["amount_invested_1"] + values["amount_invested_2"] if total_investment > Constants.budget: return "You tried to invest " + str(total_investment) + " which is above your budget of " + str(Constants.budget) + "." class Results(Page): pass page_sequence = [Investment, Results]