from otree.api import * class C(BaseConstants): NAME_IN_URL = 'public_goods_game1' PLAYERS_PER_GROUP = 4 NUM_ROUNDS = 5 TOT_ROUNDS = 10 ENDOWMENT = cu(200) MULTIPLIER = 3 SHARE = 0.75 class Subsession(BaseSubsession): pass class Group(BaseGroup): total_contribution = models.CurrencyField() return_contribution = models.CurrencyField() individual_share = models.CurrencyField() class Player(BasePlayer): contribution = models.CurrencyField( min=0, max=C.ENDOWMENT, label="Berapa banyak points yang akan Anda kontribusikan ke dalam kelompok untuk membangun jembatan?" ) # FUNCTIONS def creating_session(subsession: Subsession): subsession.group_randomly() def set_payoffs(group: Group): players = group.get_players() contributions = [p.contribution for p in players] group.total_contribution = sum(contributions) group.return_contribution = (group.total_contribution * C.MULTIPLIER) group.individual_share = ( group.total_contribution * C.MULTIPLIER / C.PLAYERS_PER_GROUP ) for p in players: p.payoff = (C.ENDOWMENT - p.contribution + group.individual_share) # PAGES class Instructions(Page): @staticmethod def is_displayed(player): return player.round_number == 1 class Contribute(Page): form_model = 'player' form_fields = ['contribution'] class ResultsWaitPage(WaitPage): after_all_players_arrive = set_payoffs class Results(Page): @staticmethod def vars_for_template(player): total = player.payoff return dict( total=total ) page_sequence = [Instructions, Contribute, ResultsWaitPage, Results]