from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) import random doc = """ A demo of how rounds work in oTree, in the context of 'matching pennies' """ class Constants(BaseConstants): name_in_url = 'my_matching_pennies_INDIVIDUAL' players_per_group = 5 num_rounds = 5 endowment = c(100) 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=1, max=3, doc="""The amount contributed by the player""", )