from otree.api import * class C(BaseConstants): NAME_IN_URL = 'public_goods_simple' PLAYERS_PER_GROUP = 4 NUM_ROUNDS = 5 ENDOWMENT = 1000 MULTIPLIER = 1.8 INSTRUCTIONS_TEMPLATE = 'public_goods_simple/instructions.html' class Subsession(BaseSubsession): pass class Group(BaseGroup): total_contribution = models.FloatField() individual_share = models.FloatField() individual_multiplier = models.FloatField() class Player(BasePlayer): contribution = models.IntegerField( choices=[0, 100, 200, 300, 400, 500, 600,700, 800, 900, 1000], label="あなたの投資額を選択してください" ) payoff_float = models.FloatField() # FUNCTIONS def set_multiplier(group: Group): group.individual_multiplier = C.MULTIPLIER / C.PLAYERS_PER_GROUP def set_payoffs(group: Group): players = group.get_players() contributions = [p.contribution for p in players] group.total_contribution = round(sum(contributions)) group.individual_share = round(group.total_contribution * C.MULTIPLIER / C.PLAYERS_PER_GROUP) for p in players: p.payoff_float = round(C.ENDOWMENT - p.contribution + group.individual_share) # PAGES class Introduction(Page): @staticmethod def is_displayed(player: Player): return player.round_number == 1 class Wait1(WaitPage): after_all_players_arrive = set_multiplier class Contribute(Page): form_model = 'player' form_fields = ['contribution'] class ResultsWaitPage(WaitPage): after_all_players_arrive = set_payoffs class Results(Page): pass page_sequence = [Wait1, Introduction, Contribute, ResultsWaitPage, Results]