from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) import random doc = """ group level of CPR in group 1' """ class Constants(BaseConstants): name_in_url = 'CPR_initial_100_mixed' players_per_group = 5 num_rounds = 5 endowment = c(4) class Subsession(BaseSubsession): def creating_session(self): print('in creating_session', self.round_number) paying_round = range(1, Constants.num_rounds, 1) self.session.vars['paying_round'] = paying_round class Group(BaseGroup): total_contribution = models.CurrencyField() def set_payoffs(self): if self.subsession.round_number in self.session.vars['paying_round']: self.total_contribution = sum([p.contribution for p in self.get_players()]) class Player(BasePlayer): contribution = models.CurrencyField( min=0, max=Constants.endowment, doc="""The amount contributed by the player""", ) fa_total_contribution = models.CurrencyField()