from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) # for randomizing import itertools import random author = 'Krishna Srinivasan & Miriam Venturini' doc = """ This app is the experiment for the project on the expressive function of the law. """ class Constants(BaseConstants): name_in_url = 'Survey-uzh' players_per_group = None num_rounds = 1 time = 20 #bonus for guess bonus = c(1) ny_ae = 74 ny_am = 68 ny_do = 32 nj_ae = 60 nj_am = 50 nj_do = 40 me_ae = 30 me_am = 20 me_do = 10 class Subsession(BaseSubsession): def creating_session(self): for p in self.get_players(): if self.session.config['state_config'] == "NY": p.condition = random.choice(['control', 'legal', 'illegal', 'legal_other', 'gtb_legal']) print('set p.condition to', p.condition) elif self.session.config['state_config'] == "NJ": p.condition = random.choice(['control', 'illegal', 'gtb_legal']) print('set p.condition to', p.condition) else: p.condition = random.choice(['control', 'legal', 'illegal']) print('set p.condition to', p.condition) if self.session.config['state_config'] != "ME": if p.condition == "illegal" or p.condition == "control": p.question = random.choice(['am', 'ae', 'do']) print('set p.question to', p.question) else: p.question = random.choice(['am', 'ae']) print('set p.question to', p.question) else: p.question = random.choice(['am', 'ae']) print('set p.question to', p.question) class Group(BaseGroup): pass class Player(BasePlayer): ######################################################### # Demographics age = models.PositiveIntegerField( min=13, max=125, label='What is your age?') state = models.CharField( choices=[ ('AL', 'Alabama'), ('AZ', 'Arizona'), ('AR', 'Arkansas'), ('CA', 'California'), ('CO', 'Colorado'), ('CT', 'Connecticut'), ('DE', 'Delaware'), ('DC', 'District of Columbia'), ('FL', 'Florida'), ('GA', 'Georgia'), ('ID', 'Idaho'), ('IL', 'Illinois'), ('IN', 'Indiana'), ('IA', 'Iowa'), ('KS', 'Kansas'), ('KY', 'Kentucky'), ('LA', 'Louisiana'), ('ME', 'Maine'), ('MD', 'Maryland'), ('MA', 'Massachusetts'), ('MI', 'Michigan'), ('MN', 'Minnesota'), ('MS', 'Mississippi'), ('MO', 'Missouri'), ('MT', 'Montana'), ('NE', 'Nebraska'), ('NV', 'Nevada'), ('NH', 'New Hampshire'), ('NJ', 'New Jersey'), ('NM', 'New Mexico'), ('NY', 'New York'), ('NC', 'North Carolina'), ('ND', 'North Dakota'), ('OH', 'Ohio'), ('OK', 'Oklahoma'), ('OR', 'Oregon'), ('PA', 'Pennsylvania'), ('RI', 'Rhode Island'), ('SC', 'South Carolina'), ('SD', 'South Dakota'), ('TN', 'Tennessee'), ('TX', 'Texas'), ('UT', 'Utah'), ('VT', 'Vermont'), ('VA', 'Virginia'), ('WA', 'Washington'), ('WV', 'West Virginia'), ('WI', 'Wisconsin'), ('WY', 'Wyoming') ], label='Which state do you currently live in?') state_years = models.PositiveIntegerField( min=0, max=100, label='For how many years have you lived in this state?') education = models.CharField( choices=['Less than high school', 'High school credential', 'Some post-high school', 'Bachelor’s degree', 'Graduate degree' ], label='What is the highest level of school you have completed or' ' the highest degree you have received?', widget=widgets.RadioSelect) age = models.PositiveIntegerField(min=0, max=100, label='What is your age?') ######################################################### #define variables of interest # e.g. if 1.8 incarcerated in legal treatment attention1 = models.BooleanField( choices=[(False,'True'), (True,'False')], label='', widget=widgets.RadioSelectHorizontal) attention2 = models.BooleanField( choices=[(False, 'Yes'), (True, 'No') ], label='For a randomly chosen question, if your response is 94 and the true number is 96, ' 'then do you receive a bonus?', widget=widgets.RadioSelect) approve_ever = models.PositiveIntegerField( min=0, max=100, label='') approve_month = models.PositiveIntegerField( min=0, max=100, label='') donation = models.PositiveIntegerField( min=0, max=100, label='') ######################################################### #define variables not used in forms condition = models.CharField() question = models.CharField() question_number = models.CharField() trueprop_ae = models.PositiveIntegerField() trueprop_am = models.PositiveIntegerField() trueprop_do = models.PositiveIntegerField() def display1(self): return self.state == self.session.config['state_config'] def attention(self): return self.attention1 and self.attention2 def donation_q(self): if self.state != "ME": if self.condition == "illegal" or self.condition == "control": return True else: return False else: return False def set_trueprop(self): if self.state == "NY": self.trueprop_ae = Constants.ny_ae self.trueprop_am = Constants.ny_am self.trueprop_do = Constants.ny_do elif self.state == "NJ": self.trueprop_ae = Constants.nj_ae self.trueprop_am = Constants.nj_am self.trueprop_do = Constants.nj_do else: self.trueprop_ae = Constants.me_ae self.trueprop_am = Constants.me_am self.trueprop_do = Constants.me_do def set_payoff(self): if self.question == "ae": # set question number self.question_number = "one" if (self.approve_ever <= self.trueprop_ae + 1) and (self.approve_ever >= self.trueprop_ae - 1): self.payoff = Constants.bonus else: self.payoff = c(0) elif self.question == "am": self.question_number = "two" if (self.approve_month <= self.trueprop_am + 1) and (self.approve_month >= self.trueprop_am - 1): self.payoff = Constants.bonus else: self.payoff = c(0) elif self.question == "do": self.question_number = "three" if (self.donation <=self.trueprop_do + 1) and (self.donation >= self.trueprop_do - 1): self.payoff = Constants.bonus else: self.payoff = c(0)