from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) author = 'LBouman' doc = """ SPG """ class Constants(BaseConstants): name_in_url = 'SPG' players_per_group = 5 num_rounds = 15 # in exp set to 15 for spg session decision page num_other_players = players_per_group - 1 general_benefit = c(15) investment_cost = c(10) class Subsession(BaseSubsession): share_distribution = models.StringField(initial="") information_condition = models.StringField(initial="") # group formation def creating_session(self): self.share_distribution = self.session.config['share_distribution'] # homogeneous / heterogeneous self.information_condition = self.session.config['information_condition'] # complete / incomplete if self.round_number == 1: self.group_randomly() else: self.group_like_round(1) # role assignment shares = {'heterogeneous': [1, 9, 20, 20, 50], 'homogeneous': [20, 20, 20, 20, 20]} for p in self.get_players(): p.share = shares[self.share_distribution][p.in_round(1).id_in_group - 1] class Group(BaseGroup): # SPG global group vars num_investors = models.IntegerField() sum_shares = models.IntegerField() def good_is_produced(self): players = self.get_players() self.num_investors = sum([p.invest for p in players]) self.sum_shares = sum([p.share for p in players if p.invest]) if self.sum_shares > 51: return True else: return False def set_payoffs(self): players = self.get_players() if self.good_is_produced(): baseline_amount = Constants.general_benefit else: baseline_amount = c(0) for p in players: p.payoff = baseline_amount if not p.invest: p.payoff += Constants.investment_cost class Player(BasePlayer): # SGP model code invest = models.BooleanField() share = models.IntegerField() # efficacy questions E1 = models.IntegerField(choices=[ [1, "1. Impossible"], [2, "2. Very unlikely"], [3, "3. Unlikely"], [4, "4. A 50/50 chance"], [5, "5. Likely"], [6, "6. Very likely"], [7, "7. Certain"], ], verbose_name="1. To what extent is your investment necessary to produce the group project? It is ... that my investment is necessary to produce the group project." ) E2 = models.IntegerField(choices=[ [1, "1. Impossible"], [2, "2. Very unlikely"], [3, "3. Unlikely"], [4, "4. A 50/50 chance"], [5, "5. Likely"], [6, "6. Very likely"], [7, "7. Certain"], ], verbose_name="2. To what extent is your investment sufficient to produce the group project? It is ... that my investment is sufficient to produce the group project. " ) E3 = models.IntegerField(choices=[ [1, "1. Impossible"], [2, "2. Very unlikely"], [3, "3. Unlikely"], [4, "4. A 50/50 chance"], [5, "5. Likely"], [6, "6. Very likely"], [7, "7. Certain"], ], verbose_name="3. To what extent does your investment determine whether or not the group project is produced? It is ... that my investment determines whether or not the group project is produced. " ) E4 = models.IntegerField(choices=[ [1, "1. Impossible"], [2, "2. Very unlikely"], [3, "3. Unlikely"], [4, "4. A 50/50 chance"], [5, "5. Likely"], [6, "6. Very likely"], [7, "7. Certain"], ], verbose_name="4. How likely do you think it is that another group member will invest? It is ... that another groupmember will invest." ) E5 = models.IntegerField(choices=[ [1, "1. Impossible"], [2, "2. Very unlikely"], [3, "3. Unlikely"], [4, "4. A 50/50 chance"], [5, "5. Likely"], [6, "6. Very likely"], [7, "7. Certain"], ], verbose_name="5. How likely do you think it is that the group project will be produced within your group?It is ... that the group project will be produced in my group. " )