from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) import random import numpy as np import csv import pandas as pd doc = '''Information processing game, posterior''' class Constants(BaseConstants): name_in_url = 'Information_processing_intro' players_per_group = None num_rounds = 1 #instructions_template = 'information_experiment_1/instructions.html' # Initial amount allocated to decision maker endowment = 6 conversion_rate = 0.1 payment_correct_guesses = 0.5 # random assignment of treatments # we would like to have 50 / 50 ex ante treat_boolean = [] for i in range(150): temp_bin = [1,1,1,1,1,0,0,0,0,0] random.shuffle(temp_bin) treat_boolean += temp_bin # loading the data of first study and prepare a dict with key = prolific ID temp_df = pd.read_csv('post_information_experiment_intro/pre_study_data_.csv', sep=';') list_prolid = temp_df['prol_id'].tolist() temp_lists = [] for cols_ in temp_df.drop(['prol_id'], axis=1).columns: temp_lists.append(temp_df[cols_].tolist()) # 0 = election_outcome_electoral --> 1 == Trump , 0 == Biden # 1 = election_outcome_popular --> 1 == Trump , 0 == Biden # 2 = econ_measure # 3 = health_measure temp_tuple = list(zip(temp_lists[0], temp_lists[1], temp_lists[2], temp_lists[3])) prol_dict = dict(zip(list_prolid, temp_tuple)) class Subsession(BaseSubsession): # Creating random group assignment for players # 2 Groups triangle = 1, circle = 0 def creating_session(self): for p in self.get_players(): # random number #x = random.uniform(0, 1) ## MINIMAL GROUP DETERMINATION p.minimal_group = (0 if random.uniform(0, 1) >= 0.5 else 1) ### TREATMENT DETERMINATION: OBSERVING THE SHARES OF CORRECT URN GUESSES OR NOT p.treatment = Constants.treat_boolean[(p.id_in_group-1)] p.participant.vars['treatment'] = p.treatment # order determination #p.participant.vars['app_nr'] = 2 p.participant.vars['update_order'] = random.randint(1,2) p.participant.vars['pol_order'] = random.randint(1, 2) p.participant.vars['neut_order'] = random.randint(1, 2) # Urn setting #p.participant.vars['urn'] = (0 if random.uniform(0, 1) >= 0.5 else 1) class Group(BaseGroup): pass class Player(BasePlayer): def prior_decisions(self): # information from wave 1: try: self.participant.vars['guess_pop_vote'] = Constants.prol_dict[self.participant.label][0] self.participant.vars['guess_president'] = Constants.prol_dict[self.participant.label][1] self.participant.vars['econ_guess'] = Constants.prol_dict[self.participant.label][2] self.participant.vars['health_guess'] = Constants.prol_dict[self.participant.label][3] except: self.participant.vars['guess_pop_vote'] = random.randint(0,1) self.participant.vars['guess_president'] = random.randint(0,1) self.participant.vars['econ_guess'] = random.randint(-2,2) self.participant.vars['health_guess'] = random.randint(-2,2) # Biden = 0, Trump = 1: if both are 0 --> both guesses for Biden, ... if (self.participant.vars['guess_president'] + self.participant.vars['guess_pop_vote']) == 0: self.participant.vars['income_wave1'] = 6 elif (self.participant.vars['guess_president'] + self.participant.vars['guess_pop_vote']) == 1: self.participant.vars['income_wave1'] = 3 else: self.participant.vars['income_wave1'] = 0 # TREATMENT CONDITION treatment = models.IntegerField(initial=1) ######################## ## Minimal Groups ## ######################## # MINIMAL GROUP MEMBERSHIP # 0 = circle, 1 = triangle minimal_group = models.IntegerField(initial=-1) ######################################################################################################################## ## RATIONALITY GUESSES ## ######################################################################################################################## dem_correct_guess = models.IntegerField(label='Among the Democrats, what is the share of participants who correctly guessed the cup?', initial=None, choices=[[2, 'More than 80%.'], [1, 'More than 70%, but less than or equal to 80%.'], [0, 'Between 60% and 70%, inclusive.'], [-1, 'Less than 60%, but more than or equal to 50%.'], [-2, 'Less than 50%.']]) rep_correct_guess = models.IntegerField(label='Among the Republicans, what is the share of participants who correctly guessed the cup?', initial=None, choices=[[2, 'More than 80%.'], [1, 'More than 70%, but less than or equal to 80%.'], [0, 'Between 60% and 70%, inclusive.'], [-1, 'Less than 60%, but more than or equal to 50%.'], [-2, 'Less than 50%.']]) def rationality_guess(self): # GUESS FOR DEMS IS CORRECT self.participant.vars['correct_dem_guess'] = self.dem_correct_guess self.participant.vars['correct_rep_guess'] = self.rep_correct_guess if self.republican_1 == 1 | self.republican_3 == 1: self.participant.vars['democrat'] = 1 else: self.participant.vars['democrat'] = 0 self.participant.vars['payoff_intro'] = 0 self.participant.vars['dem_correct_guess'] = 0 self.participant.vars['rep_correct_guess'] = 0 if self.dem_correct_guess == 0: self.participant.vars['payoff_intro'] += Constants.payment_correct_guesses self.participant.vars['dem_correct_guess'] = 1 if self.rep_correct_guess == 0: self.participant.vars['payoff_intro'] += Constants.payment_correct_guesses self.participant.vars['rep_correct_guess'] = 1 ######################################################################################################################## ## OvO Tasks ## ######################################################################################################################## # MINIMAL GROUP ovo_neutral_both_triangle_p1 = models.CurrencyField(initial=None, choices=[[1, '$1 to person 1 ------- $5 to person 2'], [2, '$2 to person 1 ------- $4 to person 2'], [3, '$3 to person 1 ------- $3 to person 2'], [4, '$4 to person 1 ------- $2 to person 2'], [5, '$5 to person 1 ------- $1 to person 2']] ) ovo_neutral_both_circle_p1 = models.CurrencyField(initial=None, choices=[[1, '$1 to person 1 ------- $5 to person 2'], [2, '$2 to person 1 ------- $4 to person 2'], [3, '$3 to person 1 ------- $3 to person 2'], [4, '$4 to person 1 ------- $2 to person 2'], [5, '$5 to person 1 ------- $1 to person 2']] ) ovo_neutral_different_circle = models.CurrencyField(initial=None, choices=[[1, '$1 to person 1 ------- $5 to person 2'], [2, '$2 to person 1 ------- $4 to person 2'], [3, '$3 to person 1 ------- $3 to person 2'], [4, '$4 to person 1 ------- $2 to person 2'], [5, '$5 to person 1 ------- $1 to person 2']] ) # POLICY ovo_pol_both_dem_p1 = models.CurrencyField(initial=None, choices=[[1, '$1 to person 1 ------- $5 to person 2'], [2, '$2 to person 1 ------- $4 to person 2'], [3, '$3 to person 1 ------- $3 to person 2'], [4, '$4 to person 1 ------- $2 to person 2'], [5, '$5 to person 1 ------- $1 to person 2']] ) ovo_pol_both_rep_p1 = models.CurrencyField(initial=None, choices=[[1, '$1 to person 1 ------- $5 to person 2'], [2, '$2 to person 1 ------- $4 to person 2'], [3, '$3 to person 1 ------- $3 to person 2'], [4, '$4 to person 1 ------- $2 to person 2'], [5, '$5 to person 1 ------- $1 to person 2']] ) ovo_pol_different_dem = models.CurrencyField(initial=None, choices=[[1, '$1 to person 1 ------- $5 to person 2'], [2, '$2 to person 1 ------- $4 to person 2'], [3, '$3 to person 1 ------- $3 to person 2'], [4, '$4 to person 1 ------- $2 to person 2'], [5, '$5 to person 1 ------- $1 to person 2']] ) ######################################################################################################################## ## Prediction Measures ## ######################################################################################################################## # adapt the style at this point here again econ_measure_biden_won = models.IntegerField(label='', initial=None, choices=[[2, 'Strong increase (10 % or higher).'], [1, 'Moderate increase (Higher than or equal to 8.5 %, but less than 10 %).'], [0, 'Stable (Higher than or equal to 7.5 %, but less than 8.5 %).'], [-1, 'Moderate decrease (Higher than or equal to 6 %, but less than 7.5 %).'], [-2, 'Strong decrease (6 % or lower).'], [-5, 'I do not want to change my previous prediction.']] ) health_measure_biden_won = models.IntegerField(label='', initial=None, choices=[[2, 'Strong improvement (Rank 12 or better)'], [1, 'Moderate improvement (Rank 13 or 14)'], [0, 'No change (Rank 15)'], [-1, 'Moderate decline (Rank 16 or 17)'], [-2, 'Strong decline (Rank 18 or worse)'], [-5, 'I do not want to change my previous prediction.']] ) ######################################################################################################################## ## Policy Items ## ######################################################################################################################## # POLITICAL SURVEY change_pol_ident = models.IntegerField(label='Since your participation in our experiment in late October, your political party affiliation, leaning, or strength of affiliation:', initial=None, choices=[ [0, '(a) remains the same'], [1, '(b) has changed']], widget=widgets.RadioSelect ) republican_1 = models.IntegerField(label='Do you consider yourself a(n)', choices=[ [1, '(a) Democrat'], [2, '(b) Republican'], [3, '(c) Independent'], [4, '(d) None of the above'] ], widget=widgets.RadioSelect ) republican_2 = models.IntegerField(label='Are you a strong or moderate Democrat/Republican?', choices=[ [1, '(a) Strong'], [2, '(b) Moderate'] ], widget=widgets.RadioSelect ) republican_3 = models.IntegerField(label='Do you consider yourself closer to the:', initial=-1, choices=[ [1, '(a) Democratic party'], [2, '(b) Republican party'] ], widget=widgets.RadioSelect ) # election_outcome_electoral = models.IntegerField(label='', # widget=widgets.RadioSelect # ) # # # def election_outcome_electoral_choices(self): # if self.participant.vars['rand_'] == 0: # choices = [[0, 'Joe Biden'], [1, 'Donald Trump']] # else: # choices = [[1, 'Donald Trump'], [0, 'Joe Biden']] # return choices # # # election_outcome_popular = models.IntegerField(label='', # widget=widgets.RadioSelect # ) # # # def election_outcome_popular_choices(self): # if self.participant.vars['rand_'] == 0: # choices = [[0, 'Joe Biden'], [1, 'Donald Trump']] # else: # choices = [[1, 'Donald Trump'], [0, 'Joe Biden']] # return choices