from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) author = 'Your name here' doc = """ Your app description """ class Constants(BaseConstants): name_in_url = 'my_public_goods' players_per_group = 4 num_rounds = 10 endowment = c(20) multiplier = 1.4 class Subsession(BaseSubsession): pass class Group(BaseGroup): total_contribution = models.CurrencyField() individual_share = models.CurrencyField() def set_payoffs(self): players = self.get_players() contributions = [p.contribution for p in players] self.total_contribution = sum(contributions) self.individual_share = self.total_contribution * Constants.multiplier / Constants.players_per_group for p in self.get_players(): p.payoff = Constants.endowment - p.contribution + self.individual_share class Player(BasePlayer): contribution = models.CurrencyField(min=0, max=Constants.endowment) gender = models.StringField(choices=["Male", "Female", "Other"], blank=True) breakfast_this_morning = models.BooleanField(blank=True) breakfast_usually = models.BooleanField(blank=True)