from otree.api import * c = cu doc = '测试公共物品投资' class C(BaseConstants): NAME_IN_URL = 'Public_Good' PLAYERS_PER_GROUP = 3 NUM_ROUNDS = 2 ENDOW = cu(100) MULTIPLIER = 2 class Subsession(BaseSubsession): pass class Group(BaseGroup): total_contribution = models.CurrencyField() individual_share = models.CurrencyField() def set_payoffs(group: Group): players = group.get_players() contributions = [p.contribution for p in players] group.total_contribution = sum(contributions) group.individual_share = ( group.total_contribution * C.MULTIPLIER / C.PLAYERS_PER_GROUP ) for p in players: p.payoff = C.ENDOW - p.contribution + group.individual_share class Player(BasePlayer): contribution = models.CurrencyField(label='你打算捐款多少给公共池?', max=C.ENDOW, min=0) class Introduction(Page): form_model = 'player' class Contribution(Page): form_model = 'player' form_fields = ['contribution'] timeout_seconds = 60 class MyWaitPage(WaitPage): after_all_players_arrive = set_payoffs class Res(Page): form_model = 'player' page_sequence = [Introduction, Contribution, MyWaitPage, Res]