from otree.api import * c = cu doc = '' class C(BaseConstants): NAME_IN_URL = 'ParticipationGame1_Test' PLAYERS_PER_GROUP = 4 NUM_ROUNDS = 1 PARTICIPATION_COSTS = 10 PEAK_PD1_1 = 5 PEAK_PD1_2 = 10 PEAK_PD1_3 = 90 PEAK_PD1_4 = 95 PARTICIPATION_COST = cu(10) class Subsession(BaseSubsession): pass class Group(BaseGroup): MEAN_OF_VOTES = models.FloatField() total_contribution = models.CurrencyField() Participation_Player1 = models.BooleanField() Participation_Player2 = models.BooleanField() Participation_Player3 = models.BooleanField() Participation_Player4 = models.BooleanField() Result = models.FloatField() Number_of_Participants = models.IntegerField() Peak1 = models.CurrencyField(initial=C.PEAK_PD1_1) Peak2 = models.CurrencyField(initial=C.PEAK_PD1_2) Peak3 = models.CurrencyField(initial=C.PEAK_PD1_3) Peak4 = models.CurrencyField(initial=C.PEAK_PD1_4) Result_CU = models.CurrencyField() def ParticipationDecisions(group: Group): player1 = group.get_player_by_id(1) group.Participation_Player1 = player1.PARTICIPATION_DECISION_1 player1.ACTUAL_PARTICIPATION = player1.PARTICIPATION_DECISION_1 player2 = group.get_player_by_id(2) group.Participation_Player2 = player2.PARTICIPATION_DECISION_2 player2.ACTUAL_PARTICIPATION = player2.PARTICIPATION_DECISION_2 player3 = group.get_player_by_id(3) group.Participation_Player3 = player3.PARTICIPATION_DECISION_3 player3.ACTUAL_PARTICIPATION = player3.PARTICIPATION_DECISION_3 player4 = group.get_player_by_id(4) group.Participation_Player4 = player4.PARTICIPATION_DECISION_4 player4.ACTUAL_PARTICIPATION = player4.PARTICIPATION_DECISION_4 group.Number_of_Participants = player1.ACTUAL_PARTICIPATION + player2.ACTUAL_PARTICIPATION + player3.ACTUAL_PARTICIPATION + player4.ACTUAL_PARTICIPATION def results_mean(group: Group): votes = [player.Vote for player in group.get_players()] if group.Number_of_Participants == 0: for player in group.get_players(): player.payoff = 0 if group.Number_of_Participants >0: group.Result = sum(votes)/group.Number_of_Participants group.Result_CU=group.Result player1 = group.get_player_by_id(1) player1.payoff = 110 - abs(group.Result - group.Peak1) - player1.ACTUAL_PARTICIPATION * 10 player2 = group.get_player_by_id(2) player2.payoff = 110 - abs(group.Result - group.Peak2) - player2.ACTUAL_PARTICIPATION * 10 player3 = group.get_player_by_id(3) player3.payoff = 110 - abs(group.Result - group.Peak3) - player3.ACTUAL_PARTICIPATION * 10 player4 = group.get_player_by_id(4) player4.payoff = 110 - abs(group.Result - group.Peak4) - player4.ACTUAL_PARTICIPATION * 10 class Player(BasePlayer): PARTICIPATION_DECISION_1 = models.BooleanField(choices=[[True, 'Yes'], [False, 'No']], initial=False, label='Do you want to participate with Peak 1 (Voting comes with a cost of 10 CU)?') PARTICIPATION_DECISION_2 = models.BooleanField(initial=False, label='Do you want to participate with Peak 2 (Voting comes with a cost of 10 CU)?') PARTICIPATION_DECISION_3 = models.BooleanField(initial=False, label='Do you want to participate with Peak 3 (Voting comes with a cost of 10 CU)?') PARTICIPATION_DECISION_4 = models.BooleanField(initial=False, label='Do you want to participate with Peak 4 (Voting comes with a cost of 10 CU)?') Vote = models.FloatField(initial=0, max=100, min=0) ACTUAL_PARTICIPATION = models.BooleanField(initial=False) Guess = models.FloatField(label='What outcome do you expect?', max=100, min=0) Endowment = models.CurrencyField(initial=110) class ParticipationDecision(Page): form_model = 'player' form_fields = ['PARTICIPATION_DECISION_1', 'PARTICIPATION_DECISION_2', 'PARTICIPATION_DECISION_3', 'PARTICIPATION_DECISION_4'] class MyWaitPage_AfterParticipation(WaitPage): after_all_players_arrive = ParticipationDecisions class VotingStageParticipants(Page): form_model = 'player' form_fields = ['Vote', 'Guess'] @staticmethod def is_displayed(player: Player): return player.ACTUAL_PARTICIPATION == 1 class VotingPageAbstentions(Page): form_model = 'player' form_fields = ['Guess'] @staticmethod def is_displayed(player: Player): return player.ACTUAL_PARTICIPATION == 0 class MyWaitPage_AfterVoting(WaitPage): after_all_players_arrive = results_mean class Results(Page): form_model = 'player' page_sequence = [ParticipationDecision, MyWaitPage_AfterParticipation, VotingStageParticipants, VotingPageAbstentions, MyWaitPage_AfterVoting, Results]