from otree.api import * import random doc = """ Game_DL """ class C(BaseConstants): NAME_IN_URL = 'dynamic_leadership' PLAYERS_PER_GROUP = 5 NUM_ROUNDS = 1 ENDOWMENT = 36 CATASTROPHE = 90 class Subsession(BaseSubsession): pass class Group(BaseGroup): target_met = models.BooleanField(initial=True) success = models.BooleanField(initial=True) #Leader has_leader = models.BooleanField(initial=False) leader = models.BooleanField() # role_player = models.CharField(initial='Follower') #PLEDGE1 pledge1leader_choice = models.BooleanField(initial=False) pledge1leader_choice1 = models.IntegerField() pledge1leader_choice2 = models.IntegerField() pledge1leader_choice3 = models.IntegerField() pledge1leader_choice = models.BooleanField( choices=[[True, 'Yes, I want to pledge'], [False, 'No, I do not want to pledge']], label="Would you like to make a pledge to the other 4 players for the rounds 1, 2, 3?" ) pledge1leader_choice1 = models.StringField(widget=widgets.RadioSelect, initial = "None", choices=[0, 1, 2, 3, 4], label="What value should (insert value1) take for rounds 1, 2, 3?" ) pledge1leader_choice2 = models.StringField(widget=widgets.RadioSelect, initial = "None", choices=[0, 1, 2, 3, 4], label="What value should (insert value2) take for rounds 1, 2, 3?" ) pledge1leader_choice3 = models.StringField(widget=widgets.RadioSelect, initial = "None", choices=[0, 1, 2, 3, 4], label="What value should (insert value3) take for rounds 1, 2, 3?" ) #PLEDGE4 pledge4leader_choice = models.BooleanField(initial=False) pledge4leader_choice1 = models.IntegerField() pledge4leader_choice2 = models.IntegerField() pledge4leader_choice3 = models.IntegerField() pledge4leader_choice = models.BooleanField( choices=[[True, 'Yes, I want to pledge'], [False, 'No, I do not want to pledge']], label="Would you like to make a pledge to the other 4 players for the rounds 4, 5, 6?" ) pledge4leader_choice1 = models.StringField(widget=widgets.RadioSelect, initial = "None", choices=[0, 1, 2, 3, 4], label="What value should (insert value1) take for rounds 4, 5, 6?" ) pledge4leader_choice2 = models.StringField(widget=widgets.RadioSelect, initial = "None", choices=[0, 1, 2, 3, 4], label="What value should (insert value2) take for rounds 4, 5, 6?" ) pledge4leader_choice3 = models.StringField(widget=widgets.RadioSelect, initial = "None", choices=[0, 1, 2, 3, 4], label="What value should (insert value3) take for rounds 4, 5, 6?" ) #PLEDGE7 pledge7leader_choice = models.BooleanField(initial=False) pledge7leader_choice1 = models.IntegerField() pledge7leader_choice2 = models.IntegerField() pledge7leader_choice3 = models.IntegerField() pledge7leader_choice = models.BooleanField( choices=[[True, 'Yes, I want to pledge'], [False, 'No, I do not want to pledge']], label="Would you like to make a pledge to the other 4 players for the rounds 7, 8, 9?" ) pledge7leader_choice1 = models.StringField(widget=widgets.RadioSelect, initial = "None", choices=[0, 1, 2, 3, 4], label="What value should (insert value1) take for rounds 7, 8, 9?" ) pledge7leader_choice2 = models.StringField(widget=widgets.RadioSelect, initial = "None", choices=[0, 1, 2, 3, 4], label="What value should (insert value2) take for rounds 7, 8, 9?" ) pledge7leader_choice3 = models.StringField(widget=widgets.RadioSelect, initial = "None", choices=[0, 1, 2, 3, 4], label="What value should (insert value3) take for rounds 7, 8, 9?" ) # CONTRIBUTIONS # Group-level contributions per round total_contribution1_dynamic = models.FloatField(initial=0) total_contribution2_dynamic = models.FloatField(initial=0) total_contribution3_dynamic = models.FloatField(initial=0) total_contribution4_dynamic = models.FloatField(initial=0) total_contribution5_dynamic = models.FloatField(initial=0) total_contribution6_dynamic = models.FloatField(initial=0) total_contribution7_dynamic = models.FloatField(initial=0) total_contribution8_dynamic = models.FloatField(initial=0) total_contribution9_dynamic = models.FloatField(initial=0) # Aggregate group-level contributions DYNAMIC total_contribution12_dynamic = models.FloatField(initial=0) total_contribution123_dynamic = models.FloatField(initial=0) total_contribution1234_dynamic = models.FloatField(initial=0) total_contribution12345_dynamic = models.FloatField(initial=0) total_contribution123456_dynamic = models.FloatField(initial=0) total_contribution1234567_dynamic = models.FloatField(initial=0) total_contribution12345678_dynamic = models.FloatField(initial=0) total_contribution123456789_dynamic = models.FloatField(initial=0) # Other total_aggregate_contributions = models.FloatField(initial=0) total_aggregate_contributions_dynamic = models.FloatField(initial=0) individual_share = models.FloatField(initial=0) threshold = models.FloatField(initial=0) threshold_reached = models.IntegerField() dropout = models.LongStringField() class Player(BasePlayer): #PLEDGES BLOCK 1 is_leader = models.BooleanField(initial=False) role_player = models.CharField(initial='Follower') pledge1follower_choice = models.IntegerField() pledge1leader_choiceAll = models.BooleanField(initial=False) pledge1follower_choice = models.StringField(widget=widgets.RadioSelect, initial = "Initiator", choices=[0, 1, 2, 3, 4], label="What value should (insert value) take for rounds 1, 2, 3?" ) pledge4follower_choice = models.IntegerField() pledge4leader_choiceAll = models.BooleanField(initial=False) pledge4follower_choice = models.StringField(widget=widgets.RadioSelect, initial = "Initiator", choices=[0, 1, 2, 3, 4], label="What value should (insert value) take for rounds 4, 5, 6?" ) pledge7follower_choice = models.IntegerField() pledge7leader_choiceAll = models.BooleanField(initial=False) pledge7follower_choice = models.StringField(widget=widgets.RadioSelect, initial = "Initiator", choices=[0, 1, 2, 3, 4], label="What value should (insert value) take for rounds 7, 8, 9?" ) #CONTRIBUTIONS color = models.StringField() real_payoff = models.FloatField() contribution_sum = models.FloatField() savings1 = models.FloatField() savings2 = models.FloatField() savings3 = models.FloatField() savings4 = models.FloatField() savings5 = models.FloatField() savings6 = models.FloatField() savings7 = models.FloatField() savings8 = models.FloatField() savings9 = models.FloatField() contribution12_static = models.FloatField() contribution1 = models.FloatField(widget=widgets.RadioSelect, choices=[0, 1, 2, 3, 4], label="Round 1: How much do you want to invest into climate protection (0-4 Cashcoins)?" ) contribution2 = models.FloatField(widget=widgets.RadioSelect, choices=[0, 1, 2, 3, 4], label="Round 2: How much do you want to invest into climate protection (0-4 Cashcoins)?" ) contribution3 = models.FloatField(widget=widgets.RadioSelect, choices=[0, 1, 2, 3, 4], label="Round 3: How much do you want to invest into climate protection (0-4 Cashcoins)?" ) contribution4 = models.FloatField(widget=widgets.RadioSelect, choices=[0, 1, 2, 3, 4], label="Round 4: How much do you want to invest into climate protection (0-4 Cashcoins)?" ) contribution5 = models.FloatField(widget=widgets.RadioSelect, choices=[0, 1, 2, 3, 4], label="Round 5: How much do you want to invest into climate protection (0-4 Cashcoins)?" ) contribution6 = models.FloatField(widget=widgets.RadioSelect, choices=[0, 1, 2, 3, 4], label="Round 6: How much do you want to invest into climate protection (0-4 Cashcoins)?" ) contribution7 = models.FloatField(widget=widgets.RadioSelect, choices=[0, 1, 2, 3, 4], label="Round 7: How much do you want to invest into climate protection (0-4 Cashcoins)?" ) contribution8 = models.FloatField(widget=widgets.RadioSelect, choices=[0, 1, 2, 3, 4], label="Round 8: How much do you want to invest into climate protection (0-4 Cashcoins)?" ) contribution9 = models.FloatField(widget=widgets.RadioSelect, choices=[0, 1, 2, 3, 4], label="Round 9: How much do you want to invest into climate protection (0-4 Cashcoins)?" ) # Functions #PLAYER FUNCTIONS #LEADERSHIP def choose_leader(player): if player.id_in_group == player.is_leader: player.role_player = 'Leader' else: player.role_player = 'Follower' return player.role_player #def role(player): # if player.id_in_group == player.is_leader: # return 1 # else: # return 2 # CONTRIBUTIONS #GROUP FUNCTIONS #PLEDGES BLOCK 1 def pledge1follower_choice_summary(group: Group): for p in group.get_players(): if group.player.id_in_group == group.is_leader: group.player.pledge1follower_choice_summary = '' else: group.player.pledge1follower_choice_summary = group.player.pledge1follower_choice return group.player.pledge1follower_choice_summary def pledge1leader1(group: Group): for p in group.get_players(): if p.pledge1leader_choiceAll == True: group.pledge1leader = True group.session.vars.update(leader_pledged=True) else: group.pledge1leader = False group.session.vars.update(leader_pledged=False) def group_pledges1(group: Group): group.pledge1leader_choice = group.pledge1leader_choice group.pledge1leader_choice1 = group.pledge1leader_choice1 group.pledge1leader_choice2 = group.pledge1leader_choice2 group.pledge1leader_choice3 = group.pledge1leader_choice3 def group_pledges1_updated(group: Group): group.pledge1leader_choice = group.pledge1leader_choice group.pledge1leader_choice1 = group.pledge1leader_choice1 group.pledge1leader_choice2 = group.pledge1leader_choice2 group.pledge1leader_choice3 = group.pledge1leader_choice3 #group.pledge1follower_choice = group.pledge1follower_choice #for p in group.get_players(): # p.pledge1follower_choice = group.pledge1follower_choice # CONTRIBUTIONS # PLEDGES BLOCK 4 def pledge4follower_choice_summary(group: Group): for p in group.get_players(): if group.player.id_in_group == group.is_leader: group.player.pledge4follower_choice_summary = '' else: group.player.pledge4follower_choice_summary = group.player.pledge4follower_choice return group.player.pledge4follower_choice_summary def pledge4leader1(group: Group): for p in group.get_players(): if p.pledge4leader_choiceAll == True: group.pledge4leader = True group.session.vars.update(leader_pledged=True) else: group.pledge4leader = False group.session.vars.update(leader_pledged=False) def group_pledges4(group: Group): group.pledge4leader_choice = group.pledge4leader_choice group.pledge4leader_choice1 = group.pledge4leader_choice1 group.pledge4leader_choice2 = group.pledge4leader_choice2 group.pledge4leader_choice3 = group.pledge4leader_choice3 def group_pledges4_updated(group: Group): group.pledge4leader_choice = group.pledge4leader_choice group.pledge4leader_choice1 = group.pledge4leader_choice1 group.pledge4leader_choice2 = group.pledge4leader_choice2 group.pledge4leader_choice3 = group.pledge4leader_choice3 # PLEDGES BLOCK 7 def pledge7follower_choice_summary(group: Group): for p in group.get_players(): if group.player.id_in_group == group.is_leader: group.player.pledge7follower_choice_summary = '' else: group.player.pledge7follower_choice_summary = group.player.pledge7follower_choice return group.player.pledge7follower_choice_summary def pledge7leader1(group: Group): for p in group.get_players(): if p.pledge7leader_choiceAll == True: group.pledge7leader = True group.session.vars.update(leader_pledged=True) else: group.pledge4leader = False group.session.vars.update(leader_pledged=False) def group_pledges7(group: Group): group.pledge7leader_choice = group.pledge7leader_choice group.pledge7leader_choice1 = group.pledge7leader_choice1 group.pledge7leader_choice2 = group.pledge7leader_choice2 group.pledge7leader_choice3 = group.pledge7leader_choice3 def group_pledges7_updated(group: Group): group.pledge7leader_choice = group.pledge7leader_choice group.pledge7leader_choice1 = group.pledge7leader_choice1 group.pledge7leader_choice2 = group.pledge7leader_choice2 group.pledge7leader_choice3 = group.pledge7leader_choice3 #CONTRIBUTIONS def set_payoffs(group: Group): group.threshold = 90 group.total_contribution1_dynamic = sum([p.contribution1 for p in group.get_players()]) * 1.5 group.total_contribution2_dynamic = sum([p.contribution2 for p in group.get_players()]) * 1.5 group.total_contribution3_dynamic = sum([p.contribution3 for p in group.get_players()]) * 1.5 group.total_contribution4_dynamic = sum([p.contribution4 for p in group.get_players()]) * 1.0 group.total_contribution5_dynamic = sum([p.contribution5 for p in group.get_players()]) * 1.0 group.total_contribution6_dynamic = sum([p.contribution6 for p in group.get_players()]) * 1.0 group.total_contribution7_dynamic = sum([p.contribution7 for p in group.get_players()]) * 0.5 group.total_contribution8_dynamic = sum([p.contribution8 for p in group.get_players()]) * 0.5 group.total_contribution9_dynamic = sum([p.contribution9 for p in group.get_players()]) * 0.5 group.total_aggregate_contributions = (group.total_contribution1_dynamic + group.total_contribution2_dynamic + group.total_contribution3_dynamic + group.total_contribution4_dynamic + group.total_contribution5_dynamic + group.total_contribution6_dynamic + group.total_contribution7_dynamic + group.total_contribution8_dynamic + group.total_contribution9_dynamic) for p in group.get_players(): if group.total_aggregate_contributions >= C.CATASTROPHE: group.target_met = True group.success = True group.session.vars.update(target_met=True) group.session.vars.update(success=True) p.payoff = C.ENDOWMENT - (p.contribution1 + p.contribution2 + p.contribution3 + p.contribution4 + p.contribution5 + p.contribution6 + p.contribution7 + p.contribution8 + p.contribution9) else: group.session.vars.update(target_met=False) group.target_met = False if random.random()<0.3: group.session.vars.update(success=True) group.success = True p.payoff = C.ENDOWMENT - ( p.contribution1 + p.contribution2 + p.contribution3 + p.contribution4 + p.contribution5 + p.contribution6 + p.contribution7 + p.contribution8 + p.contribution9) else: group.session.vars.update(success=False) group.success = False p.payoff = 0 p.real_payoff = round(float(p.payoff) * 0.50, 2) def dropouts(group: Group): for p in group.get_players(): str(group.participant.vars) def set_contribution1_payoff(group: Group): group.total_contribution1_dynamic = sum([p.contribution1 for p in group.get_players()]) * 1.5 for p in group.get_players(): p.savings1 = C.ENDOWMENT - p.contribution1 def set_contribution2_payoff(group: Group): group.total_contribution1_dynamic = sum([p.contribution1 for p in group.get_players()]) * 1.5 group.total_contribution2_dynamic = sum([p.contribution2 for p in group.get_players()]) * 1.5 group.total_contribution12_dynamic = group.total_contribution1_dynamic + group.total_contribution2_dynamic for p in group.get_players(): p.savings2 = C.ENDOWMENT - p.contribution1 - p.contribution2 def set_contribution3_payoff(group: Group): group.total_contribution1_dynamic = sum([p.contribution1 for p in group.get_players()]) * 1.5 group.total_contribution2_dynamic = sum([p.contribution2 for p in group.get_players()]) * 1.5 group.total_contribution3_dynamic = sum([p.contribution3 for p in group.get_players()]) * 1.5 group.total_contribution123_dynamic = group.total_contribution1_dynamic + group.total_contribution2_dynamic \ + group.total_contribution3_dynamic for p in group.get_players(): p.savings3 = C.ENDOWMENT - p.contribution1 - p.contribution2 - p.contribution3 def set_contribution4_payoff(group: Group): group.total_contribution1_dynamic = sum([p.contribution1 for p in group.get_players()]) * 1.5 group.total_contribution2_dynamic = sum([p.contribution2 for p in group.get_players()]) * 1.5 group.total_contribution3_dynamic = sum([p.contribution3 for p in group.get_players()]) * 1.5 group.total_contribution4_dynamic = sum([p.contribution4 for p in group.get_players()]) * 1.0 group.total_contribution1234_dynamic = group.total_contribution1_dynamic + group.total_contribution2_dynamic \ + group.total_contribution3_dynamic + group.total_contribution4_dynamic for p in group.get_players(): p.savings4 = C.ENDOWMENT - p.contribution1 - p.contribution2 - p.contribution3 - p.contribution4 def set_contribution5_payoff(group: Group): group.total_contribution1_dynamic = sum([p.contribution1 for p in group.get_players()]) * 1.5 group.total_contribution2_dynamic = sum([p.contribution2 for p in group.get_players()]) * 1.5 group.total_contribution3_dynamic = sum([p.contribution3 for p in group.get_players()]) * 1.5 group.total_contribution4_dynamic = sum([p.contribution4 for p in group.get_players()]) * 1.0 group.total_contribution5_dynamic = sum([p.contribution5 for p in group.get_players()]) * 1.0 group.total_contribution12345_dynamic = group.total_contribution1_dynamic + group.total_contribution2_dynamic \ + group.total_contribution3_dynamic + group.total_contribution4_dynamic \ + group.total_contribution5_dynamic for p in group.get_players(): p.savings5 = C.ENDOWMENT - p.contribution1 - p.contribution2 - p.contribution3 - p.contribution4 \ - p.contribution5 def set_contribution6_payoff(group: Group): group.total_contribution1_dynamic = sum([p.contribution1 for p in group.get_players()]) * 1.5 group.total_contribution2_dynamic = sum([p.contribution2 for p in group.get_players()]) * 1.5 group.total_contribution3_dynamic = sum([p.contribution3 for p in group.get_players()]) * 1.5 group.total_contribution4_dynamic = sum([p.contribution4 for p in group.get_players()]) * 1.0 group.total_contribution5_dynamic = sum([p.contribution5 for p in group.get_players()]) * 1.0 group.total_contribution6_dynamic = sum([p.contribution6 for p in group.get_players()]) * 1.0 group.total_contribution123456_dynamic = group.total_contribution1_dynamic + group.total_contribution2_dynamic \ + group.total_contribution3_dynamic + group.total_contribution4_dynamic \ + group.total_contribution5_dynamic + group.total_contribution6_dynamic for p in group.get_players(): p.savings6 = C.ENDOWMENT - p.contribution1 - p.contribution2 - p.contribution3 - p.contribution4 \ - p.contribution5 - p.contribution6 def set_contribution7_payoff(group: Group): group.total_contribution1_dynamic = sum([p.contribution1 for p in group.get_players()]) * 1.5 group.total_contribution2_dynamic = sum([p.contribution2 for p in group.get_players()]) * 1.5 group.total_contribution3_dynamic = sum([p.contribution3 for p in group.get_players()]) * 1.5 group.total_contribution4_dynamic = sum([p.contribution4 for p in group.get_players()]) * 1.0 group.total_contribution5_dynamic = sum([p.contribution5 for p in group.get_players()]) * 1.0 group.total_contribution6_dynamic = sum([p.contribution6 for p in group.get_players()]) * 1.0 group.total_contribution7_dynamic = sum([p.contribution7 for p in group.get_players()]) * 0.5 group.total_contribution1234567_dynamic = group.total_contribution1_dynamic + group.total_contribution2_dynamic \ + group.total_contribution3_dynamic + group.total_contribution4_dynamic \ + group.total_contribution5_dynamic + group.total_contribution6_dynamic \ + group.total_contribution7_dynamic for p in group.get_players(): p.savings7 = C.ENDOWMENT - p.contribution1 - p.contribution2 - p.contribution3 - p.contribution4 \ - p.contribution5 - p.contribution6 - p.contribution7 def set_contribution8_payoff(group: Group): group.total_contribution1_dynamic = sum([p.contribution1 for p in group.get_players()]) * 1.5 group.total_contribution2_dynamic = sum([p.contribution2 for p in group.get_players()]) * 1.5 group.total_contribution3_dynamic = sum([p.contribution3 for p in group.get_players()]) * 1.5 group.total_contribution4_dynamic = sum([p.contribution4 for p in group.get_players()]) * 1.0 group.total_contribution5_dynamic = sum([p.contribution5 for p in group.get_players()]) * 1.0 group.total_contribution6_dynamic = sum([p.contribution6 for p in group.get_players()]) * 1.0 group.total_contribution7_dynamic = sum([p.contribution7 for p in group.get_players()]) * 0.5 group.total_contribution8_dynamic = sum([p.contribution8 for p in group.get_players()]) * 0.5 group.total_contribution12345678_dynamic = group.total_contribution1_dynamic + group.total_contribution2_dynamic \ + group.total_contribution3_dynamic + group.total_contribution4_dynamic \ + group.total_contribution5_dynamic + group.total_contribution6_dynamic \ + group.total_contribution7_dynamic + group.total_contribution8_dynamic for p in group.get_players(): p.savings8 = C.ENDOWMENT - p.contribution1 - p.contribution2 - p.contribution3 - p.contribution4 \ - p.contribution5 - p.contribution6 - p.contribution7 - p.contribution8 def set_contribution9_payoff(group: Group): group.total_contribution1_dynamic = sum([p.contribution1 for p in group.get_players()]) * 1.5 group.total_contribution2_dynamic = sum([p.contribution2 for p in group.get_players()]) * 1.5 group.total_contribution3_dynamic = sum([p.contribution3 for p in group.get_players()]) * 1.5 group.total_contribution4_dynamic = sum([p.contribution4 for p in group.get_players()]) * 1.0 group.total_contribution5_dynamic = sum([p.contribution5 for p in group.get_players()]) * 1.0 group.total_contribution6_dynamic = sum([p.contribution6 for p in group.get_players()]) * 1.0 group.total_contribution7_dynamic = sum([p.contribution7 for p in group.get_players()]) * 0.5 group.total_contribution8_dynamic = sum([p.contribution8 for p in group.get_players()]) * 0.5 group.total_contribution9_dynamic = sum([p.contribution9 for p in group.get_players()]) * 0.5 group.total_contribution123456789_dynamic = group.total_contribution1_dynamic + group.total_contribution2_dynamic \ + group.total_contribution3_dynamic + group.total_contribution4_dynamic \ + group.total_contribution5_dynamic + group.total_contribution6_dynamic \ + group.total_contribution7_dynamic + group.total_contribution8_dynamic \ + group.total_contribution9_dynamic for p in group.get_players(): p.savings9 = C.ENDOWMENT - p.contribution1 - p.contribution2 - p.contribution3 - p.contribution4 \ - p.contribution5 - p.contribution6 - p.contribution7 - p.contribution8 - p.contribution9 def is_reached(group: Group): return group.total_both_contributions >= group.threshold # PAGES class FirstPage(WaitPage): wait_for_all_groups = True body_text = "Please wait, you are being assigned to a group of 5 players." class FirstFirstPage(Page): pass #Leadership Choice class LeadershipWaitPage(WaitPage): body_text = "Please wait for the other players." class Leadership(Page): def live_method(self, data): group = self.group # print('data is', data) if group.has_leader: return if data.get('leader'): group.has_leader = True # mark all other players as non-volunteers for p in self.get_others_in_group(): p.is_leader = False self.role_player = 'Follower' # mark myself as a volunteer self.is_leader = True self.role_player = 'Leader' # broadcast to the group that the game is finished. return {0: dict(finished=True)} def error_message(self, values): """Prevent users from proceeding before someone has volunteered.""" group = self.group if not group.has_leader: return "Can't move forward" class LeadershipResults(Page): def vars_for_template(player): return dict(name=player.id_in_group) #PLEDGE 1 class Pledge1_Leader_static_Followerstep(Page): def is_displayed(player: Player): return player.role_player == 'Follower' class Pledge1_Leader_static(Page): """You have been elected as the Leader of the Climate Protection Game. You can now decide whether you want to make a conditional contribution to the Climate Pot or not.""" """The pledge takes the following form: "I pledge to contribute (insert value1). However, if 3 out of the other 4 players contribute at least (insert value2), I pledge to contribute (insert value3). This pledge holds for time periods 1, 2, and 3.". Typically, (insert value3) will be larger than (insert value1) and (insert value2)""" def is_displayed(player: Player): return player.role_player == 'Leader' form_model = 'group' form_fields = ['pledge1leader_choice'] def pledge(player: Player): group = player.group if player.pledge1leader_choice == True: group.pledge1leader = True for p in group.get_others_in_group(): p.leader_pledged1 = True p.pledge1leader_choiceAll = True else: group.pledge1leader = False for p in group.get_others_in_group(): p.leader_pledged1 = False p.pledge1leader_choiceAll = False def update_groupdata(player: Player): if player.pledge1leader_choice == True: player.session.vars.update(leader_pledges1=True) else: player.session.vars.update(leader_pledges1=False) class Pledge1_Leader_choice_static(Page): """You have chosen to make a conditional contribution to the Climate Pot. The pledge takes the following form: "I pledge to contribute (insert value1). However, if 3 out of the other 4 players contribute at least (insert value2), I pledge to contribute (insert value3). This pledge holds for time periods 1, 2, and 3.". Typically, (insert value3) will be larger than (insert value1) and (insert value2) """ def is_displayed(player): return player.role_player == 'Leader' and player.group.pledge1leader_choice == True form_model = 'group' form_fields = ['pledge1leader_choice1', 'pledge1leader_choice2', 'pledge1leader_choice3'] class Pledge1_1WaitPage(WaitPage): def is_displayed(player: Player): return player.role_player == 'Follower' after_all_players_arrive = group_pledges1 body_text = "Please wait for the other players." class Pledge1_Leader_static_Leaderstep(Page): def is_displayed(player): return player.role_player == 'Leader' and player.group.pledge1leader_choice == True class Pledge1_Leader_static_overview(Page): """The leader has made a pledge to the Climate Pot for rounds 1, 2, 3. You can see his pledge for rounds 1, 2, 3 below. """ def is_displayed(player): return player.group.pledge1leader_choice == True class Pledge1_Follower_static(Page): """The leader has made a pledge to the Climate Pot for rounds 1, 2, 3. You too can now make a pledge for rounds 1, 2, 3. The pledge takes the following form: "I pledge to contribute (insert value)." """ def is_displayed(player): return player.role_player == 'Follower' and player.group.pledge1leader_choice == True form_model = 'player' form_fields = ['pledge1follower_choice'] class Pledge1_ResultsWaitPage(WaitPage): after_all_players_arrive = group_pledges1_updated body_text = "Please wait for the other players." class Pledge1_Results_static(Page): """How much did every player pledge?""" def is_displayed(player): return player.group.pledge1leader_choice == True def vars_for_template(player): return dict(name=player.id_in_group) class Pledge1_LastPage_static(Page): """How much did every player pledge?""" class EndBlock1(Page): pass class EndBlock1WaitPage(WaitPage): pass #PLEDGE 4 class Pledge4_Leader_static_Followerstep(Page): def is_displayed(player: Player): return player.role_player == 'Follower' class Pledge4_Leader_static(Page): """You have been elected as the Leader of the Climate Protection Game. You can now decide whether you want to make a conditional contribution to the Climate Pot or not.""" """The pledge takes the following form: "I pledge to contribute (insert value1). However, if 3 out of the other 4 players contribute at least (insert value2), I pledge to contribute (insert value3). This pledge holds for time periods 4, 5, and 6.". Typically, (insert value3) will be larger than (insert value1) and (insert value2)""" def is_displayed(player: Player): return player.role_player == 'Leader' form_model = 'group' form_fields = ['pledge4leader_choice'] def pledge(player: Player): group = player.group if player.pledge4leader_choice == True: group.pledge4leader = True for p in group.get_others_in_group(): p.leader_pledged4 = True p.pledge4leader_choiceAll = True else: group.pledge4leader = False for p in group.get_others_in_group(): p.leader_pledged4 = False p.pledge4leader_choiceAll = False def update_groupdata(player: Player): if player.pledge4leader_choice == True: player.session.vars.update(leader_pledges4=True) else: player.session.vars.update(leader_pledges4=False) class Pledge4_Leader_choice_static(Page): """You have chosen to make a conditional contribution to the Climate Pot. The pledge takes the following form: "I pledge to contribute (insert value1). However, if 3 out of the other 4 players contribute at least (insert value2), I pledge to contribute (insert value3). This pledge holds for time periods 4, 5, and 6.". Typically, (insert value3) will be larger than (insert value1) and (insert value2) """ def is_displayed(player): return player.role_player == 'Leader' and player.group.pledge4leader_choice == True form_model = 'group' form_fields = ['pledge4leader_choice1', 'pledge4leader_choice2', 'pledge4leader_choice3'] class Pledge4_1WaitPage(WaitPage): def is_displayed(player: Player): return player.role_player == 'Follower' after_all_players_arrive = group_pledges4 body_text = "Please wait for the other players." class Pledge4_Leader_static_Leaderstep(Page): def is_displayed(player): return player.role_player == 'Leader' and player.group.pledge4leader_choice == True class Pledge4_Leader_static_overview(Page): """The leader has made a pledge to the Climate Pot for rounds 4, 5, 6. You can see his pledge for rounds 4, 5, 6 below. """ def is_displayed(player): return player.group.pledge4leader_choice == True class Pledge4_Follower_static(Page): """The leader has made a pledge to the Climate Pot for rounds 4, 5, 6. You too can now make a pledge for rounds 4, 5, 6. The pledge takes the following form: "I pledge to contribute (insert value)." """ def is_displayed(player): return player.role_player == 'Follower' and player.group.pledge4leader_choice == True form_model = 'player' form_fields = ['pledge4follower_choice'] class Pledge4_ResultsWaitPage(WaitPage): after_all_players_arrive = group_pledges4_updated body_text = "Please wait for the other players." class Pledge4_Results_static(Page): """How much did every player pledge?""" def is_displayed(player): return player.group.pledge4leader_choice == True def vars_for_template(player): return dict(name=player.id_in_group) class Pledge4_LastPage_static(Page): """How much did every player pledge?""" class EndBlock4(Page): pass class EndBlock4WaitPage(WaitPage): pass #PLEDGE 7 class Pledge7_Leader_static_Followerstep(Page): def is_displayed(player: Player): return player.role_player == 'Follower' class Pledge7_Leader_static(Page): """You have been elected as the Leader of the Climate Protection Game. You can now decide whether you want to make a conditional contribution to the Climate Pot or not.""" """The pledge takes the following form: "I pledge to contribute (insert value1). However, if 3 out of the other 4 players contribute at least (insert value2), I pledge to contribute (insert value3). This pledge holds for time periods 7, 8, and 9.". Typically, (insert value3) will be larger than (insert value1) and (insert value2)""" def is_displayed(player: Player): return player.role_player == 'Leader' form_model = 'group' form_fields = ['pledge7leader_choice'] def pledge(player: Player): group = player.group if player.pledge7leader_choice == True: group.pledge7leader = True for p in group.get_others_in_group(): p.leader_pledged7 = True p.pledge7leader_choiceAll = True else: group.pledge7leader = False for p in group.get_others_in_group(): p.leader_pledged7 = False p.pledge7leader_choiceAll = False def update_groupdata(player: Player): if player.pledge7leader_choice == True: player.session.vars.update(leader_pledges7=True) else: player.session.vars.update(leader_pledges7=False) class Pledge7_Leader_choice_static(Page): """You have chosen to make a conditional contribution to the Climate Pot. The pledge takes the following form: "I pledge to contribute (insert value1). However, if 3 out of the other 4 players contribute at least (insert value2), I pledge to contribute (insert value3). This pledge holds for time periods 7, 8, and 9.". Typically, (insert value3) will be larger than (insert value1) and (insert value2) """ def is_displayed(player): return player.role_player == 'Leader' and player.group.pledge7leader_choice == True form_model = 'group' form_fields = ['pledge7leader_choice1', 'pledge7leader_choice2', 'pledge7leader_choice3'] class Pledge7_1WaitPage(WaitPage): def is_displayed(player: Player): return player.role_player == 'Follower' after_all_players_arrive = group_pledges7 body_text = "Please wait for the other players." class Pledge7_Leader_static_Leaderstep(Page): def is_displayed(player): return player.role_player == 'Leader' and player.group.pledge7leader_choice == True class Pledge7_Leader_static_overview(Page): """The leader has made a pledge to the Climate Pot for rounds 7, 8, 9. You can see his pledge for rounds 7, 8, 8 below. """ def is_displayed(player): return player.group.pledge7leader_choice == True class Pledge7_Follower_static(Page): """The leader has made a pledge to the Climate Pot for rounds 7, 8, 9. You too can now make a pledge for rounds 7, 8, 9. The pledge takes the following form: "I pledge to contribute (insert value)." """ def is_displayed(player): return player.role_player == 'Follower' and player.group.pledge7leader_choice == True form_model = 'player' form_fields = ['pledge7follower_choice'] class Pledge7_ResultsWaitPage(WaitPage): after_all_players_arrive = group_pledges7_updated body_text = "Please wait for the other players." class Pledge7_Results_static(Page): """How much did every player pledge?""" def is_displayed(player): return player.group.pledge7leader_choice == True def vars_for_template(player): return dict(name=player.id_in_group) class Pledge7_LastPage_static(Page): """How much did every player pledge?""" #CONTRIBUTIONS #Contribution Wait Pages class Contribution1WaitPage(WaitPage): body_text = "Please wait for the other players." class Contribution2WaitPage(WaitPage): body_text = "Please wait for the other players." class Contribution3WaitPage(WaitPage): body_text = "Please wait for the other players." class Contribution4WaitPage(WaitPage): body_text = "Please wait for the other players." class Contribution5WaitPage(WaitPage): body_text = "Please wait for the other players." class Contribution6WaitPage(WaitPage): body_text = "Please wait for the other players." class Contribution7WaitPage(WaitPage): body_text = "Please wait for the other players." class Contribution8WaitPage(WaitPage): body_text = "Please wait for the other players." class Contribution9WaitPage(WaitPage): body_text = "Please wait for the other players." #Contributions class Contribute1_dynamic(Page): """This is the first of 9 rounds of the Climate Protection Game. You can now decide how much you want to contribute to the climate pot.""" form_model = 'player' form_fields = ['contribution1'] def vars_for_template(player): return dict( amount_left=C.ENDOWMENT ) def get_timeout_seconds(player): return 1 * 60 class Contribute2_dynamic(Page): """This is the second of 9 rounds of the Climate Protection Game. You can now decide how much you want to contribute to the climate pot.""" form_model = 'player' form_fields = ['contribution2'] def vars_for_template(player): return dict( amount_left=C.ENDOWMENT - player.contribution1 ) def get_timeout_seconds(player): return 1 * 60 class Contribute3_dynamic(Page): """This is the third of 9 rounds of the Climate Protection Game. You can now decide how much you want to contribute to the climate pot.""" form_model = 'player' form_fields = ['contribution3'] def vars_for_template(player): return dict( amount_left=C.ENDOWMENT - player.contribution1 - player.contribution2 ) def get_timeout_seconds(player): return 1 * 60 class Contribute4_dynamic(Page): """This is the fourth of 9 rounds of the Climate Protection Game. You can now decide how much you want to contribute to the climate pot.""" form_model = 'player' form_fields = ['contribution4'] def vars_for_template(player): return dict( amount_left=C.ENDOWMENT - player.contribution1 - player.contribution2 - player.contribution3 ) def get_timeout_seconds(player): return 1 * 60 class Contribute5_dynamic(Page): """This is the fifth of 9 rounds of the Climate Protection Game. You can now decide how much you want to contribute to the climate pot.""" form_model = 'player' form_fields = ['contribution5'] def vars_for_template(player): return dict( amount_left=C.ENDOWMENT - player.contribution1 - player.contribution2 - player.contribution3 - player.contribution4 ) def get_timeout_seconds(player): return 1 * 60 class Contribute6_dynamic(Page): """This is the sixth of 9 rounds of the Climate Protection Game. You can now decide how much you want to contribute to the climate pot.""" form_model = 'player' form_fields = ['contribution6'] def vars_for_template(player): return dict( amount_left=C.ENDOWMENT - player.contribution1 - player.contribution2 - player.contribution3 - player.contribution4 - player.contribution5 ) def get_timeout_seconds(player): return 1 * 60 class Contribute7_dynamic(Page): """This is the seventh of 9 rounds of the Climate Protection Game. You can now decide how much you want to contribute to the climate pot.""" form_model = 'player' form_fields = ['contribution7'] def vars_for_template(player): return dict( amount_left=C.ENDOWMENT - player.contribution1 - player.contribution2 - player.contribution3 - player.contribution4 - player.contribution5 - player.contribution6 ) def get_timeout_seconds(player): return 1 * 60 class Contribute8_dynamic(Page): """This is the eighth of 9 rounds of the Climate Protection Game. You can now decide how much you want to contribute to the climate pot.""" form_model = 'player' form_fields = ['contribution8'] def vars_for_template(player): return dict( amount_left=C.ENDOWMENT - player.contribution1 - player.contribution2 - player.contribution3 - player.contribution4 - player.contribution5 - player.contribution6- player.contribution7 ) def get_timeout_seconds(player): return 1 * 60 class Contribute9_dynamic(Page): """This is the ninth of 9 rounds of the Climate Protection Game. You can now decide how much you want to contribute to the climate pot.""" form_model = 'player' form_fields = ['contribution9'] def vars_for_template(player): return dict( amount_left=C.ENDOWMENT - player.contribution1 - player.contribution2 - player.contribution3 - player.contribution4 - player.contribution5 - player.contribution6 - player.contribution7 - player.contribution8 ) def get_timeout_seconds(player): return 1 * 60 class Contribute1ResultsWaitPage(WaitPage): after_all_players_arrive = set_contribution1_payoff body_text = "Please wait for the contributions of the other players." class Contribute2ResultsWaitPage(WaitPage): after_all_players_arrive = set_contribution2_payoff body_text = "Please wait for the contributions of the other players." class Contribute3ResultsWaitPage(WaitPage): after_all_players_arrive = set_contribution3_payoff body_text = "Please wait for the contributions of the other players." class Contribute4ResultsWaitPage(WaitPage): after_all_players_arrive = set_contribution4_payoff body_text = "Please wait for the contributions of the other players." class Contribute5ResultsWaitPage(WaitPage): after_all_players_arrive = set_contribution5_payoff body_text = "Please wait for the contributions of the other players." class Contribute6ResultsWaitPage(WaitPage): after_all_players_arrive = set_contribution6_payoff body_text = "Please wait for the contributions of the other players." class Contribute7ResultsWaitPage(WaitPage): after_all_players_arrive = set_contribution7_payoff body_text = "Please wait for the contributions of the other players." class Contribute8ResultsWaitPage(WaitPage): after_all_players_arrive = set_contribution8_payoff body_text = "Please wait for the contributions of the other players." class Contribute9ResultsWaitPage(WaitPage): after_all_players_arrive = set_contribution9_payoff body_text = "Please wait for the contributions of the other players." class Contribute1Results_dynamic(Page): """How much did every player contribute?""" def vars_for_template(player): return dict(name=player.id_in_group) def get_timeout_seconds(player): return 1 * 60 class Contribute2Results_dynamic(Page): """How much did every player contribute?""" def vars_for_template(player): return dict(name=player.id_in_group) def get_timeout_seconds(player): return 1 * 60 class Contribute3Results_dynamic(Page): """How much did every player contribute?""" def vars_for_template(player): return dict(name=player.id_in_group) def get_timeout_seconds(player): return 1 * 60 class Contribute4Results_dynamic(Page): """How much did every player contribute?""" def vars_for_template(player): return dict(name=player.id_in_group) def get_timeout_seconds(player): return 1 * 60 class Contribute5Results_dynamic(Page): """How much did every player contribute?""" def vars_for_template(player): return dict(name=player.id_in_group) def get_timeout_seconds(player): return 1 * 60 class Contribute6Results_dynamic(Page): """How much did every player contribute?""" def vars_for_template(player): return dict(name=player.id_in_group) def get_timeout_seconds(player): return 1 * 60 class Contribute7Results_dynamic(Page): """How much did every player contribute?""" def vars_for_template(player): return dict(name=player.id_in_group) def get_timeout_seconds(player): return 1 * 60 class Contribute8Results_dynamic(Page): """How much did every player contribute?""" def vars_for_template(player): return dict(name=player.id_in_group) def get_timeout_seconds(player): return 1 * 60 class Contribute9Results_dynamic(Page): """How much did every player contribute?""" def vars_for_template(player): return dict(name=player.id_in_group) def get_timeout_seconds(player): return 1 * 60 #Threshold and Group Results class Threshold(Page): """Threshold level""" def vars_for_template(player): return dict( total_earnings=player.group.total_contribution123456789_dynamic, final_amount_left=C.ENDOWMENT - player.contribution1 - player.contribution2 - player.contribution3 - player.contribution4 - player.contribution5 - player.contribution6 - player.contribution7 - player.contribution8 - player.contribution9) def get_timeout_seconds(player): return 1 * 60 class ResultsDynamic(Page): """Players payoff: How much each has earned""" def vars_for_template(player): return dict( total_earnings=player.group.total_contribution123456789_dynamic, final_amount_left=C.ENDOWMENT - player.contribution1 - player.contribution2 - player.contribution3 - player.contribution4 - player.contribution5 - player.contribution6 - player.contribution7 - player.contribution8 - player.contribution9) def get_timeout_seconds(player): return 2 * 60 class ResultsDynamic_Final(Page): pass #Other class ResultsWaitPage(WaitPage): wait_for_all_groups = True body_text = "Please wait for the other players in the experiment." class ResultsWaitPage1(WaitPage): after_all_players_arrive = set_payoffs body_text = "Please wait for the contributions of the other players." #Sequence page_sequence = [FirstPage, FirstFirstPage, LeadershipWaitPage, Leadership, LeadershipResults, Pledge1_Leader_static_Followerstep, Pledge1_Leader_static, Pledge1_Leader_choice_static, Pledge1_1WaitPage, Pledge1_Leader_static_overview, Pledge1_Leader_static_Leaderstep, Pledge1_Follower_static, Pledge1_ResultsWaitPage, Pledge1_Results_static, Pledge1_LastPage_static, Contribution1WaitPage, Contribute1_dynamic, Contribute1ResultsWaitPage, Contribute1Results_dynamic, Contribution2WaitPage, Contribute2_dynamic, Contribute2ResultsWaitPage, Contribute2Results_dynamic, Contribution3WaitPage, Contribute3_dynamic, Contribute3ResultsWaitPage, Contribute3Results_dynamic, EndBlock1, EndBlock1WaitPage, Pledge4_Leader_static_Followerstep, Pledge4_Leader_static, Pledge4_Leader_choice_static, Pledge4_1WaitPage, Pledge4_Leader_static_overview, Pledge4_Leader_static_Leaderstep, Pledge4_Follower_static, Pledge4_ResultsWaitPage, Pledge4_Results_static, Pledge4_LastPage_static, Contribution4WaitPage, Contribute4_dynamic, Contribute4ResultsWaitPage, Contribute4Results_dynamic, Contribution5WaitPage, Contribute5_dynamic, Contribute5ResultsWaitPage, Contribute5Results_dynamic, Contribution6WaitPage, Contribute6_dynamic, Contribute6ResultsWaitPage, Contribute6Results_dynamic, EndBlock4, EndBlock4WaitPage, Pledge7_Leader_static_Followerstep, Pledge7_Leader_static, Pledge7_Leader_choice_static, Pledge7_1WaitPage, Pledge7_Leader_static_overview, Pledge7_Leader_static_Leaderstep, Pledge7_Follower_static, Pledge7_ResultsWaitPage, Pledge7_Results_static, Pledge7_LastPage_static, Contribution7WaitPage, Contribute7_dynamic, Contribute7ResultsWaitPage, Contribute7Results_dynamic, Contribution8WaitPage, Contribute8_dynamic, Contribute8ResultsWaitPage, Contribute8Results_dynamic, Contribution9WaitPage, Contribute9_dynamic, Contribute9ResultsWaitPage, Contribute9Results_dynamic, ResultsWaitPage, ResultsWaitPage1, ResultsDynamic, ResultsDynamic_Final ]