from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) import random author = 'Your name here' doc = """ Your app description """ class Constants(BaseConstants): name_in_url = 'pgg' players_per_group = 3 num_rounds = 4 alpha = 2 #endowment = c(20) #allows to change currency of unit switching_rounds = [1, 3] lb = 50 ub = 150 class Subsession(BaseSubsession): #this creates the on and off button for def creating_session(self): for i in self.get_players(): #if self.round_number == 1: this command is only when you want the random endowment to be only in the first round if self.session.config.get('hetero_endowment'): #other way of writing if hetero_endowment is true i.endowment = random.randint(Constants.lb, Constants.ub) else: i.endowment = c(100) #else: #i.endowment = i.in_round(1).endowment #again use this only when the hetero of endowment is in the first round class Group(BaseGroup): total_contribution = models.CurrencyField() individual_share = models.CurrencyField() average_contribution = models.CurrencyField() #returning_amount = models.CurrencyField(min=0) def set_payoffs(self): self.total_contribution = sum([p.contribution for p in self.get_players()]) self.average_contribution = self.total_contribution / Constants.players_per_group self.individual_share = Constants.alpha * self.average_contribution for p in self.get_players(): p.payoff = p.endowment - p.contribution + self.individual_share #def set_statistics(self): class Player(BasePlayer): endowment = models.CurrencyField() contribution = models.CurrencyField(min=0)