from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, currency_range, ) import random import csv import xlrd # for reading XLS-files author = 'Dr. Jana Freundt & Leander Kopp' doc = """ Correlation Neglect pilot """ class Constants(BaseConstants): name_in_url = 'Correlation_Neglect' players_per_group = 3 PRINCIPAL_ROLE = '

The GREEN player

' AGENT1_ROLE = '

The LIGHT BLUE player

' AGENT2_ROLE = '

The DARK BLUE player

' language_code = 1 num_rounds = 2 currency="£" currency_real="£" XR=1 Specific_Project_Dark = 10 Specific_Project_Light = 50 alpha = 0.4 Payoff_Green_Right = 1.5 Payoff_Green_Wrong = 0 High_Payment = 4.5 Low_Payment = 0.5 showup_fee = 3 class Subsession(BaseSubsession): def creating_session(subsession): subsession.group_randomly(fixed_id_in_group=True) class Group(BaseGroup): ##Green Player Decision_Principal = models.IntegerField(min=-120, max=120) Green_Right=models.IntegerField() ##Light Blue Player ##Dark Blue player Effort_Light = models.IntegerField(min=0, max=100) Effort_Dark = models.IntegerField(min=0, max=100) Effort_Cost_Light = models.FloatField(max_digits=5, decimal_places=4) Effort_Cost_Dark = models.FloatField(max_digits=5, decimal_places=4) Random_Light = models.IntegerField() Random_Dark = models.IntegerField() Work_Output_Light = models.IntegerField() Work_Output_Dark = models.IntegerField() Work_Output_Difference = models.IntegerField() Work_Output_Higher = models.IntegerField() Payoff_Light_Round = models.FloatField() Payoff_Dark_Round = models.FloatField() Payoff_Green_Round = models.FloatField() optionchoice = models.IntegerField() Belief_Light_Principal = models.IntegerField(min=-120, max=120) Belief_Dark_Principal = models.IntegerField(min=-120, max=120) Belief_Light_Dark = models.IntegerField(min=0, max=100) Belief_Dark_Light = models.IntegerField(min=0, max=100) Decision_Principal_Explanation = models.LongStringField(blank=True) Effort_Light_Explanation = models.LongStringField(blank=True) Effort_Dark_Explanation = models.LongStringField(blank=True) Belief_Light_Principal_Confidence = models.IntegerField(min=0, max=100) Belief_Dark_Principal_Confidence = models.IntegerField(min=0, max=100) def set_Random_Light(self): # Generate a random number between 1 and 100 self.Random_Light = random.randint(-30, 30) def set_Random_Dark(self): # Generate a random number between 1 and 100 self.Random_Dark = random.randint(-30, 30) def WOL(self): result = (1 - Constants.alpha) * ( self.Effort_Light + self.Random_Light) + Constants.alpha * Constants.Specific_Project_Light self.Work_Output_Light = round(result) def WOD(self): result = (1 - Constants.alpha) * ( self.Effort_Dark + self.Random_Dark) + Constants.alpha * Constants.Specific_Project_Dark self.Work_Output_Dark = round(result) def OC(self): if self.Work_Output_Light - self.Decision_Principal > self.Work_Output_Dark: self.optionchoice = 0 elif self.Work_Output_Light - self.Decision_Principal < self.Work_Output_Dark: self.optionchoice = 1 else: self.optionchoice = random.choice([0, 1]) def GR(self): if self.Work_Output_Light - self.Decision_Principal == self.Work_Output_Dark: return 1.5 if self.Effort_Light > self.Effort_Dark and self.optionchoice == 0: return 1.5 if self.Effort_Light == self.Effort_Dark and self.optionchoice == 0: return 1.5 if self.Effort_Light < self.Effort_Dark and self.optionchoice == 1: return 1.5 if self.Effort_Light == self.Effort_Dark and self.optionchoice == 1: return 1.5 else: return 0 def ECL(self): self.Effort_Cost_Light = (self.Effort_Light*self.Effort_Light)/1500 def ECD(self): self.Effort_Cost_Dark = (self.Effort_Dark*self.Effort_Dark)/1500 def PLR(self): self.Payoff_Light_Round= (1-self.optionchoice)*Constants.High_Payment+self.optionchoice*Constants.Low_Payment -self.Effort_Cost_Light def PDR(self): self.Payoff_Dark_Round= (self.optionchoice)*Constants.High_Payment+(1-self.optionchoice)*Constants.Low_Payment -self.Effort_Cost_Dark def PGR(self): self.Payoff_Green_Round= self.GR() def WODiff(self): self.Work_Output_Difference= abs(self.Work_Output_Light-self.Work_Output_Dark) def WOH(self): if self.Work_Output_Light > self.Work_Output_Dark: self.Work_Output_Higher = 0 elif self.Work_Output_Light < self.Work_Output_Dark: self.Work_Output_Higher = 1 else: self.Work_Output_Higher = 2 class Player(BasePlayer): def role(self): if self.id_in_group == 1: return '

The GREEN player

' if self.id_in_group == 2: return '

The LIGHT BLUE player

' else: return '

The DARK BLUE player

' ########## DEFINE CONTROL QUESTION VARIABLES ### ControlQuestion3 = models.IntegerField() ControlQuestion4 = models.IntegerField() ControlQuestion6 = models.IntegerField() ControlQuestion7 = models.IntegerField() ControlQuestion8 = models.IntegerField() ControlQuestion1 = models.IntegerField() ControlQuestion2 = models.IntegerField() ControlQuestion5 = models.IntegerField() ControlQuestion5_output = models.FloatField() # counter for control questions tab_consent = models.FloatField() FeedBack = models.LongStringField(blank=True) Belief_Dark = models.FloatField() Belief_Light = models.FloatField() Payoff_Light_Round_Own = models.FloatField(initial=0) Payoff_Dark_Round_Own = models.FloatField(initial=0) Payoff_Green_Round_Own = models.FloatField(initial=0) Total_Payoffs_Green = models.FloatField() Total_Payoffs_Light = models.FloatField() Total_Payoffs_Dark = models.FloatField() Total_Payoffs_GreenSUF = models.FloatField() Total_Payoffs_LightSUF = models.FloatField() Total_Payoffs_DarkSUF = models.FloatField() Belief_Selected_Round = models.IntegerField(initial=0) Belief_Selected_Bonus = models.FloatField(initial=0) Belief_Selected_Guess = models.IntegerField(initial=0) Belief_Selected_True_Threshold = models.IntegerField(initial=0) Belief_Selected_Distance = models.IntegerField(initial=0) Belief_Selected_Confidence = models.IntegerField(initial=0) def PGRO(self): self.Payoff_Green_Round_Own= self.group.Payoff_Green_Round def PLRO(self): self.Payoff_Light_Round_Own= self.group.Payoff_Light_Round def PDRO(self): self.Payoff_Dark_Round_Own= self.group.Payoff_Dark_Round def calculate_total_payoff(self): self.Total_Payoffs_Green = 0 self.Total_Payoffs_Light = 0 self.Total_Payoffs_Dark = 0 for round_num in range(1, self.round_number + 1): round_data = self.in_round(round_num) self.Total_Payoffs_Green += round_data.Payoff_Green_Round_Own self.Total_Payoffs_Light += round_data.Payoff_Light_Round_Own self.Total_Payoffs_Dark += round_data.Payoff_Dark_Round_Own def calculate_total_payoff2(self): self.Total_Payoffs_GreenSUF = round((self.Total_Payoffs_Green/2)+3,1) self.Total_Payoffs_LightSUF = round((self.Total_Payoffs_Light/2)+3,1) self.Total_Payoffs_DarkSUF = round((self.Total_Payoffs_Dark/2)+3,1) def set_belief_bonus(self): if self.id_in_group not in [2, 3]: self.Belief_Selected_Round = 0 self.Belief_Selected_Bonus = 0 return if self.Belief_Selected_Round == 0: selected_round = random.randint(1, Constants.num_rounds) self.Belief_Selected_Round = selected_round selected_group = self.in_round(selected_round).group true_threshold = selected_group.Decision_Principal if self.id_in_group == 2: guess = selected_group.Belief_Light_Principal confidence = selected_group.Belief_Light_Principal_Confidence else: guess = selected_group.Belief_Dark_Principal confidence = selected_group.Belief_Dark_Principal_Confidence distance = abs(guess - true_threshold) if distance == 0: bonus = 2 elif distance <= 5: bonus = 1 else: bonus = 0 self.Belief_Selected_Guess = guess self.Belief_Selected_True_Threshold = true_threshold self.Belief_Selected_Distance = distance self.Belief_Selected_Confidence = confidence self.Belief_Selected_Bonus = bonus def ControlQuestion1_error_message(player, value): if value != 0: return 'Some answers are wrong' def ControlQuestion2_error_message(player, value): if value != 1: return 'Some answers are wrong' def ControlQuestion3_error_message(player, value): if value != 0: return 'Some answers are wrong' def ControlQuestion4_error_message(player, value): if value != 0: return 'Some answers are wrong' def ControlQuestion5_error_message(player, value): if value != 0: return 'Some answers are wrong' def ControlQuestion5_output_error_message(player, value): if value != 34: return 'Some answers are wrong' def ControlQuestion6_error_message(player, value): if value != 1: return 'Some answers are wrong' def ControlQuestion7_error_message(player, value): if value != 1: return 'Some answers are wrong' def ControlQuestion8_error_message(player, value): if value != 0: return 'Some answers are wrong'