from typing import List from otree.api import * import numpy as np doc = """ Public Goods No Leader/No Picture """ class C(BaseConstants): NAME_IN_URL = 'PGNLNP' PLAYERS_PER_GROUP = 4 ENDOWMENT = 10 CONT_NUM = 78 EFF_FACTOR = 2.4 LEADER_PAY_FACTOR = 0.25 NUM_ROUNDS = 100 BELIEF_REWARD = 0.25 # instructions_template = 'public_goods/instructions.html' # """Amount allocated to each player""" class Subsession(BaseSubsession): End_Experiment = models.BooleanField(initial=False) End_Experiment_round = models.IntegerField() Belief_pay_round = models.IntegerField() def creating_session(subsession: Subsession): if subsession.round_number == 1: subsession.group_randomly() rand_rolls = np.random.randint(0, 101, 100) subsession.session.vars['rand_rolls'] = rand_rolls else: subsession.group_like_round(1) # def vars_for_admin_report(subsession: Subsession): # contributions = [ # p.contribution # for p in subsession.get_players() # if get_or_none(p, 'contribution') != None # ] # if contributions: # return dict( # avg_contribution=sum(contributions) / len(contributions), # min_contribution=min(contributions), # max_contribution=max(contributions), # ) # else: # return dict( # avg_contribution='(no data)', # min_contribution='(no data)', # max_contribution='(no data)', # ) class Group(BaseGroup): total_contribution = models.IntegerField() individual_share = models.FloatField() total_vote_for_1 = models.IntegerField(initial=0) total_vote_for_2 = models.IntegerField(initial=0) total_vote_for_3 = models.IntegerField(initial=0) total_vote_for_4 = models.IntegerField(initial=0) new_order = list[int] punish_factor = models.FloatField(initial=0) group_punishment = models.IntegerField(initial=0) current_payoff_sum = models.FloatField(initial=0) class Player(BasePlayer): contribution = models.IntegerField( initial=0, min=0, max=C.ENDOWMENT, doc="""The amount contributed by the player""", ) # vote = models.IntegerField( # label='Place your vote. You may not vote for yourself.', # choices=[ # [1, 'Player 1'], # [2, 'Player 2'], # [3, 'Player 3'], # [4, 'Player 4'] # ] # ) # # vote_for_1 = models.IntegerField(initial=0) # vote_for_2 = models.IntegerField(initial=0) # vote_for_3 = models.IntegerField(initial=0) # vote_for_4 = models.IntegerField(initial=0) punishment = models.IntegerField( initial=0, label='How many punishment points would you like to give to your group?', choices=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] ) #Beliefs about what P5 contributed cont_belief_p1_c0 = models.IntegerField(min=0, initial=0) cont_belief_p1_c1 = models.IntegerField(min=0, initial=0) cont_belief_p1_c2 = models.IntegerField(min=0, initial=0) cont_belief_p1_c3 = models.IntegerField(min=0, initial=0) cont_belief_p1_c4 = models.IntegerField(min=0, initial=0) cont_belief_p1_c5 = models.IntegerField(min=0, initial=0) cont_belief_p1_c6 = models.IntegerField(min=0, initial=0) cont_belief_p1_c7 = models.IntegerField(min=0, initial=0) cont_belief_p1_c8 = models.IntegerField(min=0, initial=0) cont_belief_p1_c9 = models.IntegerField(min=0, initial=0) cont_belief_p1_c10 = models.IntegerField(min=0, initial=0) # Beliefs about what P2 contributed cont_belief_p2_c0 = models.IntegerField(min=0, initial=0) cont_belief_p2_c1 = models.IntegerField(min=0, initial=0) cont_belief_p2_c2 = models.IntegerField(min=0, initial=0) cont_belief_p2_c3 = models.IntegerField(min=0, initial=0) cont_belief_p2_c4 = models.IntegerField(min=0, initial=0) cont_belief_p2_c5 = models.IntegerField(min=0, initial=0) cont_belief_p2_c6 = models.IntegerField(min=0, initial=0) cont_belief_p2_c7 = models.IntegerField(min=0, initial=0) cont_belief_p2_c8 = models.IntegerField(min=0, initial=0) cont_belief_p2_c9 = models.IntegerField(min=0, initial=0) cont_belief_p2_c10 = models.IntegerField(min=0, initial=0) # Beliefs about what P3 contributed cont_belief_p3_c0 = models.IntegerField(min=0, initial=0) cont_belief_p3_c1 = models.IntegerField(min=0, initial=0) cont_belief_p3_c2 = models.IntegerField(min=0, initial=0) cont_belief_p3_c3 = models.IntegerField(min=0, initial=0) cont_belief_p3_c4 = models.IntegerField(min=0, initial=0) cont_belief_p3_c5 = models.IntegerField(min=0, initial=0) cont_belief_p3_c6 = models.IntegerField(min=0, initial=0) cont_belief_p3_c7 = models.IntegerField(min=0, initial=0) cont_belief_p3_c8 = models.IntegerField(min=0, initial=0) cont_belief_p3_c9 = models.IntegerField(min=0, initial=0) cont_belief_p3_c10 = models.IntegerField(min=0, initial=0) # Beliefs about what P4 contributed cont_belief_p4_c0 = models.IntegerField(min=0, initial=0) cont_belief_p4_c1 = models.IntegerField(min=0, initial=0) cont_belief_p4_c2 = models.IntegerField(min=0, initial=0) cont_belief_p4_c3 = models.IntegerField(min=0, initial=0) cont_belief_p4_c4 = models.IntegerField(min=0, initial=0) cont_belief_p4_c5 = models.IntegerField(min=0, initial=0) cont_belief_p4_c6 = models.IntegerField(min=0, initial=0) cont_belief_p4_c7 = models.IntegerField(min=0, initial=0) cont_belief_p4_c8 = models.IntegerField(min=0, initial=0) cont_belief_p4_c9 = models.IntegerField(min=0, initial=0) cont_belief_p4_c10 = models.IntegerField(min=0, initial=0) belief_payoff_p1 = models.FloatField(initial=0) belief_payoff_p2 = models.FloatField(initial=0) belief_payoff_p3 = models.FloatField(initial=0) belief_payoff_p4 = models.FloatField(initial=0) belief_payoff = models.FloatField(intial=0) current_payoff = models.FloatField(initial=0) punishment_cost = models.FloatField(initial=0) total_earnings = models.CurrencyField(initial=0) # def vote_deconstruct(player: Player): # if player.vote == 1: # player.vote_for_1 = 1 # else: # player.vote_for_1 = 0 # # if player.vote == 2: # player.vote_for_2 = 1 # else: # player.vote_for_2 = 0 # # if player.vote == 3: # player.vote_for_3 = 1 # else: # player.vote_for_3 = 0 # if player.vote == 4: # player.vote_for_4 = 1 # else: # player.vote_for_4 = 0 # # # # def contribution_max(player): # # session = player.session # # config = session.config # # # # return config['endowment'] # # # def vote_counting(group): # group.total_vote_for_1 = sum([p.vote_for_1 for p in group.get_players()]) # group.total_vote_for_2 = sum([p.vote_for_2 for p in group.get_players()]) # group.total_vote_for_3 = sum([p.vote_for_3 for p in group.get_players()]) # group.total_vote_for_4 = sum([p.vote_for_4 for p in group.get_players()]) # # # def set_leader(group): # if (group.total_vote_for_1 > group.total_vote_for_2) and (group.total_vote_for_1 > group.total_vote_for_3) and ( # group.total_vote_for_1 > group.total_vote_for_4): # group.new_order = [1, 2, 3, 4] # elif (group.total_vote_for_2 > group.total_vote_for_1) and (group.total_vote_for_2 > group.total_vote_for_3) and ( # group.total_vote_for_2 > group.total_vote_for_4): # group.new_order = [2, 1, 3, 4] # elif (group.total_vote_for_3 > group.total_vote_for_1) and (group.total_vote_for_3 > group.total_vote_for_2) and ( # group.total_vote_for_3 > group.total_vote_for_4): # group.new_order = [3, 1, 2, 4] # elif (group.total_vote_for_4 > group.total_vote_for_1) and (group.total_vote_for_4 > group.total_vote_for_2) and ( # group.total_vote_for_4 > group.total_vote_for_3): # group.new_order = [4, 1, 2, 3] # else: # if group.total_vote_for_1 == group.total_vote_for_2 == group.total_vote_for_3 == group.total_vote_for_4: # group.new_order = np.random.choice([1, 2, 3, 4]) # elif group.total_vote_for_1 == group.total_vote_for_2: # group.new_order = np.random.choice([1, 2]) # elif group.total_vote_for_1 == group.total_vote_for_3: # group.new_order = np.random.choice([1, 3]) # elif group.total_vote_for_1 == group.total_vote_for_4: # group.new_order = np.random.choice([1, 4]) # elif group.total_vote_for_2 == group.total_vote_for_3: # group.new_order = np.random.choice([2, 3]) # elif group.total_vote_for_2 == group.total_vote_for_4: # group.new_order = np.random.choice([2, 4]) # elif group.total_vote_for_3 == group.total_vote_for_4: # group.new_order = np.random.choice([3, 4]) def pun_cost(player): if player.id_in_group == 1: if player.punishment == 0: player.punishment_cost = 0 elif player.punishment == 1: player.punishment_cost = 0.5 elif player.punishment == 2: player.punishment_cost = 1 elif player.punishment == 3: player.punishment_cost = 2 elif player.punishment == 4: player.punishment_cost = 3 elif player.punishment == 5: player.punishment_cost = 4.5 elif player.punishment == 6: player.punishment_cost = 6 elif player.punishment == 7: player.punishment_cost = 8 elif player.punishment == 8: player.punishment_cost = 10 elif player.punishment == 9: player.punishment_cost = 12.5 elif player.punishment == 10: player.punishment_cost = 15 def total_cont_calc(group): p1 = group.get_player_by_id(1) p2 = group.get_player_by_id(2) p3 = group.get_player_by_id(3) p4 = group.get_player_by_id(4) group.total_contribution = p1.contribution + p2.contribution + p3.contribution + p4.contribution def set_payoffs(group): p1 = group.get_player_by_id(1) p2 = group.get_player_by_id(2) p3 = group.get_player_by_id(3) p4 = group.get_player_by_id(4) group.total_contribution = p1.contribution + p2.contribution + p3.contribution + p4.contribution group.individual_share = (group.total_contribution * C.EFF_FACTOR / (C.PLAYERS_PER_GROUP - 1)) for p in group.get_players(): p.payoff = ((C.ENDOWMENT - p.contribution) + group.individual_share) if group.round_number > 1: prev_player = p.in_round(group.round_number - 1) p.total_earnings = prev_player.total_earnings + p.payoff else: p.total_earnings = p.payoff def elicitation_payoff(group): players = group.get_players() p1 = group.get_player_by_id(1) p2 = group.get_player_by_id(2) p3 = group.get_player_by_id(3) p4 = group.get_player_by_id(4) for p in players: if p.id_in_group != 1: if p.id_in_group == 2 or p.id_in_group == 3 or p.id_in_group == 4: if p1.contribution == 0: p.belief_payoff_p1 = p.cont_belief_p1_c0 * 0.25 elif p1.contribution == 1: p.belief_payoff_p1 = p.cont_belief_p1_c1 * 0.25 elif p1.contribution == 2: p.belief_payoff_p1 = p.cont_belief_p1_c2 * 0.25 elif p1.contribution == 3: p.belief_payoff_p1 = p.cont_belief_p1_c3 * 0.25 elif p1.contribution == 4: p.belief_payoff_p1 = p.cont_belief_p1_c4 * 0.25 elif p1.contribution == 5: p.belief_payoff_p1 = p.cont_belief_p1_c5 * 0.25 elif p1.contribution == 6: p.belief_payoff_p1 = p.cont_belief_p1_c6 * 0.25 elif p1.contribution == 7: p.belief_payoff_p1 = p.cont_belief_p1_c7 * 0.25 elif p1.contribution == 8: p.belief_payoff_p1 = p.cont_belief_p1_c8 * 0.25 elif p1.contribution == 9: p.belief_payoff_p1 = p.cont_belief_p1_c9 * 0.25 else: p.belief_payoff_p1 = p.cont_belief_p1_c10 * 0.25 if p.id_in_group == 1 or p.id_in_group == 3 or p.id_in_group == 4: if p2.contribution == 0: p.belief_payoff_p2 = p.cont_belief_p2_c0 * 0.25 elif p2.contribution == 1: p.belief_payoff_p2 = p.cont_belief_p2_c1 * 0.25 elif p2.contribution == 2: p.belief_payoff_p2 = p.cont_belief_p2_c2 * 0.25 elif p2.contribution == 3: p.belief_payoff_p2 = p.cont_belief_p2_c3 * 0.25 elif p2.contribution == 4: p.belief_payoff_p2 = p.cont_belief_p2_c4 * 0.25 elif p2.contribution == 5: p.belief_payoff_p2 = p.cont_belief_p2_c5 * 0.25 elif p2.contribution == 6: p.belief_payoff_p2 = p.cont_belief_p2_c6 * 0.25 elif p2.contribution == 7: p.belief_payoff_p2 = p.cont_belief_p2_c7 * 0.25 elif p2.contribution == 8: p.belief_payoff_p2 = p.cont_belief_p2_c8 * 0.25 elif p2.contribution == 9: p.belief_payoff_p2 = p.cont_belief_p2_c9 * 0.25 else: p.belief_payoff_p2 = p.cont_belief_p2_c10 * 0.25 if p.id_in_group == 1 or p.id_in_group == 2 or p.id_in_group == 4: if p3.contribution == 0: p.belief_payoff_p3 = p.cont_belief_p3_c0 * 0.25 elif p3.contribution == 1: p.belief_payoff_p3 = p.cont_belief_p3_c1 * 0.25 elif p3.contribution == 2: p.belief_payoff_p3 = p.cont_belief_p3_c2 * 0.25 elif p3.contribution == 3: p.belief_payoff_p3 = p.cont_belief_p3_c3 * 0.25 elif p3.contribution == 4: p.belief_payoff_p3 = p.cont_belief_p3_c4 * 0.25 elif p3.contribution == 5: p.belief_payoff_p3 = p.cont_belief_p3_c5 * 0.25 elif p3.contribution == 6: p.belief_payoff_p3 = p.cont_belief_p3_c6 * 0.25 elif p3.contribution == 7: p.belief_payoff_p3 = p.cont_belief_p3_c7 * 0.25 elif p3.contribution == 8: p.belief_payoff_p3 = p.cont_belief_p3_c8 * 0.25 elif p3.contribution == 9: p.belief_payoff_p3 = p.cont_belief_p3_c9 * 0.25 else: p.belief_payoff_p3 = p.cont_belief_p3_c10 * 0.25 if p.id_in_group == 1 or p.id_in_group == 2 or p.id_in_group == 3: if p4.contribution == 0: p.belief_payoff_p4 = p.cont_belief_p4_c0 * 0.25 elif p4.contribution == 1: p.belief_payoff_p4 = p.cont_belief_p4_c1 * 0.25 elif p4.contribution == 2: p.belief_payoff_p4 = p.cont_belief_p4_c2 * 0.25 elif p4.contribution == 3: p.belief_payoff_p4 = p.cont_belief_p4_c3 * 0.25 elif p4.contribution == 4: p.belief_payoff_p4 = p.cont_belief_p4_c4 * 0.25 elif p4.contribution == 5: p.belief_payoff_p4 = p.cont_belief_p4_c5 * 0.25 elif p4.contribution == 6: p.belief_payoff_p4 = p.cont_belief_p4_c6 * 0.25 elif p4.contribution == 7: p.belief_payoff_p4 = p.cont_belief_p4_c7 * 0.25 elif p4.contribution == 8: p.belief_payoff_p4 = p.cont_belief_p4_c8 * 0.25 elif p4.contribution == 9: p.belief_payoff_p4 = p.cont_belief_p4_c9 * 0.25 else: p.belief_payoff_p4 = p.cont_belief_p4_c10 * 0.25 def elicitation_final_payoff(group): if group.subsession.round_number == group.subsession.End_Experiment_round: for p in group.get_players(): prev_player = p.in_round(group.subsession.Belief_pay_round) p.belief_payoff = prev_player.belief_payoff_p1 + prev_player.belief_payoff_p2 + prev_player.belief_payoff_p3 + prev_player.belief_payoff_p4 prev_player = p.in_round(group.round_number - 1) p.total_earnings = prev_player.total_earnings def sum_current_payoffs(group): p2 = group.get_player_by_id(2) p3 = group.get_player_by_id(3) p4 = group.get_player_by_id(4) p5 = group.get_player_by_id(5) group.total_contribution = p2.contribution + p3.contribution + p4.contribution + p5.contribution group.individual_share = (group.total_contribution * C.EFF_FACTOR / (C.PLAYERS_PER_GROUP - 1)) for p in group.get_players(): if p != 1: p.current_payoff = ((C.ENDOWMENT - p.contribution) + group.individual_share) group.current_payoff_sum = p2.current_payoff + p3.current_payoff + p4.current_payoff + p5.current_payoff # def group_punishment(group: Group): # p1 = group.get_player_by_id(1) # group.group_punishment = p1.punishment def total_earnings_calc(player: Player): player.total_earnings = sum(player.payoff.in_all_rounds) # def check_roll(player): # if player.subsession.session.vars['rand_rolls'][player.subsession.round_number] > C.cont_num: # player.subsession.End_Experiment = True # Pages class Introduction(Page): pass # class Vote(Page): # form_model = 'player' # form_fields = ['vote'] # # @staticmethod # def vars_for_template(player): # p1 = player.group.get_player_by_id(1) # p2 = player.group.get_player_by_id(2) # p3 = player.group.get_player_by_id(3) # p4 = player.group.get_player_by_id(4) # # return dict( # p1_in_previous_rounds=p1.in_previous_rounds(), # p2_in_previous_rounds=p2.in_previous_rounds(), # p3_in_previous_rounds=p3.in_previous_rounds(), # p4_in_previous_rounds=p4.in_previous_rounds(), # ) # # @staticmethod # def is_displayed(player): # return player.round_number == 1 # # # class VotesWaitPage(WaitPage): # # @staticmethod # def after_all_players_arrive(group): # for p in group.get_players(): # p.vote_deconstruct() # # group.vote_counting() # group.set_leader() # group.set_players(group.new_order) # # # class ElectionResults(Page): # # @staticmethod # def vars_for_template(group): # return dict( # votes_1=group.total_vote_for_1, # votes_2=group.total_vote_for_2, # votes_3=group.total_vote_for_3, # votes_4=group.total_vote_for_4, # winner=group.get_player_by_id(1) # ) # # @staticmethod # def is_displayed(player): # return player.round_number == 1 class RollCheck(Page): @staticmethod def is_displayed(player): return player.subsession.round_number != 1 @staticmethod def vars_for_template(player): return dict( roll=player.subsession.session.vars['rand_rolls'][player.subsession.round_number] ) @staticmethod def before_next_page(player, timeout_happened): if player.subsession.session.vars['rand_rolls'][player.subsession.round_number] > C.CONT_NUM: player.subsession.End_Experiment = True player.subsession.End_Experiment_round = player.subsession.round_number player.subsession.Belief_pay_round = np.random.randint(1, player.subsession.End_Experiment_round + 1) class Punishment(Page): form_model = 'player' form_fields = ['punishment'] @staticmethod def vars_for_template(player): return dict( group_cont=player.group.total_contribution, payoff_sum=player.group.current_payoff_sum ) @staticmethod def is_displayed(player): return player.subsession.End_Experiment == False and player.id_in_group == 1 @staticmethod def before_next_page(player, timeout_happened): if player.id_in_group == 1: if player.punishment == 0: player.punishment_cost = 0 elif player.punishment == 1: player.punishment_cost = 0.5 elif player.punishment == 2: player.punishment_cost = 1 elif player.punishment == 3: player.punishment_cost = 2 elif player.punishment == 4: player.punishment_cost = 3 elif player.punishment == 5: player.punishment_cost = 4.5 elif player.punishment == 6: player.punishment_cost = 6 elif player.punishment == 7: player.punishment_cost = 8 elif player.punishment == 8: player.punishment_cost = 10 elif player.punishment == 9: player.punishment_cost = 12.5 elif player.punishment == 10: player.punishment_cost = 15 class Contribute(Page): form_model = 'player' form_fields = ['contribution'] @staticmethod def is_displayed(player): return player.subsession.End_Experiment == False class Belief_Elic_1(Page): form_model = 'player' form_fields = ['cont_belief_p1_c0', 'cont_belief_p1_c1', 'cont_belief_p1_c2', 'cont_belief_p1_c3', 'cont_belief_p1_c4', 'cont_belief_p1_c5', 'cont_belief_p1_c6', 'cont_belief_p1_c7', 'cont_belief_p1_c8', 'cont_belief_p1_c9', 'cont_belief_p1_c10'] @staticmethod def is_displayed(player): return (player.id_in_group == 2 or player.id_in_group == 3 or player.id_in_group == 4) and player.subsession.End_Experiment == False @staticmethod def error_message(player, values): print('values is', values) if values['cont_belief_p1_c0'] + values['cont_belief_p1_c1'] \ + values['cont_belief_p1_c2'] + values['cont_belief_p1_c3'] \ + values['cont_belief_p1_c4'] + values['cont_belief_p1_c5'] \ + values['cont_belief_p1_c6'] + values['cont_belief_p1_c7'] \ + values['cont_belief_p1_c8'] + values['cont_belief_p1_c9'] \ + values['cont_belief_p1_c10'] != 11: return 'The guesses must add up to 11' class Belief_Elic_4(Page): form_model = 'player' form_fields = ['cont_belief_p4_c0', 'cont_belief_p4_c1', 'cont_belief_p4_c2', 'cont_belief_p4_c3', 'cont_belief_p4_c4', 'cont_belief_p4_c5', 'cont_belief_p4_c6', 'cont_belief_p4_c7', 'cont_belief_p4_c8', 'cont_belief_p4_c9', 'cont_belief_p4_c10'] @staticmethod def is_displayed(player): return (player.id_in_group == 1 or player.id_in_group == 2 or player.id_in_group == 3) and player.subsession.End_Experiment == False @staticmethod def error_message(player, values): print('values is', values) if values['cont_belief_p4_c0'] + values['cont_belief_p4_c1'] \ + values['cont_belief_p4_c2'] + values['cont_belief_p4_c3'] \ + values['cont_belief_p4_c4'] + values['cont_belief_p4_c5'] \ + values['cont_belief_p4_c6'] + values['cont_belief_p4_c7'] \ + values['cont_belief_p4_c8'] + values['cont_belief_p4_c9'] \ + values['cont_belief_p4_c10'] != 11: return 'The guesses must add up to 11' # @staticmethod # def before_next_page(player, timeout_happened): # p2 = player.group.get_player_by_id(2) # p3 = player.group.get_player_by_id(3) # p4 = player.group.get_player_by_id(4) # p5 = player.group.get_player_by_id(5) # # if player.id_in_group != 1: # if player.id_in_group != 2: # if p2.contribution == 0: # player.belief_payoff_p2 = player.cont_belief_p2_c0 * 0.25 # elif p2.contribution == 1: # player.belief_payoff_p2 = player.cont_belief_p2_c1 * 0.25 # elif p2.contribution == 2: # player.belief_payoff_p2 = player.cont_belief_p2_c2 * 0.25 # elif p2.contribution == 3: # player.belief_payoff_p2 = player.cont_belief_p2_c3 * 0.25 # elif p2.contribution == 4: # player.belief_payoff_p2 = player.cont_belief_p2_c4 * 0.25 # elif p2.contribution == 5: # player.belief_payoff_p2 = player.cont_belief_p2_c5 * 0.25 # elif p2.contribution == 6: # player.belief_payoff_p2 = player.cont_belief_p2_c6 * 0.25 # elif p2.contribution == 7: # player.belief_payoff_p2 = player.cont_belief_p2_c7 * 0.25 # elif p2.contribution == 8: # player.belief_payoff_p2 = player.cont_belief_p2_c8 * 0.25 # elif p2.contribution == 9: # player.belief_payoff_p2 = player.cont_belief_p2_c9 * 0.25 # else: # player.belief_payoff_p2 = player.cont_belief_p2_c10 * 0.25 # # elif player.id_in_group != 3: # if p3.contribution == 0: # player.belief_payoff_p3 = player.cont_belief_p3_c0 * 0.25 # elif p3.contribution == 1: # player.belief_payoff_p3 = player.cont_belief_p3_c1 * 0.25 # elif p3.contribution == 2: # player.belief_payoff_p3 = player.cont_belief_p3_c2 * 0.25 # elif p3.contribution == 3: # player.belief_payoff_p3 = player.cont_belief_p3_c3 * 0.25 # elif p3.contribution == 4: # player.belief_payoff_p3 = player.cont_belief_p3_c4 * 0.25 # elif p3.contribution == 5: # player.belief_payoff_p3 = player.cont_belief_p3_c5 * 0.25 # elif p3.contribution == 6: # player.belief_payoff_p3 = player.cont_belief_p3_c6 * 0.25 # elif p3.contribution == 7: # player.belief_payoff_p3 = player.cont_belief_p3_c7 * 0.25 # elif p3.contribution == 8: # player.belief_payoff_p3 = player.cont_belief_p3_c8 * 0.25 # elif p3.contribution == 9: # player.belief_payoff_p3 = player.cont_belief_p3_c9 * 0.25 # else: # player.belief_payoff_p3 = player.cont_belief_p3_c10 * 0.25 # # elif player.id_in_group != 4: # if p4.contribution == 0: # player.belief_payoff_p4 = player.cont_belief_p4_c0 * 0.25 # elif p4.contribution == 1: # player.belief_payoff_p4 = player.cont_belief_p4_c1 * 0.25 # elif p4.contribution == 2: # player.belief_payoff_p4 = player.cont_belief_p4_c2 * 0.25 # elif p4.contribution == 3: # player.belief_payoff_p4 = player.cont_belief_p4_c3 * 0.25 # elif p4.contribution == 4: # player.belief_payoff_p4 = player.cont_belief_p4_c4 * 0.25 # elif p4.contribution == 5: # player.belief_payoff_p4 = player.cont_belief_p4_c5 * 0.25 # elif p4.contribution == 6: # player.belief_payoff_p4 = player.cont_belief_p4_c6 * 0.25 # elif p4.contribution == 7: # player.belief_payoff_p4 = player.cont_belief_p4_c7 * 0.25 # elif p4.contribution == 8: # player.belief_payoff_p4 = player.cont_belief_p4_c8 * 0.25 # elif p4.contribution == 9: # player.belief_payoff_p4 = player.cont_belief_p4_c9 * 0.25 # else: # player.belief_payoff_p4 = player.cont_belief_p4_c10 * 0.25 # # else: # if p5.contribution == 0: # player.belief_payoff_p5 = player.cont_belief_p5_c0 * 0.25 # elif p5.contribution == 1: # player.belief_payoff_p5 = player.cont_belief_p5_c1 * 0.25 # elif p5.contribution == 2: # player.belief_payoff_p5 = player.cont_belief_p5_c2 * 0.25 # elif p5.contribution == 3: # player.belief_payoff_p5 = player.cont_belief_p5_c3 * 0.25 # elif p5.contribution == 4: # player.belief_payoff_p5 = player.cont_belief_p5_c4 * 0.25 # elif p5.contribution == 5: # player.belief_payoff_p5 = player.cont_belief_p5_c5 * 0.25 # elif p5.contribution == 6: # player.belief_payoff_p5 = player.cont_belief_p5_c6 * 0.25 # elif p5.contribution == 7: # player.belief_payoff_p5 = player.cont_belief_p5_c7 * 0.25 # elif p5.contribution == 8: # player.belief_payoff_p5 = player.cont_belief_p5_c8 * 0.25 # elif p5.contribution == 9: # player.belief_payoff_p5 = player.cont_belief_p5_c9 * 0.25 # else: # player.belief_payoff_p5 = player.cont_belief_p5_c10 * 0.25 class Belief_Elic_2(Page): form_model = 'player' form_fields = ['cont_belief_p2_c0', 'cont_belief_p2_c1', 'cont_belief_p2_c2', 'cont_belief_p2_c3', 'cont_belief_p2_c4', 'cont_belief_p2_c5', 'cont_belief_p2_c6', 'cont_belief_p2_c7', 'cont_belief_p2_c8', 'cont_belief_p2_c9', 'cont_belief_p2_c10'] @staticmethod def is_displayed(player): return (player.id_in_group == 1 or player.id_in_group == 3 or player.id_in_group == 4) and player.subsession.End_Experiment == False @staticmethod def error_message(player, values): print('values is', values) if values['cont_belief_p2_c0'] + values['cont_belief_p2_c1'] \ + values['cont_belief_p2_c2'] + values['cont_belief_p2_c3'] \ + values['cont_belief_p2_c4'] + values['cont_belief_p2_c5'] \ + values['cont_belief_p2_c6'] + values['cont_belief_p2_c7'] \ + values['cont_belief_p2_c8'] + values['cont_belief_p2_c9'] \ + values['cont_belief_p2_c10'] != 11: return 'The guesses must add up to 11' class Belief_Elic_3(Page): form_model = 'player' form_fields = ['cont_belief_p3_c0', 'cont_belief_p3_c1', 'cont_belief_p3_c2', 'cont_belief_p3_c3', 'cont_belief_p3_c4', 'cont_belief_p3_c5', 'cont_belief_p3_c6', 'cont_belief_p3_c7', 'cont_belief_p3_c8', 'cont_belief_p3_c9', 'cont_belief_p3_c10'] @staticmethod def is_displayed(player): return (player.id_in_group == 1 or player.id_in_group == 2 or player.id_in_group == 4) and player.subsession.End_Experiment == False @staticmethod def error_message(player, values): print('values is', values) if values['cont_belief_p3_c0'] + values['cont_belief_p3_c1'] \ + values['cont_belief_p3_c2'] + values['cont_belief_p3_c3'] \ + values['cont_belief_p3_c4'] + values['cont_belief_p3_c5'] \ + values['cont_belief_p3_c6'] + values['cont_belief_p3_c7'] \ + values['cont_belief_p3_c8'] + values['cont_belief_p3_c9'] \ + values['cont_belief_p3_c10'] != 11: return 'The guesses must add up to 11' class Belief_Elic_Wait(WaitPage): after_all_players_arrive = elicitation_payoff @staticmethod def is_displayed(player): return player.subsession.End_Experiment == False class Total_Cont_Calc(WaitPage): after_all_players_arrive = total_cont_calc @staticmethod def is_displayed(player): return player.subsession.End_Experiment == False class ResultsWaitPage(WaitPage): after_all_players_arrive = 'set_payoffs' body_text = "Please wait patiently." @staticmethod def is_displayed(player): return player.subsession.End_Experiment == False class Results(Page): @staticmethod def vars_for_template(player): # group = player.group # session = group.session p1 = player.group.get_player_by_id(1) return dict( ID=player.id_in_group, cont=player.contribution, priv_cont=C.ENDOWMENT - player.contribution, total_cont=player.group.total_contribution, pun_amt=round(player.group.group_punishment,1), pun_frac=round(1 - player.group.punish_factor,1), pun_cost=p1.punishment_cost, payoff=round(player.payoff,2), total_earn=round(player.total_earnings,2), ) @staticmethod def is_displayed(player): return player.subsession.End_Experiment == False class Current_Payoffs_Calc(WaitPage): after_all_players_arrive = 'sum_current_payoffs' @staticmethod def is_displayed(player): return player.subsession.End_Experiment == False class Belief_Payoffs(WaitPage): @staticmethod def is_displayed(player): return player.subsession.End_Experiment == True after_all_players_arrive = 'elicitation_final_payoff' class FinalResults(Page): @staticmethod def is_displayed(player): return player.subsession.End_Experiment == True @staticmethod def before_next_page(player, timeout_happened): prev_player = player.in_all_rounds() player.participant.vars['prev_conts'] = prev_player.contribution player.participant.vars['prev_rounds'] = prev_player.round_number @staticmethod def vars_for_template(player): return dict( total_earn=round(player.total_earnings,2), belief_payment=round(player.belief_payoff,2), show_up_payment=7, exp_payment=round(player.total_earnings+player.belief_payoff+7,2), ) page_sequence = [RollCheck, Contribute, Total_Cont_Calc, Belief_Elic_1, Belief_Elic_2, Belief_Elic_3, Belief_Elic_4, Belief_Elic_Wait, ResultsWaitPage, Results, FinalResults]