from otree.api import * c = cu doc = '' class C(BaseConstants): NAME_IN_URL = 'survey' PLAYERS_PER_GROUP = 8 NUM_ROUNDS = 6 SETTINGS = [[6,3,2,4,5,1], [6,2,3,4,5,1], [6,3,2,4,5,1], [6,2,3,4,5,1], [6,3,2,5,4,1], [6,2,3,5,4,1], [6,3,2,5,4,1], [6,2,3,5,4,1]] groups = [[1,1,1,1,2,1], [1,2,2,1,2,1], [1,1,1,1,3,1], [1,2,2,1,3,1], [1,1,1,2,1,1], [1,2,2,2,1,1], [1,1,1,3,1,1], [1,2,2,3,1,1]] no_a1 = [12,15,16,17,17,15] no_a2 = [8,4,4,4,2,8] no_groups = [1,2,2,3,3,1] no_b = [18,18,18,18,18,18] class Subsession(BaseSubsession): pass def compute_payoff(subsession: Subsession): for i in range(1,C.NUM_ROUNDS + 1): player_list = subsession.in_round(i).get_players() group_amount = C.no_groups[i - 1] votes_for_a1 = [0 for i in range(0,group_amount)] votes_for_b = [0 for i in range(0,group_amount)] for p in player_list: for g in range(0,group_amount): if C.groups[p.id_in_group - 1][p.round_number - 1] - 1 == g: p.group_mod = g if p.vote == 1: votes_for_a1[g] += 1 if p.vote == 3: votes_for_b[g] += 1 for p in player_list: setting = C.SETTINGS[p.id_in_group - 1][p.round_number - 1] - 1 p.votes_for_a1 = votes_for_a1[C.groups[p.id_in_group - 1][p.round_number - 1] - 1] p.no_a1 = C.no_a1[setting] p.no_a2 = C.no_a2[setting] p.no_b = C.no_b[setting] if C.no_a1[setting] + p.votes_for_a1 > C.no_b[setting] + votes_for_b[C.groups[p.id_in_group - 1][p.round_number - 1] - 1]: p.taxes = 0.5 p.winning = "The professor's proposal" else: p.taxes = 4 p.winning = "The university direction's proposal" class Group(BaseGroup): pass class Player(BasePlayer): test = models.IntegerField(choices=[[0, '0'],[1, '1'],[2, '2'],[3, '3'],[4, '4'],[5, '5'],[6, '6'],[7, '7'],[8, '8'],[9, '9'],[10, '10']], initial=-1, label="This is a test question. How many votes can the students' propsal get at most in the setting above (full statement below)?", widget=widgets.RadioSelectHorizontal) test2 = models.CurrencyField(choices=[[0, '€0'],[0.5, '€0.50'],[4, '€4']], initial=-1, label='This is a another test question. Which amount of taxes do you think you will need to pay in this setting?', widget=widgets.RadioSelectHorizontal) winning = models.StringField() votes_for_a1 = models.IntegerField() taxes = models.CurrencyField() group_mod = models.IntegerField() no_a1 = models.IntegerField() no_a2 = models.IntegerField() no_b = models.IntegerField() vote = models.IntegerField(choices=[[1, "vote for the professors' proposal"], [2, "vote for the students' proposal"], [3, "vote for the university direction's proposal"]],initial=0, label='You may now choose one of the following actions:', widget=widgets.RadioSelect) belief = models.IntegerField(choices=[[0, '0']], initial=-1, label="In your opinion, how many of the other participants decided to vote for the professors' proposal?", widget=widgets.RadioSelectHorizontal) def belief_choices(player): setting = C.SETTINGS[player.id_in_group - 1][player.round_number - 1] - 1 choices = [] for i in range(0, C.no_a2[setting]): choices.append([i,str(i)]) return choices class Disclaimer(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): return player.round_number == 1 class Round1(Page): form_model = 'player' form_fields = ['test','test2'] timeout_seconds = 90 @staticmethod def is_displayed(player: Player): return player.round_number == 1 @staticmethod def vars_for_template(player): setting = C.SETTINGS[player.id_in_group - 1][player.round_number - 1] - 1 return dict( a1=C.no_a1[setting], a2=C.no_a2[setting], b=C.no_b[setting], ) class Round_other(Page): form_model = 'player' form_fields = ['vote'] timeout_seconds = 60 @staticmethod def vars_for_template(player): setting = C.SETTINGS[player.id_in_group - 1][player.round_number - 1] - 1 return dict( a1=C.no_a1[setting], a2=C.no_a2[setting], b=C.no_b[setting], ) class Elicit_beliefs(Page): form_model = 'player' form_fields = ['belief'] timeout_seconds = 45 class Wait_after_beliefs(WaitPage): wait_for_all_groups = True after_all_players_arrive = compute_payoff def is_displayed(player: Player): return player.round_number == C.NUM_ROUNDS class PayoffPage(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): return player.round_number == C.NUM_ROUNDS @staticmethod def vars_for_template(player): total_payoff = 22 amount_a2 = 0 for i in range(1,C.NUM_ROUNDS + 1): total_payoff -= player.in_round(i).taxes if player.in_round(i).vote == 2: total_payoff += 0.05 amount_a2 += 1 return dict( p0=player.in_round(1).taxes, p1=player.in_round(2).taxes, p2=player.in_round(3).taxes, p3=player.in_round(4).taxes, p4=player.in_round(5).taxes, p5=player.in_round(6).taxes, w0=player.in_round(1).winning, w1=player.in_round(2).winning, w2=player.in_round(3).winning, w3=player.in_round(4).winning, w4=player.in_round(5).winning, w5=player.in_round(6).winning, v0=player.in_round(1).votes_for_a1, v1=player.in_round(2).votes_for_a1, v2=player.in_round(3).votes_for_a1, v3=player.in_round(4).votes_for_a1, v4=player.in_round(5).votes_for_a1, v5=player.in_round(6).votes_for_a1, total=total_payoff, aa2=amount_a2, ) page_sequence = [Disclaimer, Round1, Round_other, Elicit_beliefs, Wait_after_beliefs, PayoffPage]