from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) import random doc = """ Individual level of CPR in group 1' """ class Constants(BaseConstants): name_in_url = 'CPR_v2' players_per_group = 5 num_rounds = 1 endowment = c(20) 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""", ) answer1 = models.FloatField( min=2, max=2, doc="""The answer the player""", ) answer1_1 = models.FloatField( min=3, max=3, doc="""The answer the player""", ) answer2 = models.FloatField( min=2, max=2, doc="""The answer the player""", ) answer3 = models.FloatField( min=5, max=5, doc="""The answer the player""", ) answer4 = models.FloatField( min=2.5, max=2.5, doc="""The answer the player""", ) answer5 = models.FloatField( min=4.5, max=4.5, doc="""The answer the player""", ) answer6 = models.FloatField( min=2.5, max=2.5, doc="""The answer the player""", ) answer7 = models.FloatField( min=4, max=4, doc="""The answer the player""", )