from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) import random doc = '''Information processing game''' class Constants(BaseConstants): name_in_url = 'information_experiment_1' 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 # random number for policy ovo # >= 0.5 -> Left is left, right is right #ovo_neut_order = random.randint(1, 2) #ovo_pol_order = random.randint(1, 2) #rand_guessing = random.randint(1, 4) treat_boolean = [] for i in range(150): temp_bin = [1,1,1,1,1,1,0,0,0,0] random.shuffle(temp_bin) treat_boolean += temp_bin 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) # group determination p.minimal_group = (0 if random.uniform(0, 1) >= 0.5 else 1) ### TREATMENT DETERMINATION: TO HAVE NON-RANDOM SET EQUAL TO 1 OR 0 p.label_treatment = Constants.treat_boolean[(p.id_in_group-1)] #random.randint(0,1) p.participant.vars['treatment'] = p.label_treatment ### APP ORDER p.processing_first = random.randint(0,1) p.participant.vars['processing_first'] = p.processing_first p.participant.vars['rand_'] = random.randint(0,1) # order determination p.econ_in_process = (0 if x >= 0.5 else 1) p.econ_in_demand = (1 if x >= 0.5 else 0) p.participant.vars['econ_in_process'] = (0 if x >= 0.5 else 1) p.participant.vars['econ_in_demand'] = (1 if x >= 0.5 else 0) p.participant.vars['app_nr'] = 2 p.participant.vars['first_q'] = random.randint(1,4) p.participant.vars['pol_o'] = random.randint(1, 2) p.participant.vars['neut_o'] = 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): # TREATMENT CONDITION label_treatment = models.IntegerField(initial=1) processing_first = models.IntegerField(initial=1) ######################## ## Minimal Groups ## ######################## # MINIMAL GROUP MEMBERSHIP # 0 = circle, 1 = triangle consent = models.IntegerField(label='', initial=None, choices=[[1, 'I agree to participate']], widget=widgets.RadioSelect) recontact = models.IntegerField(label='', initial=None, choices=[[1, 'I agree to be re-contacted in 3 months']], widget=widgets.RadioSelect) recontact_1 = models.IntegerField(label='', initial=None, choices=[[1, 'I agree to be re-contacted in 12 months']], widget=widgets.RadioSelect) minimal_group = models.IntegerField(initial=-1) # Orderings in the experiment econ_in_process = models.IntegerField(initial=-1) econ_in_demand = models.IntegerField(initial=-1) # def passing_order(self): # self.participant.vars['t1'] = self.econ_in_process # self.participant.vars['t2'] = self.econ_in_demand # def passing_bayesian_game(self): # if self.urn_guess == self.urn: # self.participant.vars['income_bayes'] = 1 # else: # self.participant.vars['income_bayes'] = 0 # self.participant.vars['guess_'] = self.urn_guess # self.participant.vars['urn_'] = self.urn def drawing_ball(self): if self.participant.vars['urn'] == 0: if random.uniform(0, 1) >= 1/3: self.participant.vars['ball'] = 0 else: self.participant.vars['ball'] = 1 else: if random.uniform(0, 1) >= 1/3: self.participant.vars['ball'] = 1 else: self.participant.vars['ball'] = 0 ######################################################################################################################## ## 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']] ) ######################################################################################################################## ## BAYESIAN UPDATING TASK ## ######################################################################################################################## # # 0 = yellow Urn, 1 = green Urn # urn = models.IntegerField(initial=None) # # # 0 = yellow Ball, 1 = green Ball # ball = models.IntegerField(initial=None) # # # Urn Guess: 0 = yellow, 1 = green # urn_guess = models.IntegerField(initial=None, # choices=[[0, 'Yellow cup'], # [1, 'Green cup']], # widget=widgets.RadioSelect) ######################################################################################################################## ## Prediction Measures ## ######################################################################################################################## # adapt the style at this point here again econ_measure_biden = models.IntegerField(label='What will the unemployment rate be in September 2021 if Biden wins?', 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).']] ) econ_measure_trump = models.IntegerField(label='What will the unemployment rate be in September 2021 if Trump wins', 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).']] ) health_measure_biden = 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)']] ) health_measure_trump = 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)']] ) def passing_priors(self): self.participant.vars['priors_biden'] = [self.econ_measure_biden, self.health_measure_biden] self.participant.vars['priors_trump'] = [self.econ_measure_trump, self.health_measure_trump] ######################################################################################################################## ## Policy Items ## ######################################################################################################################## # PETERSON YENGAR climate_change = models.IntegerField(label='The vast majority (over 90%) of climate scientists believe that global warming is an established fact and that it is most likely caused by man-made emissions.', choices=[[1, 'True'], [0, 'False']], widget=widgets.RadioSelect ) cohen_plea = models.IntegerField(label='Michael Cohen, Donald Trump’s personal lawyer, pleaded guilty to fraud and illegal campaign finance charges in August 2018.', choices=[[1, 'True'], [0, 'False']], widget=widgets.RadioSelect ) fire_arm = models.IntegerField(label='40% of firearm sales in the US occur without a background check.', choices=[[1, 'True'], [0, 'False']], widget=widgets.RadioSelect ) immigrant_crime = models.IntegerField(label='Illegal immigrants commit violent crime at a significantly higher rate than legal American citizens.', choices=[[1, 'True'], [0, 'False']], widget=widgets.RadioSelect ) obama_wiretap = models.IntegerField(label='Former President Barack Obama ordered wire taps on Donald Trump’s phones.', choices=[[1, 'True'], [0, 'False']], widget=widgets.RadioSelect ) voter_fraud = models.IntegerField(label='Millions of illegal votes were cast in the 2016 presidential election.', choices=[[1, 'True'], [0, 'False']], widget=widgets.RadioSelect ) # unemployment = models.IntegerField(label='Compared to January 2017, has the level of unemployment in the country increased, stayed the same, or decreased?', # choices=[ # [0, 'Decreased'], # [1, 'Stayed the same'], # [2, 'Increased']], # widget=widgets.RadioSelect # ) # POLITICAL SURVEY 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:', choices=[ [1, '(a) Democratic party'], [2, '(b) Republican party'] ], widget=widgets.RadioSelect ) # # # # Polarized Attitudes # # # abortion = models.IntegerField(label='By law, a woman should always be able to obtain an abortion.', # choices=[ # [1, 'I completely agree'], # [2, 'I agree'], # [3, 'I am indifferent'], # [4, 'I disagree'], # [5, 'I completely disagree'], # ], # widget=widgets.RadioSelect # ) # # racial_eq = models.IntegerField(label='It is a lot more difficult to be a Black person in this country than it is to be a white person.', # choices=[ # [1, 'I completely agree'], # [2, 'I agree'], # [3, 'I am indifferent'], # [4, 'I disagree'], # [5, 'I completely disagree'], # ], # widget=widgets.RadioSelect # ) # # # gender_eq = models.IntegerField(label='Women today still face obstacles that make it harder for them to get ahead than men.', # choices=[ # [1, 'I completely agree'], # [2, 'I agree'], # [3, 'I am indifferent'], # [4, 'I disagree'], # [5, 'I completely disagree'], # ], # widget=widgets.RadioSelect # ) # # # law_order = models.IntegerField(label='In order to ensure security, it is justified to rough up protestors if necessary.', # choices=[ # [1, 'I completely agree'], # [2, 'I agree'], # [3, 'I am indifferent'], # [4, 'I disagree'], # [5, 'I completely disagree'], # ], # widget=widgets.RadioSelect # ) # # # islamophobia = models.IntegerField(label='Islam encourages violence more than other religions.', # choices=[ # [1, 'I completely agree'], # [2, 'I agree'], # [3, 'I am indifferent'], # [4, 'I disagree'], # [5, 'I completely disagree'], # ], # widget=widgets.RadioSelect # ) # # # immigration = models.IntegerField(label='The recent levels of immigration will take jobs away from the people already here.', # choices=[ # [1, 'I completely agree'], # [2, 'I agree'], # [3, 'I am indifferent'], # [4, 'I disagree'], # [5, 'I completely disagree'], # ], # widget=widgets.RadioSelect # ) # # leader = models.IntegerField(label='What we really need is a strong leader who takes our nation back to its true path.', # choices=[ # [1, 'I completely agree'], # [2, 'I agree'], # [3, 'I am indifferent'], # [4, 'I disagree'], # [5, 'I completely disagree'], # ], # widget=widgets.RadioSelect # ) # # anti_est = models.IntegerField(label='Government is run by a few big interests looking for their own benefit.” / “Most politicians care only about the interests of the rich and the powerful.', # choices=[ # [1, 'I completely agree'], # [2, 'I agree'], # [3, 'I am indifferent'], # [4, 'I disagree'], # [5, 'I completely disagree'], # ], # widget=widgets.RadioSelect # ) # # pol_corr = models.IntegerField(label='Political Correctness undermines Americans‘ right to free speech.', # choices=[ # [1, 'I completely agree'], # [2, 'I agree'], # [3, 'I am indifferent'], # [4, 'I disagree'], # [5, 'I completely disagree'], # ], # widget=widgets.RadioSelect # ) # # health_ins = models.IntegerField(label='Government should increase spending to help people pay for health insurance.', # choices=[ # [1, 'I completely agree'], # [2, 'I agree'], # [3, 'I am indifferent'], # [4, 'I disagree'], # [5, 'I completely disagree'], # ], # widget=widgets.RadioSelect # ) # # env_pol = models.IntegerField(label='Policies aiming to reduce the effects of global warming generally hurt the U.S. economy.', # choices=[ # [1, 'I completely agree'], # [2, 'I agree'], # [3, 'I am indifferent'], # [4, 'I disagree'], # [5, 'I completely disagree'], # ], # widget=widgets.RadioSelect # ) # # media_trust = models.IntegerField(label='In general, mainstream media cannot be trusted.', # choices=[ # [1, 'I completely agree'], # [2, 'I agree'], # [3, 'I am indifferent'], # [4, 'I disagree'], # [5, 'I completely disagree'], # ], # widget=widgets.RadioSelect # ) # # # global_env = models.IntegerField(label='Global warming is due to human activities.', # choices=[ # [1, 'I completely agree'], # [2, 'I agree'], # [3, 'I am indifferent'], # [4, 'I disagree'], # [5, 'I completely disagree'], # ], # widget=widgets.RadioSelect # ) # # # soc_eq = models.IntegerField(label='Everyone has an equal opportunity to succeed.', # choices=[ # [1, 'I completely agree'], # [2, 'I agree'], # [3, 'I am indifferent'], # [4, 'I disagree'], # [5, 'I completely disagree'], # ], # widget=widgets.RadioSelect # ) # # gun_law = models.IntegerField(label='Government should make it more difficult to buy guns.', # choices=[ # [1, 'I completely agree'], # [2, 'I agree'], # [3, 'I am indifferent'], # [4, 'I disagree'], # [5, 'I completely disagree'], # ], # widget=widgets.RadioSelect # ) # # redistr = models.IntegerField(label='Government should reduce the difference in income between the rich and the poor.', # choices=[ # [1, 'I completely agree'], # [2, 'I agree'], # [3, 'I am indifferent'], # [4, 'I disagree'], # [5, 'I completely disagree'], # ], # widget=widgets.RadioSelect # ) # # wealth_tax = models.IntegerField(label='In order to achieve equality, it is necessary to increase taxes on people making over one million dollars per year.', # choices=[ # [1, 'I completely agree'], # [2, 'I agree'], # [3, 'I am indifferent'], # [4, 'I disagree'], # [5, 'I completely disagree'], # ], # widget=widgets.RadioSelect # ) # # lgbt = models.IntegerField(label='Gay and lesbian couples should be allowed to legally marry.', # choices=[ # [1, 'I completely agree'], # [2, 'I agree'], # [3, 'I am indifferent'], # [4, 'I disagree'], # [5, 'I completely disagree'], # ], # 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