from otree.api import * doc = """ Your app description """ class C(BaseConstants): NAME_IN_URL = 'public_goods_templates' PLAYERS_PER_GROUP = 2 NUM_ROUNDS = 1 investment_factor = 1.5 budget = 10 class Subsession(BaseSubsession): pass class Group(BaseGroup): total_contribution = models.FloatField() total_profit = models.FloatField() class Player(BasePlayer): contribution = models.FloatField( min=0, max=C.budget, label="How much do you want to invest?" ) guess_contribution_other = models.FloatField( min=0, max=C.budget, label="How much do you think the other subject will invest" ) # PAGES class Contribution(Page): form_model = "player" form_fields = ["contribution", "guess_contribution_other"] class ResultsWaitPage(WaitPage): @staticmethod def after_all_players_arrive(group: Group): total_contribution = 0 for player in group.get_players(): total_contribution += player.contribution group.total_contribution = total_contribution group.total_profit = total_contribution * C.investment_factor class Results(Page): @staticmethod def vars_for_template(player: Player): player.payoff = ( C.budget - player.contribution ) + player.group.total_profit / C.players_per_group list_of_contributions = [player.contribution] for player in player.get_others_in_group(): list_of_contributions.append(player.contribution) return { "list_of_contributions": list_of_contributions, } page_sequence = [Contribution, ResultsWaitPage, Results]