import random import csv from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) author = 'Your name here' doc = """ Your app description """ class Constants(BaseConstants): name_in_url = 'game-n_au' players_per_group = None num_rounds = 1 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): guess1 = models.IntegerField(min=0, max= 100) guess2 = models.IntegerField(min=0, max= 100) guess3 = models.IntegerField(min=0, max= 100) public = models.IntegerField(min=0, max= 100) private = models.IntegerField(min=0, max= 100) offer = models.PositiveIntegerField(min=0, max=100) info_value = models.PositiveIntegerField(min=0, max=100) info_shown = models.IntegerField(min=0, max=100) p_value = models.PositiveIntegerField() r_aux1 = models.FloatField() # To decide public of private decision first (third page) r_aux2 = models.FloatField() # To decide which other player information is shown. r_aux4 = models.FloatField() # To decide which payment to make for controls payment = models.PositiveIntegerField(min=0, max=4) quiz_1 = models.CharField(initial=None, choices=['$0.00', '$2.00'], #choices=['$0','$1', '$2'], widget=widgets.RadioSelectHorizontal) quiz_2 = models.CharField(initial=None, choices=['$0.00', '$2.00'], #choices=['$0','$1', '$2'], widget=widgets.RadioSelectHorizontal) quiz_3 = models.CharField(initial=None, choices=['$0.00', '$2.00'], #choices=['$0','$1', '$2'], widget=widgets.RadioSelectHorizontal) plyrs_num = models.PositiveIntegerField(widget=widgets.RadioSelectHorizontal, choices=[[1,"one"],[2,"two"],[3,"three"]]) # survey plyrs_select = models.PositiveIntegerField(widget=widgets.RadioSelect, choices=[[0,"We all think the most likely word in the recording is Yanney."], [1,"We all think the most likely word in the recording is Laurel."], [2,"Randomly without a particular criterion."]]) # survey std_part = models.PositiveIntegerField(widget=widgets.RadioSelect, choices=[[1,"First"],[2,"Second"],[3,"Third"]]) # survey transfer = models.PositiveIntegerField(min=0, max=73) # transfer task xyz = models.BooleanField() # transfer task random_digit = models.IntegerField() # survey role_player = models.CharField() # survey t_payment = models.PositiveIntegerField() # survey i_ddigit = models.IntegerField() # survey group_id_1 = models.PositiveIntegerField(widget=widgets.RadioSelectHorizontal, choices=[[1,""],[2,""],[3,""],[4,""],[5,""]]) # survey group_id_2 = models.PositiveIntegerField(widget=widgets.RadioSelectHorizontal, choices=[[1,""],[2,""],[3,""],[4,""],[5,""]]) # survey group_id_3 = models.PositiveIntegerField(widget=widgets.RadioSelectHorizontal, choices=[[1,""],[2,""],[3,""],[4,""],[5,""]]) # survey group_id_4 = models.PositiveIntegerField(widget=widgets.RadioSelectHorizontal, choices=[[1,""],[2,""],[3,""],[4,""],[5,""]]) i_dlottery = models.PositiveIntegerField() # survey i_dprice = models.PositiveIntegerField() # survey s_daverage = models.PositiveIntegerField() # survey s_dfirst_public = models.PositiveIntegerField() # survey s_dfirst_private = models.PositiveIntegerField() # survey s_dsecond_private = models.PositiveIntegerField() # survey s_dpayment = models.PositiveIntegerField() # survey age = models.PositiveIntegerField() # survey gender = models.CharField(initial=None, choices=['female','male','diverse'], widget=widgets.RadioSelectHorizontal) # survey english = models.CharField(initial=None, choices=['native','very good','good', 'average', 'poor', 'none'], widget=widgets.RadioSelectHorizontal) # survey check2_q = models.CharField(initial=None, max_length=50) z_value = models.PositiveIntegerField() B = models.PositiveIntegerField() r_aux_g1 = models.PositiveIntegerField() # To decide if the group is High == 1, Low == 2, None == 3 //High (>= 0.5) or Low (< 0.5). r_aux_g2 = models.FloatField() # To decide if it is Treatment (>= 0.5) or Control (< 0.5). r_aux_g3 = models.PositiveIntegerField() # To decide if it is Spillover (==1) or not (== 2). r_aux_g4 = models.FloatField() # To decide wich task to pay for Treatment. r_aux_g5 = models.PositiveIntegerField() # To decide if it is not aligned (==1) or aligned (== 2). rest = models.PositiveIntegerField(min=0, max=100) # transfer task p_2rol = models.CharField() p_3rol = models.CharField() g_transfer = models.PositiveIntegerField() # survey perception_other = models.PositiveIntegerField(widget=widgets.RadioSelectHorizontal, choices=[[1,"best guess"],[2,"influence opinion"]]) # survey personal_action = models.PositiveIntegerField(widget=widgets.RadioSelectHorizontal, choices=[[1,"best guess"],[2,"influence opinion"]]) # survey accuracy_guess = models.PositiveIntegerField(widget=widgets.RadioSelectHorizontal, choices=[[1,"More accurate"],[2,"As accurate"],[3,"Less accurate"]]) # survey offer_size = models.PositiveIntegerField(widget=widgets.RadioSelectHorizontal, choices=[[1,"More"],[2,"Same"],[3,"Less"]]) # survey guess_others = models.PositiveIntegerField(widget=widgets.RadioSelectHorizontal, choices=[[1,"Yes"],[2,"No"]]) # survey guess_self = models.PositiveIntegerField(widget=widgets.RadioSelectHorizontal, choices=[[1,"Yes"],[2,"No"]]) # survey topic_study = models.CharField(initial=None, blank=True, max_length=300) # survey free_message = models.CharField(initial=None, blank=True, max_length=500) # survey a_2trans = models.PositiveIntegerField() a_3trans = models.PositiveIntegerField() a_2val = models.PositiveIntegerField() a_3val = models.PositiveIntegerField() a_2pgue = models.PositiveIntegerField() a_3pgue = models.PositiveIntegerField() prt = models.PositiveIntegerField() times_clicked_1 = models.IntegerField(blank=True ) times_clicked_2 = models.IntegerField(blank=True ) times_clicked_3 = models.IntegerField(blank=True ) qs_checks = models.PositiveIntegerField() chosen_guess = models.PositiveIntegerField(min=0, max=100) id2_in_group = models.PositiveIntegerField(min=1, max=3) def andere_mit(self): A = [] CS1 = [[0,44,48],[50,26,42],[10,47,48],[0,61,50], [25,26,60],[0,55,53],[50,43,49],[10,78,55],[50,7,10],[50,17,0], [50,0,38],[70,24,8],[30,16,2],[35,71,64],[30,15,55],[80,59,34], [25,74,60],[50,52,48],[60,46,65],[50,44,44],[20,45,35],[2,29,1], [50,29,65],[50,71,38],[50,12,34],[0,65,54],[30,25,60],[53,41,41], [100,20,43],[50,57,60],[0,24,40],[50,33,50],[60,33,23],[0,26,43], [25,62,72],[5,30,54],[0,64,58],[50,93,65],[50,26,42],[67,95,60], [50,93,76],[100,37,60],[50,28,33],[77,76,60],[0,71,25],[0,14,52], [40,51,51],[50,5,5],[100,94,50],[100,12,3],[0,76,70],[50,94,65], [0,25,40],[50,44,53],[50,6,32],[50,55,58],[67,37,43],[50,15,65], [50,67,65],[50,71,45],[0,6,35],[50,30,37],[50,41,40],[55,29,30], [70,60,90],[0,2,12],[50,93,45],[70,100,80],[50,20,39],[50,2,37], [40,51,48],[60,56,56],[50,30,35],[50,44,38],[33,46,30],[50,63,51], [50,1,37],[50,51,55],[23,16,2],[20,69,4],[0,86,35],[50,31,47],[50,88,60], [0,39,54],[33,80,65],[40,47,20],[67,37,34]] CS0 = [[0,84,61],[40,45,33],[20,29,41],[0,21,40], [0,11,35],[50,63,82],[50,52,48],[50,47,40], [70,24,2],[55,82,57],[0,70,60], [0,7,54],[60,19,70],[50,80,30],[50,29,30],[25,51,90], [50,47,52],[90,78,60],[0,28,46],[23,15,2],[0,75,68], [50,51,55],[90,90,85],[33,30,32],[50,38,50],[100,69,55], [50,5,25],[50,3,45],[60,96,2],[15,68,65],[67,14,55],[50,62,57], [50,23,1],[70,78,60],[50,79,45],[60,65,70],[80,74,18],[0,87,60], [40,36,50],[50,63,45],[0,35,46],[5,27,54],[50,84,57],[50,89,57], [50,3,60],[70,58,50],[50,59,54],[60,5,1],[25,65,30]] CP1 = [[0,44,48],[0,84,61],[50,26,42],[20,5,10], [0,27,39],[50,5,50],[50,48,56],[10,11,37], [50,47,47],[50,76,40],[25,56,55],[0,77,56], [50,56,50],[50,7,31],[50,69,60],[30,46,55], [50,25,40],[70,41,60]] CP0 = [[10,47,48],[0,61,50],[40,45,33], [50,71,50],[50,7,30],[0,38,55],[25,92,65]] if self.session.config['treatment'] == 'sound': if self.participant.vars['category'] == 1: # with open('andere_reqS1.txt', 'r') as file: # reader = csv.reader(file) # for row in reader: # A.append(row) A = CS1 else: # with open('andere_reqS0.txt', 'r') as file: # reader = csv.reader(file) # for row in reader: # A.append(row) A = CS0 else: if self.participant.vars['category'] == 1: # with open('andere_reqP1.txt', 'r') as file: # reader = csv.reader(file) # for row in reader: # A.append(row) A = CP1 else: # with open('andere_reqP0.txt', 'r') as file: # reader = csv.reader(file) # for row in reader: # A.append(row) A = CP0 l = len(A) - 1 a = random.randint(0,l) b = random.randint(0,l) c = random.randint(0,l) self.a_2trans = round(A[b][0]*0.73) self.a_3trans = round(A[c][0]*0.73) self.a_2val = A[b][1] self.a_3val = A[c][1] self.a_2pgue = A[b][2] self.a_3pgue = A[c][2] def shuffled_role(self): # survey rol = ['A', 'B', 'C'] random.shuffle(rol) print(rol) p2_transfer = self.a_2trans #random.randint(0,100) p3_transfer = self.a_2trans #random.randint(0,100) print("Survey App:") self.role_player = rol[0] self.p_2rol = rol[1] self.p_3rol = rol[2] if self.role_player == 'A': self.g_transfer = self.participant.vars['t_transfer'] elif self.p_2rol == 'A': self.g_transfer = p2_transfer else: self.g_transfer = p3_transfer if self.role_player == 'A': self.t_payment = 73 - self.g_transfer elif self.role_player == 'B': self.t_payment = round((self.g_transfer)/2,0) else: self.t_payment = round((self.g_transfer)/2,0) def choose_guess(self): chosen = random.randint(1,3) if chosen == 1: self.chosen_guess = self.guess3 elif chosen == 2: self.chosen_guess = self.a_2pgue elif chosen == 3: self.chosen_guess = self.a_3pgue def assign_treatment(self): self.r_aux_g1 = 1 #random.randint(1,3), 1 High, 2 low, 3 is control self.r_aux_g2 = 0.7 #random.random() # Defines whether group or control self.r_aux_g3 = random.randint(1,2) # Defines whether spillover (1) or not (2) self.r_aux_g4 = random.randint(1,2) # Defines the payment self.r_aux_g5 = random.randint(1,2) # Defines whether non aligned (1) or aligned (2) self.B = 3 self.p_value = random.randint(0, 100) self.r_aux1 = random.random() self.r_aux2 = random.random() self.id2_in_group = random.randint(1,3) print("Value Guess App:") #lista = [] #print(lista) #for p in players: # lista.append(p.participant.id_in_session) # print(lista) #for p in players: # p.participant.vars['group'] = lista #g_name = '-'.join([str(n) for n in lista]) #print(g_name) #for p in players: # p.participant.vars['group_name'] = lista def get_z(self): self.z_value = sum(i.p_value for i in self.get_players()) / 3 def set_payoffsG(self): p2_value = self.a_2val #random.randint(0, 100) p3_value = self.a_3val #random.randint(0, 100) #players = self.get_players() the_average = (self.p_value + p2_value + p3_value) / 3 self.z_value = round(the_average,0) def set_info_to_see(self): p2_public = self.a_2pgue #random.randint(0,100) p3_public = self.a_3pgue #random.randint(0,100) self.info_shown = p2_public * (self.r_aux2 <= 0.5) + p3_public * (self.r_aux2 > 0.5) # to separate def set_payments(self): if self.r_aux_g4 == 1: self.payment = 1 else: self.payment = 4 if self.r_aux_g1 == 1: self.participant.vars['incentive'] = 1 elif self.r_aux_g1 == 2: self.participant.vars['incentive'] = 0 else: self.participant.vars['incentive'] = 3 if self.r_aux_g2 >= 0.5: self.participant.vars['treatment'] = 1 else: self.participant.vars['treatment'] = 0 self.participant.vars['s_average'] = self.z_value self.participant.vars['s_first_public'] = self.public self.participant.vars['s_first_private'] = self.private self.participant.vars['s_second_private'] = self.guess3 self.participant.vars['s_payment'] = self.payment if self.offer >= self.info_value: self.participant.vars['s_price_info'] = self.info_value else: self.participant.vars['s_price_info'] = 0 def set_payoffs(self): self.participant.vars['t_transfer'] = self.transfer def final_payoff(self): self.i_dlottery = self.participant.vars['i_lottery'] self.i_dprice = self.participant.vars['i_price'] i_lottery = self.participant.vars['i_lottery'] i_price = self.participant.vars['i_price'] i_digit = self.i_ddigit #random.randint(1,10) #self.random_digit #self.USD_sixth_digit #random.randint(0, 10) #self.i_ddigit = i_digit #hi_outcome = self.participant.vars['high_out'] #lo_outcome = self.participant.vars['low_out'] #scl_payoff = self.participant.vars['scl_payoff'] #timeout_B = self.participant.vars['timeout_B'] #timeout_V = self.participant.vars['timeout_V'] role = self.role_player t_payment = self.t_payment self.s_daverage = self.participant.vars['s_average'] self.s_dfirst_public = self.participant.vars['s_first_public'] self.s_dfirst_private = self.participant.vars['s_first_private'] self.s_dsecond_private = self.participant.vars['s_second_private'] s_average = self.participant.vars['s_average'] s_first_public = self.participant.vars['s_first_public'] s_first_private = self.participant.vars['s_first_private'] s_second_private = self.participant.vars['s_second_private'] s_chosen = self.chosen_guess self.s_dpayment = self.participant.vars['s_payment'] s_payment = self.participant.vars['s_payment'] incentive = self.participant.vars['incentive'] treatment = self.participant.vars['treatment'] s_price_info = self.participant.vars['s_price_info'] low = s_average - 3 high = s_average + 3 discount = i_price + s_price_info if self.qs_checks == 6: bonus = 0.5 elif self.qs_checks == 4 or self.qs_checks == 5: bonus = 0.2 else: bonus = 0 if i_lottery == 1: if i_digit <= 4: lotto = 2 else: lotto = 0 if i_lottery == 0: lotto = 0 if self.s_dpayment == 1: if self.r_aux_g5 == 1 and self.id2_in_group == 1 and self.s_daverage >= 45: self.payoff = lotto + t_payment/100 + 2 - discount/100 + bonus elif self.r_aux_g5 == 1 and self.id2_in_group == 1 and self.s_daverage < 46: self.payoff = lotto + 2 + t_payment/100 + 2 - discount/100 + bonus elif self.r_aux_g5 == 1 and self.id2_in_group > 1 and self.s_daverage < 55: self.payoff = lotto + t_payment/100 + 2 - discount/100 + bonus elif self.r_aux_g5 == 1 and self.id2_in_group > 1 and self.s_daverage > 54: self.payoff = lotto + 2 + t_payment/100 + 2 - discount/100 + bonus elif self.r_aux_g5 != 1 and self.s_daverage < 55: self.payoff = lotto + t_payment/100 + 2 - discount/100 + bonus elif self.r_aux_g5 != 1 and self.s_daverage > 54: self.payoff = lotto + 2 + t_payment/100 + 2 - discount/100 + bonus elif self.s_dpayment == 4: if self.r_aux_g3 == 1: self.payoff = lotto + 2*(s_chosen >= low and s_chosen <= high) + t_payment/100 + 2 - discount/100 + bonus else: self.payoff = lotto + 2*(s_second_private >= low and s_second_private <= high) + t_payment/100 + 2 - discount/100 + bonus