from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) from django.utils import translation from django import http from django.conf import settings import random from math import atan, degrees, sqrt, tan, pi from .utils import compute_line, intersection_point, distance, max_tuple import itertools author = 'Your name here' doc = """ Your app description """ class Constants(BaseConstants): name_in_url = 'Leader' players_per_group = 6 num_rounds = 20 endowment = c(20) # randrounds = random.sample(range(1,2+1), k=2) randrounds = random.sample(range(1,20+1), k=4) print("randrounds") print(randrounds) class Player(BasePlayer): fake_earnings = models.CurrencyField() personal_ID = models.StringField() incorrect_attempts_leaderrole = models.IntegerField() leader = models.StringField() leader_role = models.StringField(choices=[ ["Attacker", 'We are in Position A'], ["Defender", 'We are in Position Z'] ], label = "", widget=widgets.RadioSelect) signal = models.StringField() expectation_confl = models.CurrencyField() correct_expectation_confl = models.CurrencyField() correct_expectation_confl_perround = models.CurrencyField() earnings_expectation_confl = models.CurrencyField() condition = models.StringField() counterbalance_choice = models.StringField(choices=[['group1','group1'],['group2','group2'],['group3','group3'],['group4','group4'],['group5','group5'],['group6','group6'],['group7','group7'],['group8','group8'],['group9','group9'],['group10','group10'],['group11','group11'],['group12','group12'],['group13','group13'], ['group14','group14'],['group15','group15'],['group16','group16'],['group17','group17'],['group18','group18'],['group19','group19'],['group20','group20'],['group21','group21'],['group22','group22'],['group23','group23'],['group24','group24'],['group25','group25'],['group26','group26'], ['group27','group27'],['group28','group28'],['group29','group29'],['group30','group30'],['group31','group31'],['group32','group32'],['group33','group33'],['group34','group34'],['group35','group35'],['group36','group36'],['group37','group37'],['group38','group38'],['group39','group39'], ['group40','group40'],['group41','group41'],['group42','group42'],['group43','group43'],['group44','group44'],['group45','group45'],['group46','group46'],['group47','group47'],['group48','group48'],['group49','group49'],['group50','group50'],['group51','group51'],['group52','group52']]) #Questions after experiment total_signalhonest_group1 = models.CurrencyField() total_signalhonest_group2 = models.CurrencyField() exp_signalhonest = models.CurrencyField() exp_earnings = models.CurrencyField() reelect = models.StringField(choices=[ ["No", 'No'], ["Yes", 'Yes'] ], label = "", widget=widgets.RadioSelect) exp_RoleArounds = models.CurrencyField() exp_RoleBrounds = models.CurrencyField() increase_leaderendorse = models.CurrencyField() decrease_leaderendorse = models.CurrencyField() totalincrease_leaderendorse = models.CurrencyField() totaldecrease_leaderendorse = models.CurrencyField() totalincrease_leaderendorse_euro = models.CurrencyField() totaldecrease_leaderendorse_euro = models.CurrencyField() ScenarionAA = models.IntegerField(choices=[ [1, '1 not socially appropriate'], [2, '2 '], [3, '3 '], [4, '4 '], [5, '5 '], [6, '6 '], [7, '7 very socially appropriate'], ], label="Your group is in Position A. How socially appropriate do you think it is for the coordinator to communicate that your group is in Position A?", widget=widgets.RadioSelectHorizontal) ScenarionAB = models.IntegerField(choices=[ [1, '1 not socially appropriate'], [2, '2 '], [3, '3 '], [4, '4 '], [5, '5 '], [6, '6 '], [7, '7 very socially appropriate'], ], label="Your group is in Position A. How socially appropriate do you think it is for the coordinator to communicate that your group is in Position Z?", widget=widgets.RadioSelectHorizontal) ScenarionBA = models.IntegerField(choices=[ [1, '1 not socially appropriate'], [2, '2 '], [3, '3 '], [4, '4 '], [5, '5 '], [6, '6 '], [7, '7 very socially appropriate'], ], label="Your group is in Position Z. How socially appropriate do you think it is for the coordinator to communicate that your group is in Position A?", widget=widgets.RadioSelectHorizontal) ScenarionBB = models.IntegerField(choices=[ [1, '1 not socially appropriate'], [2, '2 '], [3, '3 '], [4, '4 '], [5, '5 '], [6, '6 '], [7, '7 very socially appropriate'], ], label="Your group is in Position Z. How socially appropriate do you think it is for the coordinator to communicate that your group is in Position Z?", widget=widgets.RadioSelectHorizontal) coh1_solidarity = models.IntegerField(choices=[ [1, '1 strongly disagree'], [2, '2 '], [3, '3 '], [4, '4 '], [5, '5 '], [6, '6 '], [7, '7 strongly agree'], ], label="I feel a bond with my group.", widget=widgets.RadioSelectHorizontal) coh2_solidarity = models.IntegerField(choices=[ [1, '1 strongly disagree'], [2, '2 '], [3, '3 '], [4, '4 '], [5, '5 '], [6, '6 '], [7, '7 strongly agree'], ], label="I feel solidarity with my group.", widget=widgets.RadioSelectHorizontal) coh3_solidarity = models.IntegerField(choices=[ [1, '1 strongly disagree'], [2, '2 '], [3, '3 '], [4, '4 '], [5, '5 '], [6, '6 '], [7, '7 strongly agree'], ], label="I feel committed to my group.", widget=widgets.RadioSelectHorizontal) coh4_satisfaction = models.IntegerField(choices=[ [1, '1 strongly disagree'], [2, '2 '], [3, '3 '], [4, '4 '], [5, '5 '], [6, '6 '], [7, '7 strongly agree'], ], label="I am glad to be my group.", widget=widgets.RadioSelectHorizontal) coh5_satisfaction = models.IntegerField(choices=[ [1, '1 strongly disagree'], [2, '2 '], [3, '3 '], [4, '4 '], [5, '5 '], [6, '6 '], [7, '7 strongly agree'], ], label="I think that my group has a lot to be proud of.", widget=widgets.RadioSelectHorizontal) coh6_satisfaction = models.IntegerField(choices=[ [1, '1 strongly disagree'], [2, '2 '], [3, '3 '], [4, '4 '], [5, '5 '], [6, '6 '], [7, '7 strongly agree'], ], label="It is pleasant to be my group.", widget=widgets.RadioSelectHorizontal) coh7_satisfaction = models.IntegerField(choices=[ [1, '1 strongly disagree'], [2, '2 '], [3, '3 '], [4, '4 '], [5, '5 '], [6, '6 '], [7, '7 strongly agree'], ], label="Being my group gives me a good feeling.", widget=widgets.RadioSelectHorizontal) compr_quest_1 = models.IntegerField(choices=[ [1, 'correct'], [2, 'incorrect'] ], label = "", widget=widgets.RadioSelect) compr_quest_2 = models.IntegerField(choices=[ [1, 'correct'], [2, 'incorrect'] ], label = "", widget=widgets.RadioSelect) compr_quest_3 = models.IntegerField(choices=[ [1, 'correct'], [2, 'incorrect'] ], label = "", widget=widgets.RadioSelect) compr_quest_4 = models.IntegerField(choices=[ [1, 'correct'], [2, 'incorrect'] ], label = "", widget=widgets.RadioSelect) compr_quest_5 = models.IntegerField(choices=[ [1, 'correct'], [2, 'incorrect'] ], label = "", widget=widgets.RadioSelect) compr_quest_6 = models.IntegerField(choices=[ [1, 'correct'], [2, 'incorrect'] ], label = "", widget=widgets.RadioSelect) compr_quest_7 = models.IntegerField(choices=[ [1, 'what the coordinator thinks is best'], [2, 'what the coordinator is told the Position is'] ], label = "", widget=widgets.RadioSelect) compr_quest_8 = models.IntegerField(choices=[ [1, 'Members in Position A receive points from members in Position Z.'], [2, 'Members in Position Z receive points from members in Position A.'], [3, 'Members of neither group receive points from the other group.'], [4, 'Both groups receive additional points.'] ], label = "", widget=widgets.RadioSelect) compr_quest_9 = models.IntegerField(choices=[ [1, '0'], [2, '13'], [3, '15'], [4, '25'], [5, '27'] ], label = "", widget=widgets.RadioSelect) compr_quest_10 = models.IntegerField(choices=[ [1, '0'], [2, '13'], [3, '15'], [4, '25'], [5, '27'] ], label = "", widget=widgets.RadioSelect) compr_quest_12 = models.IntegerField(choices=[ [1, '0'], [2, '5'], [3, '13'], [4, '15'], [5, '20'] ], label = "", widget=widgets.RadioSelect) compr_quest_11 = models.IntegerField(choices=[ [1, '0'], [2, '10'], [3, '20'], [4, '30'], [5, '40'] ], label = "", widget=widgets.RadioSelect) compr_quest_13 = models.IntegerField(choices=[ [1, '0'], [2, '5'], [3, '13'], [4, '15'], [5, '20'] ], label = "", widget=widgets.RadioSelect) compr_quest_14 = models.IntegerField(choices=[ [1, '0'], [2, '10'], [3, '20'], [4, '30'], [5, '40'] ], label = "", widget=widgets.RadioSelect) compr_quest_15 = models.IntegerField(choices=[ [1, 'Members in Position A receive points from members in Position Z.'], [2, 'Members in Position Z receive points from members in Position A.'], [3, 'Members of neither group receive points from the other group.'], [4, 'Both groups receive additional points.'] ], label = "", widget=widgets.RadioSelect) compr_quest_16 = models.IntegerField(choices=[ [1, '2'], [2, '8'], [3, '12'], [4, '18'], [5, '20'] ], label = "", widget=widgets.RadioSelect) compr_quest_17 = models.IntegerField(choices=[ [1, '2'], [2, '8'], [3, '12'], [4, '18'], [5, '20'] ], label = "", widget=widgets.RadioSelect) compr_quest_18 = models.IntegerField(choices=[ [1, '0'], [2, '10'], [3, '20'], [4, '30'], [5, '40'] ], label = "", widget=widgets.RadioSelect) compr_quest_19 = models.IntegerField(choices=[ [1, '4'], [2, '6'], [3, '14'], [4, '16'], [5, '20'] ], label = "", widget=widgets.RadioSelect) compr_quest_20 = models.IntegerField(choices=[ [1, '4'], [2, '6'], [3, '14'], [4, '16'], [5, '20'] ], label = "", widget=widgets.RadioSelect) compr_quest_21 = models.IntegerField(choices=[ [1, '0'], [2, '10'], [3, '20'], [4, '30'], [5, '40'] ], label = "", widget=widgets.RadioSelect) #standard game contribution_keep = models.CurrencyField() role_player = models.StringField() group_player = models.StringField() keep = models.CurrencyField() keep_aft_approp = models.CurrencyField() keep = models.CurrencyField() keep_aft_approp = models.CurrencyField() avgpoeuro = models.CurrencyField() avgpayoff = models.CurrencyField() payoffstore = models.CurrencyField() avgpoeuro_total = models.CurrencyField() avgpoeuro_total_float = models.FloatField() avgpoeuro_float = models.FloatField() exp_earnings_float = models.FloatField() earnings_expectation_confl_float = models.FloatField() totalincrease_leaderendorse_euro_float = models.FloatField() totaldecrease_leaderendorse_euro_float = models.FloatField() g1_total_contribution_confl = models.CurrencyField() g2_total_contribution_confl = models.CurrencyField() g1_total_keep = models.CurrencyField() g2_total_keep = models.CurrencyField() g1_success = models.BooleanField() g2_success = models.BooleanField() contribution_confl = models.CurrencyField( min=0, max=Constants.endowment ) def group(self): if self.id_in_group == 1 or self.id_in_group == 2 or self.id_in_group == 3: self.group_player = 'Group1' return 'Group1' else: self.group_player = 'Group2' return 'Group2' def set_payoffs_avgpoeuro(self): #print(Constants.randrounds) payoffstore = 0 for x in Constants.randrounds: payoff = self.in_round(x).payoff payoff = c(payoff).to_real_world_currency(self.session) payoffstore += payoff avgpayoff = payoffstore avgpoeuro = avgpayoff self.participant.vars['avgpoeuro'] = avgpoeuro print('avgpoeuro') print(avgpoeuro) return avgpoeuro class Group(BaseGroup): #standard game total_keep_att = models.CurrencyField() total_keep_def = models.CurrencyField() appropriated_resources = models.CurrencyField() total_contribution_confl_att = models.CurrencyField() total_contribution_confl_def = models.CurrencyField() attacker_success = models.BooleanField() total_share_att = models.CurrencyField() total_share_def = models.CurrencyField() individual_share_chal_def = models.CurrencyField() individual_share_chal_att = models.CurrencyField() p1_payoff = models.CurrencyField() p2_payoff = models.CurrencyField() p3_payoff = models.CurrencyField() p4_payoff = models.CurrencyField() p5_payoff = models.CurrencyField() p6_payoff = models.CurrencyField() random_role_g1 = models.StringField() random_role_g2 = models.StringField() def role(self): players = self.get_players() p1 = self.get_player_by_id(1) p2 = self.get_player_by_id(2) p3 = self.get_player_by_id(3) p4 = self.get_player_by_id(4) p5 = self.get_player_by_id(5) p6 = self.get_player_by_id(6) #random_role_g1 = random.choice(['Attacker', 'Defender']) random_sequence1 = ["Defender", "Attacker", "Defender", "Attacker", "Attacker", "Defender", "Defender", "Defender", "Attacker", "Attacker", "Defender", "Attacker", "Defender", "Defender", "Defender", "Attacker", "Attacker", "Attacker", "Attacker", "Defender"] random_sequence2 = ["Defender", "Defender", "Attacker", "Attacker", "Defender", "Defender", "Attacker", "Attacker", "Attacker", "Defender", "Attacker", "Defender", "Attacker", "Attacker", "Attacker", "Defender", "Defender", "Attacker", "Defender", "Defender"] random_sequence3 = ["Attacker", "Defender", "Defender", "Defender", "Attacker", "Defender", "Attacker", "Attacker", "Defender", "Attacker", "Defender", "Attacker", "Defender", "Defender", "Defender", "Attacker", "Defender", "Attacker", "Attacker", "Attacker"] random_sequence4 = ["Defender", "Attacker", "Defender", "Defender", "Attacker", "Attacker", "Defender", "Attacker", "Defender", "Attacker", "Defender", "Attacker", "Attacker", "Attacker", "Defender", "Defender", "Defender", "Defender", "Attacker", "Attacker"] random_sequence5 = ["Attacker", "Defender", "Attacker", "Defender", "Defender", "Defender", "Defender", "Attacker", "Attacker", "Defender", "Defender", "Defender", "Attacker", "Defender", "Attacker", "Attacker", "Attacker", "Attacker", "Defender", "Attacker"] random_sequence6 = ["Defender", "Attacker", "Attacker", "Defender", "Defender", "Attacker", "Attacker", "Attacker", "Defender", "Attacker", "Defender", "Defender", "Attacker", "Defender", "Attacker", "Defender", "Defender", "Attacker", "Attacker", "Defender"] random_sequence7 = ["Attacker", "Defender", "Defender", "Attacker", "Defender", "Attacker", "Defender", "Defender", "Defender", "Attacker", "Defender", "Attacker", "Attacker", "Attacker", "Attacker", "Defender", "Attacker", "Defender", "Defender", "Attacker"] random_sequence8 = ["Attacker", "Defender", "Defender", "Attacker", "Defender", "Defender", "Defender", "Attacker", "Defender", "Defender", "Defender", "Attacker", "Attacker", "Attacker", "Attacker", "Defender", "Attacker", "Attacker", "Defender", "Attacker"] random_sequence9 = ["Attacker", "Attacker", "Attacker", "Defender", "Attacker", "Defender", "Attacker", "Defender", "Defender", "Attacker", "Defender", "Attacker", "Defender", "Attacker", "Defender", "Defender", "Attacker", "Attacker", "Defender", "Defender"] random_sequence10 = ["Defender", "Attacker", "Attacker", "Defender", "Defender", "Attacker", "Defender", "Defender", "Defender", "Attacker", "Attacker", "Defender", "Attacker", "Attacker", "Attacker", "Defender", "Defender", "Defender", "Attacker", "Attacker"] random_sequence11 = ["Defender", "Attacker", "Attacker", "Attacker", "Defender", "Defender", "Defender", "Attacker", "Defender", "Attacker", "Attacker", "Defender", "Attacker", "Defender", "Attacker", "Defender", "Defender", "Defender", "Attacker", "Attacker"] random_sequence12 = ["Attacker", "Attacker", "Attacker", "Defender", "Defender", "Attacker", "Defender", "Defender", "Defender", "Attacker", "Attacker", "Defender", "Defender", "Attacker", "Attacker", "Defender", "Defender", "Defender", "Attacker", "Attacker"] random_sequence13 = ["Attacker", "Defender", "Attacker", "Defender", "Defender", "Attacker", "Defender", "Defender", "Attacker", "Attacker", "Defender", "Defender", "Attacker", "Defender", "Attacker", "Attacker", "Attacker", "Attacker", "Defender", "Defender"] if p1.participant.vars['counterbalance_choice'] == 'group1': sequence = random_sequence1 condition = 'honest' if p1.participant.vars['counterbalance_choice'] == 'group2': sequence = random_sequence1 condition = 'deception' if p1.participant.vars['counterbalance_choice'] == 'group3': sequence = random_sequence2 condition = 'honest' if p1.participant.vars['counterbalance_choice'] == 'group4': sequence = random_sequence2 condition = 'deception' if p1.participant.vars['counterbalance_choice'] == 'group5': sequence = random_sequence3 condition = 'honest' if p1.participant.vars['counterbalance_choice'] == 'group6': sequence = random_sequence3 condition = 'deception' if p1.participant.vars['counterbalance_choice'] == 'group7': sequence = random_sequence4 condition = 'honest' if p1.participant.vars['counterbalance_choice'] == 'group8': sequence = random_sequence4 condition = 'deception' if p1.participant.vars['counterbalance_choice'] == 'group9': sequence = random_sequence5 condition = 'honest' if p1.participant.vars['counterbalance_choice'] == 'group10': sequence = random_sequence5 condition = 'deception' if p1.participant.vars['counterbalance_choice'] == 'group11': sequence = random_sequence6 condition = 'honest' if p1.participant.vars['counterbalance_choice'] == 'group12': sequence = random_sequence6 condition = 'deception' if p1.participant.vars['counterbalance_choice'] == 'group13': sequence = random_sequence7 condition = 'honest' if p1.participant.vars['counterbalance_choice'] == 'group14': sequence = random_sequence7 condition = 'deception' if p1.participant.vars['counterbalance_choice'] == 'group15': sequence = random_sequence8 condition = 'honest' if p1.participant.vars['counterbalance_choice'] == 'group16': sequence = random_sequence8 condition = 'deception' if p1.participant.vars['counterbalance_choice'] == 'group17': sequence = random_sequence9 condition = 'honest' if p1.participant.vars['counterbalance_choice'] == 'group18': sequence = random_sequence9 condition = 'deception' if p1.participant.vars['counterbalance_choice'] == 'group19': sequence = random_sequence10 condition = 'honest' if p1.participant.vars['counterbalance_choice'] == 'group20': sequence = random_sequence10 condition = 'deception' if p1.participant.vars['counterbalance_choice'] == 'group21': sequence = random_sequence11 condition = 'honest' if p1.participant.vars['counterbalance_choice'] == 'group22': sequence = random_sequence11 condition = 'deception' if p1.participant.vars['counterbalance_choice'] == 'group23': sequence = random_sequence12 condition = 'honest' if p1.participant.vars['counterbalance_choice'] == 'group24': sequence = random_sequence12 condition = 'deception' if p1.participant.vars['counterbalance_choice'] == 'group25': sequence = random_sequence13 condition = 'honest' if p1.participant.vars['counterbalance_choice'] == 'group26': sequence = random_sequence13 condition = 'deception' if p1.participant.vars['counterbalance_choice'] == 'group27': sequence = random_sequence1 condition = 'honest' if p1.participant.vars['counterbalance_choice'] == 'group28': sequence = random_sequence1 condition = 'deception' if p1.participant.vars['counterbalance_choice'] == 'group29': sequence = random_sequence2 condition = 'honest' if p1.participant.vars['counterbalance_choice'] == 'group30': sequence = random_sequence2 condition = 'deception' if p1.participant.vars['counterbalance_choice'] == 'group31': sequence = random_sequence3 condition = 'honest' if p1.participant.vars['counterbalance_choice'] == 'group32': sequence = random_sequence3 condition = 'deception' if p1.participant.vars['counterbalance_choice'] == 'group33': sequence = random_sequence4 condition = 'honest' if p1.participant.vars['counterbalance_choice'] == 'group34': sequence = random_sequence4 condition = 'deception' if p1.participant.vars['counterbalance_choice'] == 'group35': sequence = random_sequence5 condition = 'honest' if p1.participant.vars['counterbalance_choice'] == 'group36': sequence = random_sequence5 condition = 'deception' if p1.participant.vars['counterbalance_choice'] == 'group37': sequence = random_sequence6 condition = 'honest' if p1.participant.vars['counterbalance_choice'] == 'group38': sequence = random_sequence6 condition = 'deception' if p1.participant.vars['counterbalance_choice'] == 'group39': sequence = random_sequence7 condition = 'honest' if p1.participant.vars['counterbalance_choice'] == 'group40': sequence = random_sequence7 condition = 'deception' if p1.participant.vars['counterbalance_choice'] == 'group41': sequence = random_sequence8 condition = 'honest' if p1.participant.vars['counterbalance_choice'] == 'group42': sequence = random_sequence8 condition = 'deception' if p1.participant.vars['counterbalance_choice'] == 'group43': sequence = random_sequence9 condition = 'honest' if p1.participant.vars['counterbalance_choice'] == 'group44': sequence = random_sequence9 condition = 'deception' if p1.participant.vars['counterbalance_choice'] == 'group45': sequence = random_sequence10 condition = 'honest' if p1.participant.vars['counterbalance_choice'] == 'group46': sequence = random_sequence10 condition = 'deception' if p1.participant.vars['counterbalance_choice'] == 'group47': sequence = random_sequence11 condition = 'honest' if p1.participant.vars['counterbalance_choice'] == 'group48': sequence = random_sequence11 condition = 'deception' if p1.participant.vars['counterbalance_choice'] == 'group49': sequence = random_sequence12 condition = 'honest' if p1.participant.vars['counterbalance_choice'] == 'group50': sequence = random_sequence12 condition = 'deception' if p1.participant.vars['counterbalance_choice'] == 'group51': sequence = random_sequence13 condition = 'honest' if p1.participant.vars['counterbalance_choice'] == 'group52': sequence = random_sequence13 condition = 'deception' if self.round_number == 1: random_role_g1 = random_sequence1[0] if self.round_number == 2: random_role_g1 = random_sequence1[1] if self.round_number == 3: random_role_g1 = random_sequence1[2] if self.round_number == 4: random_role_g1 = random_sequence1[3] if self.round_number == 5: random_role_g1 = random_sequence1[4] if self.round_number == 6: random_role_g1 = random_sequence1[5] if self.round_number == 7: random_role_g1 = random_sequence1[6] if self.round_number == 8: random_role_g1 = random_sequence1[7] if self.round_number == 9: random_role_g1 = random_sequence1[8] if self.round_number == 10: random_role_g1 = random_sequence1[9] if self.round_number == 11: random_role_g1 = random_sequence1[10] if self.round_number == 12: random_role_g1 = random_sequence1[11] if self.round_number == 13: random_role_g1 = random_sequence1[12] if self.round_number == 14: random_role_g1 = random_sequence1[13] if self.round_number == 15: random_role_g1 = random_sequence1[14] if self.round_number == 16: random_role_g1 = random_sequence1[15] if self.round_number == 17: random_role_g1 = random_sequence1[16] if self.round_number == 18: random_role_g1 = random_sequence1[17] if self.round_number == 19: random_role_g1 = random_sequence1[18] if self.round_number == 20: random_role_g1 = random_sequence1[19] if random_role_g1 == 'Attacker': random_role_g2 = 'Defender' else: random_role_g2 = 'Attacker' p1.role_player = random_role_g1 p2.role_player = random_role_g1 p3.role_player = random_role_g1 p4.role_player = random_role_g2 p5.role_player = random_role_g2 p6.role_player = random_role_g2 # print("role_player") # print(p1.role_player) # print(p2.role_player) # print(p3.role_player) # print(p4.role_player) # print(p5.role_player) # print(p6.role_player) p1.leader = 'Leader' p2.leader = 'Fighter' p3.leader = 'Fighter' p4.leader = 'Leader' p5.leader = 'Fighter' p6.leader = 'Fighter' p1.condition = condition p2.condition = condition p3.condition = condition p4.condition = condition p5.condition = condition p6.condition = condition print("Condition") print(p1.condition) p1.group_player = 'Group1' p2.group_player = 'Group1' p3.group_player = 'Group1' p4.group_player = 'Group2' p5.group_player = 'Group2' p6.group_player = 'Group2' p1.incorrect_attempts_leaderrole = 0 p4.incorrect_attempts_leaderrole = 0 # print("leader") # print(p1.leader) # print(p2.leader) # print(p3.leader) # print(p4.leader) # print(p5.leader) # print(p6.leader) def leaderrole(self): players = self.get_players() p1 = self.get_player_by_id(1) p2 = self.get_player_by_id(2) p3 = self.get_player_by_id(3) p4 = self.get_player_by_id(4) p5 = self.get_player_by_id(5) p6 = self.get_player_by_id(6) p1.leader_role = p1.leader_role p2.leader_role = p1.leader_role p3.leader_role = p1.leader_role p4.leader_role = p4.leader_role p5.leader_role = p4.leader_role p6.leader_role = p4.leader_role if p1.leader_role == p1.role_player: p1.signal = 'Honest' else: p1.signal = 'Dishonest' if p4.leader_role == p4.role_player: p4.signal = 'Honest' else: p4.signal = 'Dishonest' print("Real Role G1") print(p1.role_player) print("Role According To Leader G1") print(p1.leader_role) print("Signal Honesty G1") print(p1.signal) print("Real Role G2") print(p4.role_player) print("Role According To Leader G2") print(p4.leader_role) print("Signal Honesty G2") print(p4.signal) for p in players: if self.round_number == 1: if p1.signal == 'Honest': p.total_signalhonest_group1 = 1 else: p.total_signalhonest_group1 = 0 if p4.signal == 'Honest': p.total_signalhonest_group2 = 1 else: p.total_signalhonest_group2 = 0 for p in players: if self.round_number > 1: if p1.signal == 'Honest': p.total_signalhonest_group1 = p.in_round(self.round_number-1).total_signalhonest_group1 + 1 else: p.total_signalhonest_group1 = p.in_round(self.round_number-1).total_signalhonest_group1 if p4.signal == 'Honest': p.total_signalhonest_group2 = p.in_round(self.round_number-1).total_signalhonest_group2 + 1 else: p.total_signalhonest_group2 = p.in_round(self.round_number-1).total_signalhonest_group2 print("Counter Signal Honesty G1") print(p1.total_signalhonest_group1) print("Counter Signal Honesty G2") print(p4.total_signalhonest_group2) def calculate_payoffs(self): players = self.get_players() p1 = self.get_player_by_id(1) p2 = self.get_player_by_id(2) p3 = self.get_player_by_id(3) p4 = self.get_player_by_id(4) p5 = self.get_player_by_id(5) p6 = self.get_player_by_id(6) for p in players: # print(p.leader) # Conflict total contribution Attacker contributions_confl_att = [p.contribution_confl for p in players if p.role_player == 'Attacker' and p.leader == 'Fighter'] self.total_contribution_confl_att = sum(contributions_confl_att) # print(self.total_contribution_confl_att) # Conflict total contribution Defender contributions_confl_def = [p.contribution_confl for p in players if p.role_player == 'Defender' and p.leader == 'Fighter'] self.total_contribution_confl_def = sum(contributions_confl_def) # print(self.total_contribution_confl_def) total_keep_att = 0 total_keep_def = 0 for p in players: if p.leader == 'Fighter': if p.role_player == 'Defender': p.keep = Constants.endowment - (p.contribution_confl) total_keep_def = (total_keep_def + p.keep) if self.total_contribution_confl_att > self.total_contribution_confl_def: p.keep_aft_approp = 0 else: p.keep_aft_approp = p.keep else: p.keep = Constants.endowment - (p.contribution_confl) total_keep_att = (total_keep_att + p.keep) p.keep_aft_approp = p.keep self.total_keep_att = total_keep_att self.total_keep_def = total_keep_def if self.total_contribution_confl_att > self.total_contribution_confl_def: self.appropriated_resources = (self.total_keep_def) self.individual_share_chal_att = (self.appropriated_resources / 2) self.total_share_att = self.appropriated_resources + self.total_keep_att self.total_share_def = 0 self.individual_share_chal_def = 0 self.attacker_success = True else: self.individual_share_chal_att = 0 self.individual_share_chal_def = 0 self.total_share_def = self.total_keep_def self.total_share_att = self.total_keep_att self.attacker_success = False for p in players: if p.leader == 'Fighter': if p.role_player == 'Attacker': p.payoff = p.keep_aft_approp + self.individual_share_chal_att else: p.payoff = p.keep_aft_approp + self.individual_share_chal_def #to calculate fake earnings to display to participants if p2.leader_role == 'Defender': if (p2.contribution_confl + p3.contribution_confl) < (p5.contribution_confl + p6.contribution_confl): p2.fake_earnings = 0 else: p2.fake_earnings = p2.keep if p2.leader_role == 'Attacker': if (p2.contribution_confl + p3.contribution_confl) > (p5.contribution_confl + p6.contribution_confl): p2.fake_earnings = p2.keep + ((p5.keep + p6.keep) / 2) else: p2.fake_earnings = p2.keep if p3.leader_role == 'Defender': if (p2.contribution_confl + p3.contribution_confl) < (p5.contribution_confl + p6.contribution_confl): p3.fake_earnings = 0 else: p3.fake_earnings = p3.keep if p3.leader_role == 'Attacker': if (p2.contribution_confl + p3.contribution_confl) > (p5.contribution_confl + p6.contribution_confl): p3.fake_earnings = p3.keep + ((p5.keep + p6.keep) / 2) else: p3.fake_earnings = p3.keep if p5.leader_role == 'Defender': if (p5.contribution_confl + p6.contribution_confl) < (p2.contribution_confl + p3.contribution_confl): p5.fake_earnings = 0 else: p5.fake_earnings = p5.keep if p5.leader_role == 'Attacker': if (p5.contribution_confl + p6.contribution_confl) > (p2.contribution_confl + p3.contribution_confl): p5.fake_earnings = p5.keep + ((p2.keep + p3.keep) / 2) else: p5.fake_earnings = p5.keep if p6.leader_role == 'Defender': if (p5.contribution_confl + p6.contribution_confl) < (p2.contribution_confl + p3.contribution_confl): p6.fake_earnings = 0 else: p6.fake_earnings = p6.keep if p6.leader_role == 'Attacker': if (p5.contribution_confl + p6.contribution_confl) > (p2.contribution_confl + p3.contribution_confl): p6.fake_earnings = p6.keep + ((p2.keep + p3.keep) / 2) else: p6.fake_earnings = p6.keep for p in players: if p.leader == 'Leader': if p.role_player == 'Attacker': if self.attacker_success == True: p.payoff = 40 else: p.payoff = 0 else: if self.attacker_success == True: p.payoff = 0 else: p.payoff = 40 for p in players: if p1.payoff == 40: p.g1_success = True p.g2_success = False else: p.g1_success = False p.g2_success = True self.p1_payoff = p1.payoff self.p2_payoff = p2.payoff self.p3_payoff = p3.payoff self.p4_payoff = p4.payoff self.p5_payoff = p5.payoff self.p6_payoff = p6.payoff for p in players: p.g1_total_contribution_confl = p2.contribution_confl + p3.contribution_confl p.g2_total_contribution_confl = p5.contribution_confl + p6.contribution_confl p.g1_total_keep = p2.keep + p3.keep p.g2_total_keep = p5.keep + p6.keep print("total invest conflict g1") print(p1.g1_total_contribution_confl) print("total invest conflict g2") print(p1.g2_total_contribution_confl) print("total keep g1") print(p1.g1_total_keep) print("total keep g2") print(p1.g2_total_keep) print("success g1") print(p1.g1_success) print("success g2") print(p1.g2_success) if self.round_number == 1: p1.correct_expectation_confl = 0 if p1.expectation_confl == ((p2.contribution_confl + p3.contribution_confl)/2): p1.correct_expectation_confl = 1 p1.correct_expectation_confl_perround = 1 else: p1.correct_expectation_confl = 0 p1.correct_expectation_confl_perround = 0 p4.correct_expectation_confl = 0 if p4.expectation_confl == ((p5.contribution_confl + p6.contribution_confl)/2): p4.correct_expectation_confl = 1 p4.correct_expectation_confl_perround = 1 else: p4.correct_expectation_confl = 0 p4.correct_expectation_confl_perround = 0 print("Counter Correct Expectation Conflict G1") print(p1.correct_expectation_confl) # print(((p2.contribution_confl + p3.contribution_confl)/2)) print("Counter Correct Expectation Conflict G2") print(p4.correct_expectation_confl) # print(((p5.contribution_confl + p6.contribution_confl)/2)) if self.round_number > 1: if p1.expectation_confl == ((p2.contribution_confl + p3.contribution_confl)/2): p1.correct_expectation_confl = p1.in_round(self.round_number-1).correct_expectation_confl + 1 p1.correct_expectation_confl_perround = 1 else: p1.correct_expectation_confl = p1.in_round(self.round_number-1).correct_expectation_confl p1.correct_expectation_confl_perround = 0 if p4.expectation_confl == ((p5.contribution_confl + p6.contribution_confl)/2): p4.correct_expectation_confl = p4.in_round(self.round_number-1).correct_expectation_confl + 1 p4.correct_expectation_confl_perround = 1 else: p4.correct_expectation_confl = p4.in_round(self.round_number-1).correct_expectation_confl p4.correct_expectation_confl_perround = 0 print("Counter Correct Expectation Conflict G1") print(p1.correct_expectation_confl) # print(((p2.contribution_confl + p3.contribution_confl)/2)) print("Counter Correct Expectation Conflict G2") print(p4.correct_expectation_confl) # print(((p5.contribution_confl + p6.contribution_confl)/2)) def set_exp(self): players = self.get_players() p1 = self.get_player_by_id(1) p2 = self.get_player_by_id(2) p3 = self.get_player_by_id(3) p4 = self.get_player_by_id(4) p5 = self.get_player_by_id(5) p6 = self.get_player_by_id(6) if p1.exp_signalhonest == p1.total_signalhonest_group1: p1.exp_earnings = 0.5 else: p1.exp_earnings = 0 if p2.exp_signalhonest == p1.total_signalhonest_group1: p2.exp_earnings = 0.5 else: p2.exp_earnings = 0 if p3.exp_signalhonest == p1.total_signalhonest_group1: p3.exp_earnings = 0.5 else: p3.exp_earnings = 0 if p4.exp_signalhonest == p4.total_signalhonest_group2: p4.exp_earnings = 0.5 else: p4.exp_earnings = 0 if p5.exp_signalhonest == p4.total_signalhonest_group2: p5.exp_earnings = 0.5 else: p5.exp_earnings = 0 if p6.exp_signalhonest == p4.total_signalhonest_group2: p6.exp_earnings = 0.5 else: p6.exp_earnings = 0 for p in players: print("honest") print(p.exp_earnings) if p.round_number == 20: for p in players: if p.exp_RoleArounds == 10: p.exp_earnings = p.exp_earnings + 0.5 print("RoleA") print(p.exp_earnings) if p.round_number == 20: for p in players: if p.exp_RoleBrounds == 10: p.exp_earnings = p.exp_earnings + 0.5 print("RoleB") print(p.exp_earnings) if p.round_number == 20: for p in players: p.participant.vars['exp_earnings'] = p.exp_earnings if p.round_number == 20: p1.totalincrease_leaderendorse = p2.increase_leaderendorse + p3.increase_leaderendorse p1.totaldecrease_leaderendorse = p2.decrease_leaderendorse + p3.decrease_leaderendorse p4.totalincrease_leaderendorse = p5.increase_leaderendorse + p6.increase_leaderendorse p4.totaldecrease_leaderendorse = p5.decrease_leaderendorse + p6.decrease_leaderendorse print("p1") print(p1.totalincrease_leaderendorse) print(p1.totaldecrease_leaderendorse) print("p1") print(p4.totalincrease_leaderendorse) print(p4.totaldecrease_leaderendorse) class Subsession(BaseSubsession): players_per_group = models.IntegerField()