from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) doc = """ This is a one-period public goods game with 2 players. """ class Constants(BaseConstants): name_in_url = 'Inequality_Study_Assigned' players_per_group = 8 num_rounds = 24 endowment = c(100) instructions_template = 'Inequality_Study_Assigned/instructions.html' class Subsession(BaseSubsession): def random_group_order(self): self.group_randomly() print(self.get_group_matrix()) def do_my_shuffle(self): #get all players in session players = self.get_players() #get total numbers of participants num_players = self.session.num_participants #couple participants to their variables for x in range(num_players): players[int(x)] = "p"+str(x+1) print(players) print("p"+str(x+1)+".coupled_HH") print("p"+str(x+1)+".coupled_HL") print("p"+str(x+1)+".coupled_LH") print("p"+str(x+1)+".coupled_LL") print("p"+str(x+1)+".multiplier") print("p"+str(x+1)+".endowment") #create variables to count itterations inside the loop x = 0 d={} #randomize players from random import shuffle shuffle(players) if self.round_number > 1: for p_self in self.get_players(): p_self.coupled_pother1 = p_self.in_round(self.round_number-1).coupled_pother1 p_self.coupled_pother2 = p_self.in_round(self.round_number-1).coupled_pother2 p_self.coupled_pother3 = p_self.in_round(self.round_number-1).coupled_pother3 p_self.coupled_pother4 = p_self.in_round(self.round_number-1).coupled_pother4 p_self.coupled_pother5 = p_self.in_round(self.round_number-1).coupled_pother5 p_self.coupled_pother6 = p_self.in_round(self.round_number-1).coupled_pother6 p_self.coupled_pother7 = p_self.in_round(self.round_number-1).coupled_pother7 p_self.coupled_pother8 = p_self.in_round(self.round_number-1).coupled_pother8 for p_self in self.get_players(): print("Paired Previously before shuffle") print("p1 other1:") print(p_self.coupled_pother1) print("p1 other2:") print(p_self.coupled_pother2) print("p1 other3:") print(p_self.coupled_pother3) print("p1 other4:") print(p_self.coupled_pother4) print("p1 other5:") print(p_self.coupled_pother5) print("p1 other6:") print(p_self.coupled_pother6) print("p1 other7:") print(p_self.coupled_pother7) print("p1 other8:") print(p_self.coupled_pother8) print("p.id") print(p_self.random_id) #randomize players from random import shuffle shuffle(players) import random if self.round_number == 1: number_list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24] print("Original list:", number_list) random.shuffle(number_list) print("List after first shuffle:", number_list) self.session.vars['ran_number_list'] = number_list # print("List after first shuffle:", number_list) print(self.session.vars['ran_number_list']) print(self.session.vars['ran_number_list'][0]) print(self.session.vars['ran_number_list'][1]) print(self.session.vars['ran_number_list'][2]) if self.round_number == self.session.vars['ran_number_list'][0]: matrix = self.get_group_matrix() new_structure = [[1,2], [3,4], [5,6], [7,8]] self.set_group_matrix(new_structure) if self.round_number == self.session.vars['ran_number_list'][1]: matrix = self.get_group_matrix() new_structure = [[1,3], [5,2], [8,6], [7,4]] self.set_group_matrix(new_structure) if self.round_number == self.session.vars['ran_number_list'][2]: matrix = self.get_group_matrix() new_structure = [[1,4], [3,5], [7,6], [8,2]] self.set_group_matrix(new_structure) if self.round_number == self.session.vars['ran_number_list'][3]: matrix = self.get_group_matrix() new_structure = [[1,5], [3,6], [4,8], [2,7]] self.set_group_matrix(new_structure) if self.round_number == self.session.vars['ran_number_list'][4]: matrix = self.get_group_matrix() new_structure = [[1,6], [3,7], [8,5], [4,2]] self.set_group_matrix(new_structure) if self.round_number == self.session.vars['ran_number_list'][5]: matrix = self.get_group_matrix() new_structure = [[1,7], [3,8], [5,4], [2,6]] self.set_group_matrix(new_structure) if self.round_number == self.session.vars['ran_number_list'][6]: matrix = self.get_group_matrix() new_structure = [[1,8], [3,2], [5,7], [4,6]] self.set_group_matrix(new_structure) if self.round_number == self.session.vars['ran_number_list'][7]: matrix = self.get_group_matrix() new_structure = [[1,2], [3,4], [5,6], [7,8]] self.set_group_matrix(new_structure) #repeat if self.round_number == self.session.vars['ran_number_list'][8]: matrix = self.get_group_matrix() new_structure = [[1,2], [3,4], [5,6], [7,8]] self.set_group_matrix(new_structure) if self.round_number == self.session.vars['ran_number_list'][9]: matrix = self.get_group_matrix() new_structure = [[1,3], [5,2], [8,6], [7,4]] self.set_group_matrix(new_structure) if self.round_number == self.session.vars['ran_number_list'][10]: matrix = self.get_group_matrix() new_structure = [[1,4], [3,5], [7,6], [8,2]] self.set_group_matrix(new_structure) if self.round_number == self.session.vars['ran_number_list'][11]: matrix = self.get_group_matrix() new_structure = [[1,5], [3,6], [4,8], [2,7]] self.set_group_matrix(new_structure) if self.round_number == self.session.vars['ran_number_list'][12]: matrix = self.get_group_matrix() new_structure = [[1,6], [3,7], [8,5], [4,2]] self.set_group_matrix(new_structure) if self.round_number == self.session.vars['ran_number_list'][13]: matrix = self.get_group_matrix() new_structure = [[1,7], [3,8], [5,4], [2,6]] self.set_group_matrix(new_structure) if self.round_number == self.session.vars['ran_number_list'][14]: matrix = self.get_group_matrix() new_structure = [[1,8], [3,2], [5,7], [4,6]] self.set_group_matrix(new_structure) if self.round_number == self.session.vars['ran_number_list'][15]: matrix = self.get_group_matrix() new_structure = [[1,2], [3,4], [5,6], [7,8]] self.set_group_matrix(new_structure) #repeat if self.round_number == self.session.vars['ran_number_list'][16]: matrix = self.get_group_matrix() new_structure = [[1,2], [3,4], [5,6], [7,8]] self.set_group_matrix(new_structure) if self.round_number == self.session.vars['ran_number_list'][17]: matrix = self.get_group_matrix() new_structure = [[1,3], [5,2], [8,6], [7,4]] self.set_group_matrix(new_structure) if self.round_number == self.session.vars['ran_number_list'][18]: matrix = self.get_group_matrix() new_structure = [[1,4], [3,5], [7,6], [8,2]] self.set_group_matrix(new_structure) if self.round_number == self.session.vars['ran_number_list'][19]: matrix = self.get_group_matrix() new_structure = [[1,5], [3,6], [4,8], [2,7]] self.set_group_matrix(new_structure) if self.round_number == self.session.vars['ran_number_list'][20]: matrix = self.get_group_matrix() new_structure = [[1,6], [3,7], [8,5], [4,2]] self.set_group_matrix(new_structure) if self.round_number == self.session.vars['ran_number_list'][21]: matrix = self.get_group_matrix() new_structure = [[1,7], [3,8], [5,4], [2,6]] self.set_group_matrix(new_structure) if self.round_number == self.session.vars['ran_number_list'][22]: matrix = self.get_group_matrix() new_structure = [[1,8], [3,2], [5,7], [4,6]] self.set_group_matrix(new_structure) if self.round_number == self.session.vars['ran_number_list'][23]: matrix = self.get_group_matrix() new_structure = [[1,2], [3,4], [5,6], [7,8]] self.set_group_matrix(new_structure) print(self.get_group_matrix()) class Group(BaseGroup): def SetType(self): q = 1 for p in self.get_players(): play_num = q q = q + 1 print(play_num) 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) p7 = self.get_player_by_id(7) p8 = self.get_player_by_id(8) if play_num >= 1: p1.endowment = 75 p1.multiplier = 1.7 p1.type = "HH" print("p1") print(p1.type) if play_num >= 2: p2.endowment = 75 p2.multiplier = 1.7 p2.type = "HH" print("p2") print(p2.type) if play_num >= 3: p3.endowment = 75 p3.multiplier = 1.3 p3.type = "HL" print("p3") print(p3.type) if play_num >= 4: p4.endowment = 75 p4.multiplier = 1.3 p4.type = "HL" print("p4") print(p4.type) if play_num >= 5: p5.endowment = 25 p5.multiplier = 1.7 p5.type = "LH" print("p5") print(p5.type) if play_num >= 6: p6.endowment = 25 p6.multiplier = 1.7 p6.type = "LH" print("p6") print(p6.type) if play_num >= 7: p7.endowment = 25 p7.multiplier = 1.3 p7.type = "LL" if play_num >= 8: p8.endowment = 25 p8.multiplier = 1.3 p8.type = "LL" for p in self.get_players(): p.participant.vars['multiplier'] = p.multiplier p.participant.vars['endowment'] = p.endowment p.participant.vars['type'] = p.type p.participant.vars['condition'] = p.condition # def random_group_order(self): # self.subsession.random_group_order() # def do_my_shuffle(self): # self.subsession.do_my_shuffle() total_contribution = models.CurrencyField() individual_share = models.CurrencyField() def set_type(self): for p in self.get_players(): if p.multiplier == 1.7 and p.endowment == 75: p.type = "HH" p.condition = self.session.config['condition'] for p in self.get_players(): if p.multiplier == 1.3 and p.endowment == 75: p.type = "HL" p.condition = self.session.config['condition'] for p in self.get_players(): if p.multiplier == 1.7 and p.endowment == 25: p.type = "LH" p.condition = self.session.config['condition'] for p in self.get_players(): if p.multiplier == 1.3 and p.endowment == 25: p.type = "LL" p.condition = self.session.config['condition'] x = 1 for p in self.get_players(): p.random_id = x x = x + 1 for p in self.get_players(): print(p.random_id) for p in self.get_players(): p.participant.vars['multiplier'] = p.multiplier p.participant.vars['endowment'] = p.endowment p.participant.vars['type'] = p.type p.participant.vars['random_id'] = p.random_id p.participant.vars['condition'] = p.condition def set_payoffs(self): print(self.round_number) #calculate pay-offs p1 = self.get_player_by_id(1) p2 = self.get_player_by_id(2) # p1.con_other = p2.contribution # p2.con_other = p1.contribution p1.type_partner = p2.type p2.type_partner = p1.type p1.addedtoPGG = p1.contribution * p1.multiplier p2.addedtoPGG = p2.contribution * p2.multiplier self.total_contribution = p1.addedtoPGG + p2.addedtoPGG self.individual_share = self.total_contribution / 2 p1.kept = (p1.endowment - p1.contribution) p2.kept = (p2.endowment - p2.contribution) p1.earnings = self.individual_share + (p1.endowment - p1.contribution) p2.earnings = self.individual_share + (p2.endowment - p2.contribution) #count accumulated_wealth if self.round_number == 1: p1.accumulated_wealth = p1.earnings p2.accumulated_wealth = p2.earnings else: p1.accumulated_wealth = p1.in_round(self.round_number-1).accumulated_wealth + p1.earnings p2.accumulated_wealth = p2.in_round(self.round_number-1).accumulated_wealth + p2.earnings for p in self.get_players(): p.participant.vars['earnings'] = p.earnings p.participant.vars['accumulated_wealth'] = p.accumulated_wealth if self.round_number == 1: #in first round there is no info yet if p2.type == "HH": p1.con_other1 = p2.contribution else: if p2.type == "HL": p1.con_other2 = p2.contribution else: if p2.type == "LH": p1.con_other3 = p2.contribution else: p1.con_other4 = p2.contribution if self.round_number > 1: if p2.type == "HH": p1.con_other1 = p1.in_round(self.round_number-1).con_other1 + p2.contribution p1.con_other2 = p1.in_round(self.round_number-1).con_other2 p1.con_other3 = p1.in_round(self.round_number-1).con_other3 p1.con_other4 = p1.in_round(self.round_number-1).con_other4 else: if p2.type == "HL": p1.con_other2 = p1.in_round(self.round_number-1).con_other2 + p2.contribution p1.con_other1 = p1.in_round(self.round_number-1).con_other1 p1.con_other3 = p1.in_round(self.round_number-1).con_other3 p1.con_other4 = p1.in_round(self.round_number-1).con_other4 else: if p2.type == "LH": p1.con_other3 = p1.in_round(self.round_number-1).con_other3 + p2.contribution p1.con_other1 = p1.in_round(self.round_number-1).con_other1 p1.con_other2 = p1.in_round(self.round_number-1).con_other2 p1.con_other4 = p1.in_round(self.round_number-1).con_other4 else: p1.con_other4 = p1.in_round(self.round_number-1).con_other4 + p2.contribution p1.con_other1 = p1.in_round(self.round_number-1).con_other1 p1.con_other2 = p1.in_round(self.round_number-1).con_other2 p1.con_other3 = p1.in_round(self.round_number-1).con_other3 if self.round_number == 1: #in first round there is no info yet if p1.type == "HH": p2.con_other1 = p1.contribution else: if p1.type == "HL": p2.con_other2 = p1.contribution else: if p1.type == "LH": p2.con_other3 = p1.contribution else: p2.con_other4 = p1.contribution if self.round_number > 1: if p1.type == "HH": p2.con_other1 = p2.in_round(self.round_number-1).con_other1 + p1.contribution p2.con_other2 = p2.in_round(self.round_number-1).con_other2 p2.con_other3 = p2.in_round(self.round_number-1).con_other3 p2.con_other4 = p2.in_round(self.round_number-1).con_other4 else: if p1.type == "HL": p2.con_other2 = p2.in_round(self.round_number-1).con_other2 + p1.contribution p2.con_other1 = p2.in_round(self.round_number-1).con_other1 p2.con_other3 = p2.in_round(self.round_number-1).con_other3 p2.con_other4 = p2.in_round(self.round_number-1).con_other4 else: if p1.type == "LH": p2.con_other3 = p2.in_round(self.round_number-1).con_other3 + p1.contribution p2.con_other1 = p2.in_round(self.round_number-1).con_other1 p2.con_other2 = p2.in_round(self.round_number-1).con_other2 p2.con_other4 = p2.in_round(self.round_number-1).con_other4 else: p2.con_other4 = p2.in_round(self.round_number-1).con_other4 + p1.contribution p2.con_other1 = p2.in_round(self.round_number-1).con_other1 p2.con_other2 = p2.in_round(self.round_number-1).con_other2 p2.con_other3 = p2.in_round(self.round_number-1).con_other3 if self.round_number > 1: p1.beliefs_HH = p1.in_round(self.round_number-1).beliefs_HH p1.beliefs_HL = p1.in_round(self.round_number-1).beliefs_HL p1.beliefs_LH = p1.in_round(self.round_number-1).beliefs_LH p1.beliefs_LL = p1.in_round(self.round_number-1).beliefs_LL p2.beliefs_HH = p2.in_round(self.round_number-1).beliefs_HH p2.beliefs_HL = p2.in_round(self.round_number-1).beliefs_HL p2.beliefs_LH = p2.in_round(self.round_number-1).beliefs_LH p2.beliefs_LL = p2.in_round(self.round_number-1).beliefs_LL print("Con Partner") print("p1 other1:") print(p1.con_other1) print("p1 other2:") print(p1.con_other2) print("p1 other3:") print(p1.con_other3) print("p1 other4:") print(p1.con_other4) print("---") print("p2 other1:") print(p2.con_other1) print("p2 other2:") print(p2.con_other2) print("p2 other3:") print(p2.con_other3) print("p2 other4:") print(p2.con_other4) print("believes HH =") print(p1.beliefs_HH) print("believes HL =") print(p1.beliefs_HL) print("believes LH =") print(p1.beliefs_LH) print("believes LL =") print(p1.beliefs_LL) print("believes HH =") print(p2.beliefs_HH) print("believes HL =") print(p2.beliefs_HL) print("believes LH =") print(p2.beliefs_LH) print("believes LL =") print(p2.beliefs_LL) if self.round_number == 1: #in first round there is no info yet if p1.random_id == 1: p1.coupled_pother1 = 1 else: if p1.random_id == 2: p1.coupled_pother2 = 2 else: if p1.random_id == 3: p1.coupled_pother3 = 3 else: if p1.random_id == 4: p1.coupled_pother4 = 4 else: if p1.random_id == 5: p1.coupled_pother5 = 5 else: if p1.random_id == 6: p1.coupled_pother6 = 6 else: if p1.random_id == 7: p1.coupled_pother7 = 7 else: p1.coupled_pother8 = 8 if self.round_number == 1: #in first round there is no info yet if p2.random_id == 1: p2.coupled_pother1 = 1 else: if p2.random_id == 2: p2.coupled_pother2 = 2 else: if p2.random_id == 3: p2.coupled_pother3 = 3 else: if p2.random_id == 4: p2.coupled_pother4 = 4 else: if p2.random_id == 5: p2.coupled_pother5 = 5 else: if p2.random_id == 6: p2.coupled_pother6 = 6 else: if p2.random_id == 7: p2.coupled_pother7 = 7 else: p2.coupled_pother8 = 8 if self.round_number == 1: #in first round there is no info yet if p2.random_id == 1: p1.coupled_pother1 = p1.coupled_pother1 + 1 else: if p2.random_id == 2: p1.coupled_pother2 = p1.coupled_pother2 + 2 else: if p2.random_id == 3: p1.coupled_pother3 = p1.coupled_pother3 + 3 else: if p2.random_id == 4: p1.coupled_pother4 = p1.coupled_pother4 + 4 else: if p2.random_id == 5: p1.coupled_pother5 = p1.coupled_pother5 + 5 else: if p2.random_id == 6: p1.coupled_pother6 = p1.coupled_pother6 + 6 else: if p2.random_id == 7: p1.coupled_pother7 = p1.coupled_pother7 + 7 else: p1.coupled_pother8 = p1.coupled_pother8 + 8 if self.round_number > 1: if p2.random_id == 1: p1.coupled_pother1 = p1.in_round(self.round_number-1).coupled_pother1 + 1 p1.coupled_pother2 = p1.in_round(self.round_number-1).coupled_pother2 p1.coupled_pother3 = p1.in_round(self.round_number-1).coupled_pother3 p1.coupled_pother4 = p1.in_round(self.round_number-1).coupled_pother4 p1.coupled_pother5 = p1.in_round(self.round_number-1).coupled_pother5 p1.coupled_pother6 = p1.in_round(self.round_number-1).coupled_pother6 p1.coupled_pother7 = p1.in_round(self.round_number-1).coupled_pother7 p1.coupled_pother8 = p1.in_round(self.round_number-1).coupled_pother8 else: if p2.random_id == 2: p1.coupled_pother2 = p1.in_round(self.round_number-1).coupled_pother2 + 2 p1.coupled_pother1 = p1.in_round(self.round_number-1).coupled_pother1 p1.coupled_pother3 = p1.in_round(self.round_number-1).coupled_pother3 p1.coupled_pother4 = p1.in_round(self.round_number-1).coupled_pother4 p1.coupled_pother5 = p1.in_round(self.round_number-1).coupled_pother5 p1.coupled_pother6 = p1.in_round(self.round_number-1).coupled_pother6 p1.coupled_pother7 = p1.in_round(self.round_number-1).coupled_pother7 p1.coupled_pother8 = p1.in_round(self.round_number-1).coupled_pother8 else: if p2.random_id == 3: p1.coupled_pother3 = p1.in_round(self.round_number-1).coupled_pother3 + 3 p1.coupled_pother1 = p1.in_round(self.round_number-1).coupled_pother1 p1.coupled_pother2 = p1.in_round(self.round_number-1).coupled_pother2 p1.coupled_pother4 = p1.in_round(self.round_number-1).coupled_pother4 p1.coupled_pother5 = p1.in_round(self.round_number-1).coupled_pother5 p1.coupled_pother6 = p1.in_round(self.round_number-1).coupled_pother6 p1.coupled_pother7 = p1.in_round(self.round_number-1).coupled_pother7 p1.coupled_pother8 = p1.in_round(self.round_number-1).coupled_pother8 else: if p2.random_id == 4: p1.coupled_pother4 = p1.in_round(self.round_number-1).coupled_pother4 + 4 p1.coupled_pother1 = p1.in_round(self.round_number-1).coupled_pother1 p1.coupled_pother2 = p1.in_round(self.round_number-1).coupled_pother2 p1.coupled_pother3 = p1.in_round(self.round_number-1).coupled_pother3 p1.coupled_pother5 = p1.in_round(self.round_number-1).coupled_pother5 p1.coupled_pother6 = p1.in_round(self.round_number-1).coupled_pother6 p1.coupled_pother7 = p1.in_round(self.round_number-1).coupled_pother7 p1.coupled_pother8 = p1.in_round(self.round_number-1).coupled_pother8 else: if p2.random_id == 5: p1.coupled_pother5 = p1.in_round(self.round_number-1).coupled_pother5 + 5 p1.coupled_pother1 = p1.in_round(self.round_number-1).coupled_pother1 p1.coupled_pother2 = p1.in_round(self.round_number-1).coupled_pother2 p1.coupled_pother3 = p1.in_round(self.round_number-1).coupled_pother3 p1.coupled_pother4 = p1.in_round(self.round_number-1).coupled_pother4 p1.coupled_pother6 = p1.in_round(self.round_number-1).coupled_pother6 p1.coupled_pother7 = p1.in_round(self.round_number-1).coupled_pother7 p1.coupled_pother8 = p1.in_round(self.round_number-1).coupled_pother8 else: if p2.random_id == 6: p1.coupled_pother6 = p1.in_round(self.round_number-1).coupled_pother6 + 6 p1.coupled_pother1 = p1.in_round(self.round_number-1).coupled_pother1 p1.coupled_pother2 = p1.in_round(self.round_number-1).coupled_pother2 p1.coupled_pother3 = p1.in_round(self.round_number-1).coupled_pother3 p1.coupled_pother4 = p1.in_round(self.round_number-1).coupled_pother4 p1.coupled_pother5 = p1.in_round(self.round_number-1).coupled_pother5 p1.coupled_pother7 = p1.in_round(self.round_number-1).coupled_pother7 p1.coupled_pother8 = p1.in_round(self.round_number-1).coupled_pother8 else: if p2.random_id == 7: p1.coupled_pother7 = p1.in_round(self.round_number-1).coupled_pother7 + 7 p1.coupled_pother1 = p1.in_round(self.round_number-1).coupled_pother1 p1.coupled_pother2 = p1.in_round(self.round_number-1).coupled_pother2 p1.coupled_pother3 = p1.in_round(self.round_number-1).coupled_pother3 p1.coupled_pother4 = p1.in_round(self.round_number-1).coupled_pother4 p1.coupled_pother5 = p1.in_round(self.round_number-1).coupled_pother5 p1.coupled_pother6 = p1.in_round(self.round_number-1).coupled_pother6 p1.coupled_pother8 = p1.in_round(self.round_number-1).coupled_pother8 else: p1.coupled_pother8 = p1.in_round(self.round_number-1).coupled_pother8 + 8 p1.coupled_pother1 = p1.in_round(self.round_number-1).coupled_pother1 p1.coupled_pother2 = p1.in_round(self.round_number-1).coupled_pother2 p1.coupled_pother3 = p1.in_round(self.round_number-1).coupled_pother3 p1.coupled_pother4 = p1.in_round(self.round_number-1).coupled_pother4 p1.coupled_pother5 = p1.in_round(self.round_number-1).coupled_pother5 p1.coupled_pother6 = p1.in_round(self.round_number-1).coupled_pother6 p1.coupled_pother7 = p1.in_round(self.round_number-1).coupled_pother7 if self.round_number == 1: #in first round there is no info yet if p1.random_id == 1: p2.coupled_pother1 = p2.coupled_pother1 + 1 else: if p1.random_id == 2: p2.coupled_pother2 = p2.coupled_pother2 + 2 else: if p1.random_id == 3: p2.coupled_pother3 = p2.coupled_pother3 + 3 else: if p1.random_id == 4: p2.coupled_pother4 = p2.coupled_pother4 + 4 else: if p1.random_id == 5: p2.coupled_pother5 = p2.coupled_pother5 + 5 else: if p1.random_id == 6: p2.coupled_pother6 = p2.coupled_pother6 + 6 else: if p1.random_id == 7: p2.coupled_pother7 = p2.coupled_pother7 + 7 else: p2.coupled_pother8 = p2.coupled_pother8 + 8 if self.round_number > 1: if p1.random_id == 1: p2.coupled_pother1 = p2.in_round(self.round_number-1).coupled_pother1 + 1 p2.coupled_pother2 = p2.in_round(self.round_number-1).coupled_pother2 p2.coupled_pother3 = p2.in_round(self.round_number-1).coupled_pother3 p2.coupled_pother4 = p2.in_round(self.round_number-1).coupled_pother4 p2.coupled_pother5 = p2.in_round(self.round_number-1).coupled_pother5 p2.coupled_pother6 = p2.in_round(self.round_number-1).coupled_pother6 p2.coupled_pother7 = p2.in_round(self.round_number-1).coupled_pother7 p2.coupled_pother8 = p2.in_round(self.round_number-1).coupled_pother8 else: if p1.random_id == 2: p2.coupled_pother2 = p2.in_round(self.round_number-1).coupled_pother2 + 2 p2.coupled_pother1 = p2.in_round(self.round_number-1).coupled_pother1 p2.coupled_pother3 = p2.in_round(self.round_number-1).coupled_pother3 p2.coupled_pother4 = p2.in_round(self.round_number-1).coupled_pother4 p2.coupled_pother5 = p2.in_round(self.round_number-1).coupled_pother5 p2.coupled_pother6 = p2.in_round(self.round_number-1).coupled_pother6 p2.coupled_pother7 = p2.in_round(self.round_number-1).coupled_pother7 p2.coupled_pother8 = p2.in_round(self.round_number-1).coupled_pother8 else: if p1.random_id == 3: p2.coupled_pother3 = p2.in_round(self.round_number-1).coupled_pother3 + 3 p2.coupled_pother1 = p2.in_round(self.round_number-1).coupled_pother1 p2.coupled_pother2 = p2.in_round(self.round_number-1).coupled_pother2 p2.coupled_pother4 = p2.in_round(self.round_number-1).coupled_pother4 p2.coupled_pother5 = p2.in_round(self.round_number-1).coupled_pother5 p2.coupled_pother6 = p2.in_round(self.round_number-1).coupled_pother6 p2.coupled_pother7 = p2.in_round(self.round_number-1).coupled_pother7 p2.coupled_pother8 = p2.in_round(self.round_number-1).coupled_pother8 else: if p1.random_id == 4: p2.coupled_pother4 = p2.in_round(self.round_number-1).coupled_pother4 + 4 p2.coupled_pother1 = p2.in_round(self.round_number-1).coupled_pother1 p2.coupled_pother2 = p2.in_round(self.round_number-1).coupled_pother2 p2.coupled_pother3 = p2.in_round(self.round_number-1).coupled_pother3 p2.coupled_pother5 = p2.in_round(self.round_number-1).coupled_pother5 p2.coupled_pother6 = p2.in_round(self.round_number-1).coupled_pother6 p2.coupled_pother7 = p2.in_round(self.round_number-1).coupled_pother7 p2.coupled_pother8 = p2.in_round(self.round_number-1).coupled_pother8 else: if p1.random_id == 5: p2.coupled_pother5 = p2.in_round(self.round_number-1).coupled_pother5 + 5 p2.coupled_pother1 = p2.in_round(self.round_number-1).coupled_pother1 p2.coupled_pother2 = p2.in_round(self.round_number-1).coupled_pother2 p2.coupled_pother3 = p2.in_round(self.round_number-1).coupled_pother3 p2.coupled_pother4 = p2.in_round(self.round_number-1).coupled_pother4 p2.coupled_pother6 = p2.in_round(self.round_number-1).coupled_pother6 p2.coupled_pother7 = p2.in_round(self.round_number-1).coupled_pother7 p2.coupled_pother8 = p2.in_round(self.round_number-1).coupled_pother8 else: if p1.random_id == 6: p2.coupled_pother6 = p2.in_round(self.round_number-1).coupled_pother6 + 6 p2.coupled_pother1 = p2.in_round(self.round_number-1).coupled_pother1 p2.coupled_pother2 = p2.in_round(self.round_number-1).coupled_pother2 p2.coupled_pother3 = p2.in_round(self.round_number-1).coupled_pother3 p2.coupled_pother4 = p2.in_round(self.round_number-1).coupled_pother4 p2.coupled_pother5 = p2.in_round(self.round_number-1).coupled_pother5 p2.coupled_pother7 = p2.in_round(self.round_number-1).coupled_pother7 p2.coupled_pother8 = p2.in_round(self.round_number-1).coupled_pother8 else: if p1.random_id == 7: p2.coupled_pother7 = p2.in_round(self.round_number-1).coupled_pother7 + 7 p2.coupled_pother1 = p2.in_round(self.round_number-1).coupled_pother1 p2.coupled_pother2 = p2.in_round(self.round_number-1).coupled_pother2 p2.coupled_pother3 = p2.in_round(self.round_number-1).coupled_pother3 p2.coupled_pother4 = p2.in_round(self.round_number-1).coupled_pother4 p2.coupled_pother5 = p2.in_round(self.round_number-1).coupled_pother5 p2.coupled_pother6 = p2.in_round(self.round_number-1).coupled_pother6 p2.coupled_pother8 = p2.in_round(self.round_number-1).coupled_pother8 else: p2.coupled_pother8 = p2.in_round(self.round_number-1).coupled_pother8 + 8 p2.coupled_pother1 = p2.in_round(self.round_number-1).coupled_pother1 p2.coupled_pother2 = p2.in_round(self.round_number-1).coupled_pother2 p2.coupled_pother3 = p2.in_round(self.round_number-1).coupled_pother3 p2.coupled_pother4 = p2.in_round(self.round_number-1).coupled_pother4 p2.coupled_pother5 = p2.in_round(self.round_number-1).coupled_pother5 p2.coupled_pother6 = p2.in_round(self.round_number-1).coupled_pother6 p2.coupled_pother7 = p2.in_round(self.round_number-1).coupled_pother7 for p in self.get_players(): p.participant.vars['coupled_pother1'] = p.coupled_pother1 p.participant.vars['coupled_pother2'] = p.coupled_pother2 p.participant.vars['coupled_pother3'] = p.coupled_pother3 p.participant.vars['coupled_pother4'] = p.coupled_pother4 p.participant.vars['coupled_pother5'] = p.coupled_pother5 p.participant.vars['coupled_pother6'] = p.coupled_pother6 p.participant.vars['coupled_pother7'] = p.coupled_pother7 p.participant.vars['coupled_pother8'] = p.coupled_pother8 for p in self.get_players(): p.participant.vars['con_other1'] = p.con_other1 p.participant.vars['con_other2'] = p.con_other2 p.participant.vars['con_other3'] = p.con_other3 p.participant.vars['con_other4'] = p.con_other4 p.participant.vars['beliefs_HH'] = p.beliefs_HH p.participant.vars['beliefs_HL'] = p.beliefs_HL p.participant.vars['beliefs_LH'] = p.beliefs_LH p.participant.vars['beliefs_LL'] = p.beliefs_LL print("Paired Previously") print("p1 other1:") print(p1.coupled_pother1) print("p1 other2:") print(p1.coupled_pother2) print("p1 other3:") print(p1.coupled_pother3) print("p1 other4:") print(p1.coupled_pother4) print("p1 other5:") print(p1.coupled_pother5) print("p1 other6:") print(p1.coupled_pother6) print("p1 other7:") print(p1.coupled_pother7) print("p1 other8:") print(p1.coupled_pother8) print("---") print("p2 other1:") print(p2.coupled_pother1) print("p2 other2:") print(p2.coupled_pother2) print("p2 other3:") print(p2.coupled_pother3) print("p2 other4:") print(p2.coupled_pother4) print("p2 other5:") print(p2.coupled_pother5) print("p2 other6:") print(p2.coupled_pother6) print("p2 other7:") print(p2.coupled_pother7) print("p2 other8:") print(p2.coupled_pother8) #count previous partner for player 1 if self.round_number == 1: #in first round there is no info yet if p2.type == "HH": p1.coupled_HH = p1.coupled_HH + 1 p1.coupled_HL = p1.coupled_HL p1.coupled_LH = p1.coupled_LH p1.coupled_LL = p1.coupled_LL else: if p2.type == "HL": p1.coupled_HL = p1.coupled_HL + 1 p1.coupled_HH = p1.coupled_HH p1.coupled_LH = p1.coupled_LH p1.coupled_LL = p1.coupled_LL else: if p2.type == "LH": p1.coupled_LH = p1.coupled_LH + 1 p1.coupled_HH = p1.coupled_HH p1.coupled_HL = p1.coupled_HL p1.coupled_LL = p1.coupled_LL else: p1.coupled_LL = p1.coupled_LL + 1 p1.coupled_HH = p1.coupled_HH p1.coupled_HL = p1.coupled_HL p1.coupled_LH = p1.coupled_LH if self.round_number > 1: if p2.type == "HH": p1.coupled_HH = p1.in_round(self.round_number-1).coupled_HH + 1 p1.coupled_HL = p1.in_round(self.round_number-1).coupled_HL p1.coupled_LH = p1.in_round(self.round_number-1).coupled_LH p1.coupled_LL = p1.in_round(self.round_number-1).coupled_LL else: if p2.type == "HL": p1.coupled_HL = p1.in_round(self.round_number-1).coupled_HL + 1 p1.coupled_HH = p1.in_round(self.round_number-1).coupled_HH p1.coupled_LH = p1.in_round(self.round_number-1).coupled_LH p1.coupled_LL = p1.in_round(self.round_number-1).coupled_LL else: if p2.type == "LH": p1.coupled_LH = p1.in_round(self.round_number-1).coupled_LH + 1 p1.coupled_HH = p1.in_round(self.round_number-1).coupled_HH p1.coupled_HL = p1.in_round(self.round_number-1).coupled_HL p1.coupled_LL = p1.in_round(self.round_number-1).coupled_LL else: p1.coupled_LL = p1.in_round(self.round_number-1).coupled_LL + 1 p1.coupled_HH = p1.in_round(self.round_number-1).coupled_HH p1.coupled_HL = p1.in_round(self.round_number-1).coupled_HL p1.coupled_LH = p1.in_round(self.round_number-1).coupled_LH if self.round_number == 1: #in first round there is no info yet if p1.type == "HH": p2.coupled_HH = p2.coupled_HH + 1 p2.coupled_HL = p2.coupled_HL p2.coupled_LH = p2.coupled_LH p2.coupled_LL = p2.coupled_LL else: if p1.type == "HL": p2.coupled_HL = p2.coupled_HL + 1 p2.coupled_HH = p2.coupled_HH p2.coupled_LH = p2.coupled_LH p2.coupled_LL = p2.coupled_LL else: if p1.type == "LH": p2.coupled_LH = p2.coupled_LH + 1 p2.coupled_HH = p2.coupled_HH p2.coupled_HL = p2.coupled_HL p2.coupled_LL = p2.coupled_LL else: p2.coupled_LL = p2.coupled_LL + 1 p2.coupled_HH = p2.coupled_HH p2.coupled_HL = p2.coupled_HL p2.coupled_LH = p2.coupled_LH if self.round_number > 1: if p1.type == "HH": p2.coupled_HH = p2.in_round(self.round_number-1).coupled_HH + 1 p2.coupled_HL = p2.in_round(self.round_number-1).coupled_HL p2.coupled_LH = p2.in_round(self.round_number-1).coupled_LH p2.coupled_LL = p2.in_round(self.round_number-1).coupled_LL else: if p1.type == "HL": p2.coupled_HL = p2.in_round(self.round_number-1).coupled_HL + 1 p2.coupled_HH = p2.in_round(self.round_number-1).coupled_HH p2.coupled_LH = p2.in_round(self.round_number-1).coupled_LH p2.coupled_LL = p2.in_round(self.round_number-1).coupled_LL else: if p1.type == "LH": p2.coupled_LH = p2.in_round(self.round_number-1).coupled_LH + 1 p2.coupled_HH = p2.in_round(self.round_number-1).coupled_HH p2.coupled_HL = p2.in_round(self.round_number-1).coupled_HL p2.coupled_LL = p2.in_round(self.round_number-1).coupled_LL else: p2.coupled_LL = p2.in_round(self.round_number-1).coupled_LL + 1 p2.coupled_HH = p2.in_round(self.round_number-1).coupled_HH p2.coupled_HL = p2.in_round(self.round_number-1).coupled_HL p2.coupled_LH = p2.in_round(self.round_number-1).coupled_LH for p in self.get_players(): p.participant.vars['coupled_HH'] = p.coupled_HH p.participant.vars['coupled_HL'] = p.coupled_HL p.participant.vars['coupled_LH'] = p.coupled_LH p.participant.vars['coupled_LL'] = p.coupled_LL print("coupled_HH =") print(p1.coupled_HH) print("coupled_HL =") print(p1.coupled_HL) print("coupled_LH =") print(p1.coupled_LH) print("coupled_LL =") print(p1.coupled_LL) print("coupled_HH =") print(p2.coupled_HH) print("coupled_HL =") print(p2.coupled_HL) print("coupled_LH =") print(p2.coupled_LH) print("coupled_LL =") print(p2.coupled_LL) def get_multiplier_previous_round(self): # for p in self.get_players(): # if self.round_number > 1: # p.no_response = p.in_round(self.round_number-1).no_response # p.participant.vars['no_response'] = p.no_response #get global variables created in first app for p in self.get_players(): if p.participant.vars['multiplier'] == 1.7: p.multiplier = 1.7 else: p.multiplier = 1.3 for p in self.get_players(): if p.participant.vars['endowment'] == 75: p.endowment = 75 else: p.endowment = 25 for p in self.get_players(): if p.participant.vars['type'] == "HH": p.type = "HH" else: if p.participant.vars['type'] == "HL": p.type = "HL" else: if p.participant.vars['type'] == "LH": p.type = "LH" else: p.type = "LL" for p in self.get_players(): if p.participant.vars['random_id'] == 1: p.random_id = 1 else: if p.participant.vars['random_id'] == 2: p.random_id = 2 else: if p.participant.vars['random_id'] == 3: p.random_id = 3 else: if p.participant.vars['random_id'] == 4: p.random_id = 4 else: if p.participant.vars['random_id'] == 5: p.random_id = 5 else: if p.participant.vars['random_id'] == 6: p.random_id = 6 else: if p.participant.vars['random_id'] == 7: p.random_id = 7 else: if p.participant.vars['random_id'] == 8: p.random_id = 8 else: p.random_id = 9 for p in self.get_players(): print("random_id") print(p.random_id) for p in self.get_players(): if p.participant.vars['type'] == "HH": p.typedisplay = "Type 1" else: if p.participant.vars['type'] == "HL": p.typedisplay = "Type 2" else: if p.participant.vars['type'] == "LH": p.typedisplay = "Type 3" else: p.typedisplay = "Type 4" def my_method(self): #make the multiplier selected a global variable across apps for p in self.get_players(): p.participant.vars['endowment'] = p.endowment p.participant.vars['multiplier'] = p.multiplier p.participant.vars['type'] = p.type p.participant.vars['earnings'] = p.earnings p.participant.vars['accumulated_wealth'] = p.accumulated_wealth p.participant.vars['random_id'] = p.random_id p.participant.vars['con_other1'] = p.con_other1 p.participant.vars['con_other2'] = p.con_other2 p.participant.vars['con_other3'] = p.con_other3 p.participant.vars['con_other4'] = p.con_other4 p.participant.vars['beliefs_HH'] = p.beliefs_HH p.participant.vars['beliefs_HL'] = p.beliefs_HL p.participant.vars['beliefs_LH'] = p.beliefs_LH p.participant.vars['beliefs_LL'] = p.beliefs_LL p.participant.vars['coupled_pother1'] = p.coupled_pother1 p.participant.vars['coupled_pother2'] = p.coupled_pother2 p.participant.vars['coupled_pother3'] = p.coupled_pother3 p.participant.vars['coupled_pother4'] = p.coupled_pother4 p.participant.vars['coupled_pother5'] = p.coupled_pother5 p.participant.vars['coupled_pother6'] = p.coupled_pother6 p.participant.vars['coupled_pother7'] = p.coupled_pother7 p.participant.vars['coupled_pother8'] = p.coupled_pother8 p.participant.vars['coupled_HH'] = p.coupled_HH p.participant.vars['coupled_HL'] = p.coupled_HL p.participant.vars['coupled_LH'] = p.coupled_LH p.participant.vars['coupled_LL'] = p.coupled_LL class Player(BasePlayer): multiplier = models.FloatField(choices=[[1.7,"1.7"],[1.3,"1.3"]]) accumulated_wealth = models.CurrencyField() contribution = models.CurrencyField( min=0, max=Constants.endowment, doc="""The amount contributed by the player""" ) def contribution_max(self): return self.endowment endowment = models.CurrencyField(choices=[[75,"75"],[25,"25"]]) addedtoPGG = models.CurrencyField() coupled_HH = models.IntegerField(initial=0) coupled_HL = models.IntegerField(initial=0) coupled_LH = models.IntegerField(initial=0) coupled_LL = models.IntegerField(initial=0) coupled_pother1 = models.IntegerField(initial=0) coupled_pother2 = models.IntegerField(initial=0) coupled_pother3 = models.IntegerField(initial=0) coupled_pother4 = models.IntegerField(initial=0) coupled_pother5 = models.IntegerField(initial=0) coupled_pother6 = models.IntegerField(initial=0) coupled_pother7 = models.IntegerField(initial=0) coupled_pother8 = models.IntegerField(initial=0) beliefs_HH = models.CurrencyField(min=0, max=75) beliefs_HL = models.CurrencyField(min=0, max=75) beliefs_LH = models.CurrencyField(min=0, max=25) beliefs_LL = models.CurrencyField(min=0, max=25) con_other1 = models.CurrencyField(initial=0) con_other2 = models.CurrencyField(initial=0) con_other3 = models.CurrencyField(initial=0) con_other4 = models.CurrencyField(initial=0) type = models.StringField() typedisplay = models.StringField() type_partner = models.StringField() earnings = models.CurrencyField() kept = models.CurrencyField() random_id = models.IntegerField(initial=0) Attention_Check_2 = models.IntegerField() condition = models.StringField() random_id = models.IntegerField() def my_method(self): #make the income and multiplier selected a global variable across apps self.participant.vars['multiplier'] = self.multiplier self.participant.vars['endowment'] = self.endowment self.participant.vars['type'] = self.type self.participant.vars['accumulated_wealth'] = self.accumulated_wealth self.participant.vars['random_id'] = self.random_id self.participant.vars['con_other1'] = self.con_other1 self.participant.vars['con_other2'] = self.con_other2 self.participant.vars['con_other3'] = self.con_other3 self.participant.vars['con_other4'] = self.con_other4 self.participant.vars['beliefs_HH'] = self.beliefs_HH self.participant.vars['beliefs_HL'] = self.beliefs_HL self.participant.vars['beliefs_LH'] = self.beliefs_LH self.participant.vars['beliefs_LL'] = self.beliefs_LL self.participant.vars['coupled_pother1'] = self.coupled_pother1 self.participant.vars['coupled_pother2'] = self.coupled_pother2 self.participant.vars['coupled_pother3'] = self.coupled_pother3 self.participant.vars['coupled_pother4'] = self.coupled_pother4 self.participant.vars['coupled_pother5'] = self.coupled_pother5 self.participant.vars['coupled_pother6'] = self.coupled_pother6 self.participant.vars['coupled_pother7'] = self.coupled_pother7 self.participant.vars['coupled_pother8'] = self.coupled_pother8 self.participant.vars['coupled_HH'] = self.coupled_HH self.participant.vars['coupled_HL'] = self.coupled_HL self.participant.vars['coupled_LH'] = self.coupled_LH self.participant.vars['coupled_LL'] = self.coupled_LL print(self.participant.vars['multiplier']) print(self.participant.vars['endowment']) print(self.participant.vars['type']) print(self.participant.vars['accumulated_wealth']) print(self.participant.vars['random_id']) def other_player(self): #make it possible to show data other player in pages return self.get_others_in_group()[0] def p_other(self): #not sure if this is important self.get_others_in_group()