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
fixed_fee = 2
correct_answer1 = 0
correct_answer2 = 0
correct_answer3 = 0
cq_incentive = 0.5
correct_forecast = 5
class Subsession(BaseSubsession):
def creating_session(self):
for p in self.get_players():
# TREATMENT VARIATIONS
p.human_article = random.randint(0, 1)
p.econ_topic = random.randint(0, 1)
class Group(BaseGroup):
pass
class Player(BasePlayer):
def ControlQuestion(self):
if Constants.correct_control == self.mask_control:
self.participant.vars['control_correct'] = 1
self.participant.payoff += 1
self.participant.vars['bonus'] = self.participant.vars['income_guess'] + 1
else:
self.participant.vars['control_correct'] = 0
self.participant.vars['bonus'] = self.participant.vars['income_guess']
########################
## GENERAL QUESTIONS ##
########################
# HUMAN OR AI TREATMENT
human_article = models.IntegerField(initial=-1)
# 1 = ECONOMIC TOPIC, 2 = HEALTH TOPIC
econ_topic = models.IntegerField(initial=-1)
# CONSENTS
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 one month']],
widget=widgets.RadioSelect)
income_ = models.FloatField(initial=Constants.fixed_fee)
########################################################################################################################
## ARTICLE QUESTIONS ##
########################################################################################################################
def payoffs_(self):
self.participant.vars['correct_answers'] = 0
if Constants.correct_answer1 == self.control_1:
self.participant.vars['correct_answers'] += 1
if Constants.correct_answer2 == self.control_2:
self.participant.vars['correct_answers'] += 1
if Constants.correct_answer3 == self.control_3:
self.participant.vars['correct_answers'] += 1
self.participant.vars['income_answers'] = Constants.cq_incentive*self.participant.vars['correct_answers']
self.income_ += self.participant.vars['income_answers']
def setting_labels(self):
if self.econ_topic == 1:
choices_ = [[0, 'Strong increase (XX % or higher).'],
[1, 'Moderate increase (Higher than or equal to XX %, but less than XX %).'],
[2, 'Stable (Higher than or equal to XX %, but less than XX %).'],
[3, 'Moderate decrease (Higher than or equal to XX %, but less than XX %).'],
[4, 'Strong decrease (XX % or lower).']]
self.participant.vars['labels_'] = [choices_[i][1] for i in range(5)]
#print(self.participant.vars['labels_'])
self.participant.vars['choices_'] = choices_
else:
choices_ = [[0, 'Strong increase (XYYX % or higher).'],
[1, 'Moderate increase (Higher than or equal to XX %, but less than YYY %).'],
[2, 'Stable (Higher than or equal to YYY %, but less than YYY %).'],
[3, 'Moderate decrease (Higher than or equal to XX %, but less than YYY %).'],
[4, 'Strong decrease (YYY % or lower).']]
self.participant.vars['labels_'] = [choices_[i][1] for i in range(5)]
#print(self.participant.vars['labels_'])
self.participant.vars['choices_'] = choices_
####### PRIOR PREDICTIONS #######
prior_prediction = models.IntegerField(label="",
initial=None,
widget=widgets.RadioSelect
)
def prior_prediction_choices(self):
return self.participant.vars['choices_']
prior_conf = models.IntegerField(label="On a scale from 1 to 5, with 1 being not confident at all and 5 being extremely confident,
how confident are you, that your forecast will turn out to be true.",
initial=None,
choices=[[1, '1 (Not confident at all.)'],
[2, '2'],
[3, '3'],
[4, '4'],
[5, '5 (Extremely confident.)']],
widget=widgets.RadioSelect
)
####### POSTERIOR PREDICTION #######
post_prediction = models.IntegerField(label="",
initial=None,
widget=widgets.RadioSelect
)
def post_prediction_choices(self):
return self.participant.vars['choices_']
post_conf = models.IntegerField(label="On a scale from 1 to 5, with 1 being not confident at all and 5 being extremely confident,
how confident are you, that your forecast will turn out to be true.",
initial=None,
choices=[[1, '1 (Not confident at all.)'],
[2, '2'],
[3, '3'],
[4, '4'],
[5, '5 (Extremely confident.)']],
widget=widgets.RadioSelect
)
####### WRITING A BRIEF SUMMARY #######
summary_ = models.LongStringField(label="", initial=None)
conf_ = models.IntegerField(
label="On a scale from 1 to 5, with 1 being not confident at all and 5 being extremely confident,
how confident are you that your summary helps the other person make a better decision.",
initial=None,
choices=[[1, '1 (Not confident at all.)'],
[2, '2'],
[3, '3'],
[4, '4'],
[5, '5 (Extremely confident.)']],
widget=widgets.RadioSelect
)
####### PERCEPTION OF ARTICLE 1 #######
skew = models.IntegerField(
label='On a scale of -3 to +3, with negative numbers representing left leaning or liberal skew,
positive numbers representing right leaning or conservative skew, and 0 representing neutral,
how would you rate the article you just read?',
initial=None,
choices=[[-3, '-3 (extremely left leaning)'],
[-2, '-2 (left leaning)'],
[-1, '-1 (slightly left leaning)'],
[0, '0 (neutral)'],
[1, '1 (slightly right leaning)'],
[2, '2 (right leaning)'],
[3, '3 (extremely right leaning)']])
reliance = models.IntegerField(
label='On a scale of 1 to 7, with 1 being not reliable at all and 7 being extremely reliable,
how would you rate the information in the article you just read?',
initial=None,
choices=[[1, '1 (Not reliable at all)'],
[2, '2'],
[3, '3'],
[4, '4 (Fairly reliable)'],
[5, '5'],
[6, '6'],
[7, '7 (extremely reliable)']])
inspiring = models.IntegerField(
label='On a scale of 1 to 7, with 1 being not inspiring at all and 7 being extremely inspiring,
how would you rate the article you just read?',
initial=None,
choices=[[1, '1 (Not inspiring at all)'],
[2, '2'],
[3, '3'],
[4, '4 (Fairly inspiring)'],
[5, '5'],
[6, '6'],
[7, '7 (Extremely inspiring)']])
objectivity = models.IntegerField(
label='On a scale of 1 to 7, with 1 being not objective at all and 7 being extremely objective,
how would you rate the article you just read?',
initial=None,
choices=[[1, '1 (Not objective at all)'],
[2, '2'],
[3, '3'],
[4, '4 (Fairly objective)'],
[5, '5'],
[6, '6'],
[7, '7 (Extremely objective)']])
####### CONTROL QUESTIONS #######
control_1 = models.IntegerField(
label='TBD',
initial=None,
choices=[
[0, 'False'],
[1, 'True']],
widget=widgets.RadioSelect
)
control_2 = models.IntegerField(
label='TBD',
initial=None,
choices=[
[0, 'False'],
[1, 'True']],
widget=widgets.RadioSelect
)
control_3 = models.IntegerField(
label='TBD',
initial=None,
choices=[
[0, 'False'],
[1, 'True']],
widget=widgets.RadioSelect
)
helpful = models.IntegerField(
label='On a scale of 1 to 7, with 1 being not helpful at all and 7 being extremely helpful,
how would you rate the article\'s helpfulness to make a better forecast?',
initial=None,
choices=[[1, '1 (Not objective at all)'],
[2, '2'],
[3, '3'],
[4, '4 (Fairly objective)'],
[5, '5'],
[6, '6'],
[7, '7 (Extremely objective)']])
# ARTICLE 2
skew_2 = models.IntegerField(
label='On a scale of -3 to +3, with negative numbers representing left leaning or liberal skew,
positive numbers representing right leaning or conservative skew, and 0 representing neutral,
how would you rate the article you just read?',
initial=None,
choices=[[-3, '-3 (extremely left leaning)'],
[-2, '-2 (left leaning)'],
[-1, '-1 (slightly left leaning)'],
[0, '0 (neutral)'],
[1, '1 (slightly right leaning)'],
[2, '2 (right leaning)'],
[3, '3 (extremely right leaning)']])
reliance_2 = models.IntegerField(
label='On a scale of 1 to 7, with 1 being not reliable at all and 7 being extremely reliable,
how would you rate the information in the article you just read?',
initial=None,
choices=[[1, '1 (Not reliable at all)'],
[2, '2'],
[3, '3'],
[4, '4 (Fairly reliable)'],
[5, '5'],
[6, '6'],
[7, '7 (extremely reliable)']])
inspiring_2 = models.IntegerField(
label='On a scale of 1 to 7, with 1 being not inspiring at all and 7 being extremely inspiring,
how would you rate the article you just read?',
initial=None,
choices=[[1, '1 (Not inspiring at all)'],
[2, '2'],
[3, '3'],
[4, '4 (Fairly inspiring)'],
[5, '5'],
[6, '6'],
[7, '7 (Extremely inspiring)']])
objectivity_2 = models.IntegerField(
label='On a scale of 1 to 7, with 1 being not objective at all and 7 being extremely objective,
how would you rate the article you just read?',
initial=None,
choices=[[1, '1 (Not objective at all)'],
[2, '2'],
[3, '3'],
[4, '4 (Fairly objective)'],
[5, '5'],
[6, '6'],
[7, '7 (Extremely objective)']])
helpful_2 = models.IntegerField(
label='On a scale of 1 to 7, with 1 being not helpful at all and 7 being extremely helpful,
how would you rate the article\'s helpfulness to make a better forecast?',
initial=None,
choices=[[1, '1 (Not objective at all)'],
[2, '2'],
[3, '3'],
[4, '4 (Fairly objective)'],
[5, '5'],
[6, '6'],
[7, '7 (Extremely objective)']])
####### CONTROL QUESTIONS #######
control_1_2 = models.IntegerField(
label='TBD',
initial=None,
choices=[
[0, 'False'],
[1, 'True']],
widget=widgets.RadioSelect
)
control_2_2 = models.IntegerField(
label='TBD',
initial=None,
choices=[
[0, 'False'],
[1, 'True']],
widget=widgets.RadioSelect
)
control_3_2 = models.IntegerField(
label='TBD',
initial=None,
choices=[
[0, 'False'],
[1, 'True']],
widget=widgets.RadioSelect
)
########################################################################################################################
## SELF-ESTEEM MEASURE ROSENBERG ##
########################################################################################################################
rosen_1 = models.IntegerField(
label='On the whole, I am satisfied with myself.',
initial=None,
choices=[
[1, ' Strongly Disagree'],
[2, ' Disagree'],
[3, ' Agree'],
[4, ' Strongly Agree']],
widget=widgets.RadioSelect
)
rosen_2 = models.IntegerField(
label='At times I think I am no good at all.',
initial=None,
choices=[
[4, ' Strongly Disagree'],
[3, ' Disagree'],
[2, ' Agree'],
[1, ' Strongly Agree']],
widget=widgets.RadioSelect
)
rosen_3 = models.IntegerField(
label='I feel that I have a number of good qualities.',
initial=None,
choices=[
[1, ' Strongly Disagree'],
[2, ' Disagree'],
[3, ' Agree'],
[4, ' Strongly Agree']],
widget=widgets.RadioSelect
)
rosen_4 = models.IntegerField(
label='I am able to do things as well as most other people.',
initial=None,
choices=[
[1, ' Strongly Disagree'],
[2, ' Disagree'],
[3, ' Agree'],
[4, ' Strongly Agree']],
widget=widgets.RadioSelect
)
rosen_5 = models.IntegerField(
label='I feel I do not have much to be proud of.',
initial=None,
choices=[
[4, ' Strongly Disagree'],
[3, ' Disagree'],
[2, ' Agree'],
[1, ' Strongly Agree']],
widget=widgets.RadioSelect
)
rosen_6 = models.IntegerField(
label='I certainly feel useless at times.',
initial=None,
choices=[
[4, ' Strongly Disagree'],
[3, ' Disagree'],
[2, ' Agree'],
[1, ' Strongly Agree']],
widget=widgets.RadioSelect
)
rosen_7 = models.IntegerField(
label='I feel that I\'m a person of worth, at least on an equal plane with others.',
initial=None,
choices=[
[1, ' Strongly Disagree'],
[2, ' Disagree'],
[3, ' Agree'],
[4, ' Strongly Agree']],
widget=widgets.RadioSelect
)
rosen_8 = models.IntegerField(
label='I wish I could have more respect for myself.',
initial=None,
choices=[
[4, ' Strongly Disagree'],
[3, ' Disagree'],
[2, ' Agree'],
[1, ' Strongly Agree']],
widget=widgets.RadioSelect
)
rosen_9 = models.IntegerField(
label='All in all, I am inclined to feel that I am a failure.',
initial=None,
choices=[
[4, ' Strongly Disagree'],
[3, ' Disagree'],
[2, ' Agree'],
[1, ' Strongly Agree']],
widget=widgets.RadioSelect
)
rosen_10 = models.IntegerField(
label='I take a positive attitude toward myself.',
initial=None,
choices=[
[1, ' Strongly Disagree'],
[2, ' Disagree'],
[3, ' Agree'],
[4, ' Strongly Agree']],
widget=widgets.RadioSelect
)
########################################################################################################################
## NEWS QUESTIONS ## /Users/kev/Downloads otree unzip BLAH.otreezip
########################################################################################################################
abc = models.IntegerField(blank=True,
choices=[[1, 'ABC, NBC, or CBS']],
widget=widgets.RadioSelect)
cnn = models.IntegerField(blank=True,
choices=[[1, 'CNN']],
widget=widgets.RadioSelect)
fox = models.IntegerField(blank=True,
choices=[[1, 'Fox News']],
widget=widgets.RadioSelect)
local = models.IntegerField(blank=True,
choices=[[1, 'Local TV or radio']],
widget=widgets.RadioSelect)
msnbc = models.IntegerField(blank=True,
choices=[[1, 'MSNBC']],
widget=widgets.RadioSelect)
npr = models.IntegerField(blank=True,
choices=[[1, 'NPR (National Public Radio) or PBS']],
widget=widgets.RadioSelect)
magazines = models.IntegerField(blank=True,
initial=0,
choices=[[1, 'Newspapers, magazines, online or in paper']],
widget=widgets.RadioSelect)
face = models.IntegerField(blank=True,
choices=[[1, 'Facebook']],
widget=widgets.RadioSelect)
twit = models.IntegerField(blank=True,
choices=[[1, 'Twitter']],
widget=widgets.RadioSelect)
other = models.StringField(
blank=True,
initial=None)
economist = models.IntegerField(blank=True,
choices=[[1, 'Economist']],
widget=widgets.RadioSelect)
nyt = models.IntegerField(blank=True,
choices=[[1, 'New York Times']],
widget=widgets.RadioSelect)
wsj = models.IntegerField(blank=True,
choices=[[1, 'Wall Street Journal']],
widget=widgets.RadioSelect)
wash_ex = models.IntegerField(blank=True,
choices=[[1, 'Washington Examiner']],
widget=widgets.RadioSelect)
wash_pos = models.IntegerField(blank=True,
choices=[[1, 'Washington Post']],
widget=widgets.RadioSelect)
nature = models.IntegerField(blank=True,
choices=[[1, 'Nature']],
widget=widgets.RadioSelect)
science = models.IntegerField(blank=True,
choices=[[1, 'Science']],
widget=widgets.RadioSelect)
other_2 = models.StringField(label='',
blank=True,
initial=None)
### STRING WITH PARTICIPANTS PARTY AFFILIATION
def party_aff(self):
if (self.republican_1 == 1) | (self.republican_3 == 1):
self.participant.vars['party_aff'] = ['Democrat', 'Democratic', 'Republican', 'Republican']
else:
self.participant.vars['party_aff'] = ['Republican', 'Republican', 'Democrat', 'Democratic']