from otree.api import * c = cu doc = '' class C(BaseConstants): NAME_IN_URL = 'Police_Experiment_Controll_Group2' PLAYERS_PER_GROUP = 5 NUM_ROUNDS = 1 GENERAL_BENEFIT = cu(10) VOLUNTEER_COST = cu(5) NUM_OTHER_PLAYERS = 4 class Subsession(BaseSubsession): pass class Group(BaseGroup): num_volunteers = models.IntegerField() def set_payoffs(group: Group): players = group.get_players() group.num_volunteers = sum ([p.volunteer for p in players]) if group.num_volunteers > 0: baseline_amount = C.GENERAL_BENEFIT else: baseline_amount = cu(0) victim_payoff = -5 for p in players: if p.id_in_group != 5: p.payoff = baseline_amount if p.volunteer: p.payoff -= C.VOLUNTEER_COST else: p.payoff = victim_payoff class Player(BasePlayer): volunteer = models.BooleanField(choices=[[True, 'Yes'], [False, 'No']], initial=False, label='Do you call the police?', widget=widgets.RadioSelect) def victim(player: Player): group = player.group if player.id_in_group == 5 : player.is_victim = True class Instructions(Page): form_model = 'player' class Distribution_of_roles(Page): form_model = 'player' class Decision(Page): form_model = 'player' form_fields = ['volunteer'] @staticmethod def is_displayed(player: Player): group = player.group return player.id_in_group != 5 @staticmethod def before_next_page(player: Player, timeout_happened): group = player.group if player.id_in_group == 5 : return player.skip_next_page() class MyWaitPage(WaitPage): after_all_players_arrive = set_payoffs title_text = 'WaitPage' body_text = 'Please wait until the other players have made a decision.' class Results(Page): form_model = 'player' page_sequence = [Instructions, Distribution_of_roles, Decision, MyWaitPage, Results]