from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) class C(BaseConstants): NAME_IN_URL = 'public_goods_simple' PLAYERS_PER_GROUP = 3 NUM_ROUNDS = 5 ENDOWMENT = c(10) MULTIPLIER = 2 class Subsession(BaseSubsession): pass class Group(BaseGroup): total_contribution = models.CurrencyField() individual_share = models.CurrencyField() def set_payoffs(group): players = group.get_players() contributions = [p.contribution for p in players] group.total_contribution = sum(contributions) group.average_contribution = group.total_contribution / len(group.get_players()) group.individual_share = ( group.total_contribution * C.MULTIPLIER / C.PLAYERS_PER_GROUP ) for p in players: p.payoff = C.ENDOWMENT - p.contribution + group.individual_share class Player(BasePlayer): question1 = models.IntegerField(label="How many rounds are there in this game?") question2 = models.IntegerField(label=" What is the multiplier used in this game?") question3 = models.IntegerField(label="What is an endowment in this game?") contribution = models.CurrencyField(min=0, max=C.ENDOWMENT, label='How much do you want to contribute?')