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 instructions_template = 'my_public_goods/InstructionsContribute.html' endowment = c(20) multiplier = 1.4 efficiency_factor = 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) how_hungry = models.CurrencyField (min=1, max=10) Q1 = models.StringField(choices=["16", "20", "24","28"]) Q2 = models.StringField(choices=["5", "7", "11", "18"]) Q3 = models.StringField(choices=["18", "20", "32", "41"])