from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) doc = """ This is a one-period global warming game with 3 players. """ class Constants(BaseConstants): name_in_url = 'global_warming3' players_per_group = 5 num_rounds = 3 instructions_template = 'global_warming3/instructions.html' # """Amount allocated to each player""" multiplier = 4 class ConstantsSmall(Constants): endowment = c(1) class ConstantsMiddle(Constants): endowment = c(2) class ConstantsLarge(Constants): endowment = c(3) class Subsession(BaseSubsession): def creating_session(self): if self.round_number == 1: self.group_randomly() else: self.group_like_round(1) 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)', ) class Player(BasePlayer): contribution_small = models.CurrencyField( min=0, max = 1, doc="""The amount contributed by the player""", label="あなたは何枚カードを手放し、環境保全に貢献しますか?(0枚〜1枚)" ) contribution_middle = models.CurrencyField( min=0, max = 2, doc="""The amount contributed by the player""", label="あなたは何枚カードを手放し、環境保全に貢献しますか?(0枚〜2枚)" ) contribution_large = models.CurrencyField( min=0, max = 3, doc="""The amount contributed by the player""", label="あなたは何枚カードを手放し、環境保全に貢献しますか?(0枚〜3枚)" ) contribution = models.CurrencyField() total_payoff = models.CurrencyField() private_benefit = models.CurrencyField() private_benefit4 = models.CurrencyField() club_benefit = models.CurrencyField() country_level = models.StringField() class Group(BaseGroup): individual_share = models.CurrencyField() sum_contribution = models.CurrencyField() total_contribution =models.CurrencyField() def set_payoffs(self): for p in self.get_players(): if p.id_in_group == 1 or p.id_in_group == 2: p.contribution_middle = c(0) p.contribution_large = c(0) elif p.id_in_group == 3: p.contribution_small = c(0) p.contribution_large = c(0) elif p.id_in_group == 4 or p.id_in_group == 5: p.contribution_middle = c(0) p.contribution_small = c(0) self.total_contribution = sum([p.contribution_small for p in self.get_players()]) + sum([p.contribution_middle for p in self.get_players()]) + sum([p.contribution_large for p in self.get_players()]) self.individual_share = ( self.total_contribution ) for p in self.get_players(): if p.id_in_group == 1: p.country_level = "小規模国A" elif p.id_in_group == 2: p.country_level = "小規模国B" elif p.id_in_group == 3: p.country_level = "中規模国C" elif p.id_in_group == 4: p.country_level = "大規模国D" else: p.country_level = "大規模国E" for p in self.get_players(): if p.id_in_group == 1 or p.id_in_group == 2: if p.contribution_small == ConstantsSmall.endowment: p.club_benefit = self.individual_share else: p.club_benefit= 0 p.payoff = (ConstantsSmall.endowment - p.contribution_small)*Constants.multiplier + self.individual_share + p.club_benefit p.private_benefit = ConstantsSmall.endowment - p.contribution_small p.private_benefit4 = p.private_benefit * 4 elif p.id_in_group == 3: if p.contribution_middle == ConstantsMiddle.endowment: p.club_benefit = self.individual_share else: p.club_benefit= 0 p.payoff = (ConstantsMiddle.endowment - p.contribution_middle)*Constants.multiplier + self.individual_share + p.club_benefit p.private_benefit = ConstantsMiddle.endowment - p.contribution_middle p.private_benefit4 = p.private_benefit * 4 elif p.id_in_group == 4 or p.id_in_group == 5: if p.contribution_large == ConstantsLarge.endowment: p.club_benefit = self.individual_share else: p.club_benefit= 0 p.payoff = (ConstantsLarge.endowment - p.contribution_large)*Constants.multiplier + self.individual_share + p.club_benefit p.private_benefit = ConstantsLarge.endowment - p.contribution_large p.private_benefit4 = p.private_benefit * 4 p.contribution = p.contribution_small + p.contribution_middle + p.contribution_large