from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) doc = """ This is a public goods game with 4 players. """ class Constants(BaseConstants): name_in_url = 'public_goods_resettlement' players_per_group = 2 num_rounds = 1 instructions_template = 'public_goods/instructions.html' # """Amount allocated to each player""" multiplier = 1 endowment = 10 class Subsession(BaseSubsession): def vars_for_admin_report(self): contributions = [ p.contribution for p in self.get_players() if p.contribution != None ] if contributions: return dict( avg_contribution=sum(contributions) / len(contributions), min_contribution=min(contributions), max_contribution=max(contributions), ) else: return dict( avg_contribution='(no data)', min_contribution='(no data)', max_contribution='(no data)', ) earnings = [ p.earning for p in self.get_playes() if p.earning != None ] if earnings: return dict( avg_earning=sum(earnings) / len(earnings), min_earning=min(earnings), max_earning=max(earnings), ) else: return dict( avg_earning='(no data)', min_earning='(no data)', max_earning='(no data)', ) class Group(BaseGroup): total_contribution = models.CurrencyField() total_earning = models.CurrencyField() individual_share = models.CurrencyField() def set_payoffs(self): self.total_contribution = sum([p.contribution for p in self.get_players()]) self.total_earning = sum([p.earning for p in self.get_players()]) self.individual_share = (self.total_earning / Constants.players_per_group) for p in self.get_players(): p.payoff = Constants.endowment - p.contribution + p.earning + self.individual_share class Player(BasePlayer): contribution = models.CurrencyField( min=0, label='''How much do you want to contribute?''' ) earning = models.CurrencyField( label='''How much did you earn at the typing game?''' ) feelings1 = models.IntegerField( min=1, max=5, label='''Do you agree with the project even if you are told to miss a turn?(Disagree=1 Agree=5)''' ) feelings2 = models.IntegerField( min=1, max=5, label='''How do you feel?(Dissatisfied=1 Satisfied=5)''' ) feelings3 = models.IntegerField( min=1, max=5, label='''How do you feel?(Dissatisfied=1 Satisfied=5)''' ) Stealing_p_leader = models.IntegerField( min=0, max=20, label='''From the leader''' ) Stealing_p_A = models.IntegerField( min=0, max=20, label='''From Participant A''' ) Stealing_p_B = models.IntegerField( min=0, max=20, label='''From Parcitipant B''' ) def Stealing_p_C(self): for p in self.get_players(): p.Stealing_p_C = 20 - p.Stealing_p_leader - p.Stealing_p_A - p.Stealing_p_B