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_real_v2' 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()]) def make_field(label): return models.IntegerField( choices=[ [1, 'very slightly or not at all'], [2, 'a little'], [3, 'moderately'], [4, 'quite a bit'], [5, "extremely"] ], label=label, widget=widgets.RadioSelect, ) class Player(BasePlayer): contribution = models.CurrencyField( min=0, max=Constants.endowment, doc="""The amount contributed by the player""", ) e1 = make_field("I feel guilty.") e2 = make_field("I feel angry.") e3 = make_field("I feel proud.") restoration = models.CurrencyField(min=0) def restoration_max(self): return sum([p.contribution for p in self.in_all_rounds()])