from otree.api import * author = 'Your name here' doc = """ Your app description """ class Constants(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=Constants.budget, label="How much do you want to invest?" ) guess_contribution_other = models.FloatField( min=0, max=Constants.budget, label="How much do you think the other subject will invest" ) # FUNCTIONS # 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 * Constants.investment_factor class Results(Page): @staticmethod def vars_for_template(player: Player): player.payoff = ( Constants.budget - player.contribution ) + player.group.total_profit / Constants.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]