from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) import random #from otree_tools.models import fields as tool_models import itertools import json class Constants(BaseConstants): name_in_url = 'demographic_survey' players_per_group = None surveys = ['1', '2', '3'] num_rounds = 1 StandardChoices=[ [1, 'Disagree strongly'], [2, 'Disagree moderately'], [3, 'Disagree a little'], [4, 'Neither agree nor disagree'], [5, 'Agree a little'], [6, 'Agree moderately'], [7, 'Agree strongly'], ] class Subsession(BaseSubsession): def creating_session(self): if self.round_number == 1: for p in self.get_players(): round_numbers = list(range(1, Constants.num_rounds + 1)) random.shuffle(round_numbers) p.participant.vars['surveys_rounds'] = dict(zip(Constants.surveys, round_numbers)) p.participant.vars['num_rounds'] = Constants.num_rounds class Group(BaseGroup): pass class Player(BasePlayer): #Demographics race = models.IntegerField( label="Choose the race that you consider yourself to be", choices=[ [1, 'White or Caucasian'], [2, 'Black or African American'], [3, 'American Indian/ Native American or Alaska Native'], [4, 'Asian'], [5, 'Native Hawaiian or Other Pacific Islander'], [6, 'Other'], [7, 'I prefer not to say.'] ] ) state = models.StringField( label="What is the state of your residency?", choices=['AK', 'AL', 'AR', 'AZ', 'CA', 'CO', 'CT', 'DC', 'DE', 'FL', 'GA', 'HI', 'IA', 'ID', 'IL', 'IN', 'KS', 'KY', 'LA', 'MA', 'MD', 'ME', 'MI', 'MN', 'MO', 'MS', 'MT', 'NC', 'ND', 'NE', 'NH', 'NJ', 'NM', 'NV', 'NY', 'OH', 'OK', 'OR', 'PA', 'RI', 'SC', 'SD', 'TN', 'TX', 'UT', 'VA', 'VT', 'WA', 'WI', 'WV', 'WY'] ) zipcode = models.IntegerField( label="What is the zipcode of your residency?", min=0, max=99999, blank=True, initial=None ) education = models.IntegerField( label="What is the highest level of education that you have completed?", choices=[ [1, 'Some high school or less'], [2, 'High school diploma or GED'], [3, 'Some college but no degree'], [4, 'Associates or technical degree'], [5, 'Bachelors degree'], [6, 'Graduate or professional degree (MA, MS, MBA, PhD, JD, MD, DDS, etc)'], [7, 'I prefer not to say.'] ] ) marital_status = models.IntegerField( label="What is your marital status?", choices=[ [1, 'Single, never married'], [2, 'Married or domestic partnership'], [3, 'Widowed'], [4, 'Divorced'], [5, 'Separated'], [6, 'I prefer not to say.'] ] ) household_income = models.IntegerField( label="What was your total household income before taxes during the past 12 months?", choices=[ [1, 'Less than $25,000'], [2, '$25,000-$49,999'], [3, '$50,000-$74,999'], [4, '$75,000-$99,999'], [5, '$100,000-$149,999'], [6, '$150,000 or more'], [7, 'I prefer not to say.'] ] ) health_insurance = models.IntegerField( label="Are you currently covered by any of the following types of health insurance or health coverage plans?", choices=[ [1, 'Insurance through a current or former employer or union'], [2, 'Insurance purchased directly from an insurance company'], [3, 'Medicare, for people 65 or older, or people with certain disabilities'], [4, 'Medicaid, Medical Assistance, or any kind of government assistance for those with low incomes or ' 'a disability'], [5, 'TRICARE or other military healthcare'], [6, 'VA (enrolled for VA healthcare)'], [7, 'Indian Health Service'], [8, 'Any other type of health insurance or health coverage plan'] ] ) access_to_healthcare = models.IntegerField( label="How difficult do you think it is to access the healthcare services that you need? Please answer this " "question on a 1 − 5 scale, where 1 represents ”very easy” and 5 represents ”very difficult”", choices=[[1, 'Very easy'], [2, 'Somewhat easy'], [3, 'Neither easy nor difficult'], [4, 'Somewhat difficult'], [5, 'Very difficult'] ] ) past_mammogram = models.IntegerField( label="Have you ever had a mammogram in the past?", choices=[ [1, 'No'], [2, 'Maybe'], [3, 'Yes'] ] ) mammogram_behavior = models.IntegerField( label="When did you have your most recent mammogram", choices=[ [1, 'Past Month'], [2, 'Past Six Months'], [3, 'Past Year'], [4, 'Past Two Years'], [5, 'Past Five Years'], [6, 'Earlier than Five Years ago'], [7, "Can't Remember"] ] ) ha1 = models.IntegerField( label="Are you concerned that you might have a serious illness or disease that doctors have not found?", choices=[[1, 'Never'], [2, 'Occasionally'], [3, 'Much of my time'], [4, 'Most of my time'] ] ) ha2 = models.IntegerField( label="How much time do you spend worrying about your health?", choices=[[1, 'Never'], [2, 'Occasionally'], [3, 'Much of my time'], [4, 'Most of my time'] ] ) ha3 = models.IntegerField( label="How often are you afraid that you have a serious illness?", choices=[[1, 'Never'], [2, 'Occasionally'], [3, 'Much of my time'], [4, 'Most of my time'] ] ) ha4 = models.IntegerField( label="How relieved do you feel when a doctor tells you there is nothing wrong?", choices=[[1, 'Initially relieved'], [2, 'Initially relieved, worries return later, and eventually relieved'], [3, 'Initially relieved, but worries always return'], [4, 'Not relieved'] ] ) ha5 = models.IntegerField( label="I have difficulty taking my mind off things about my health.", choices=[[1, 'Not at all'], [2, 'A little bit'], [3, 'Quite a lot'], [4, 'Very much'] ] ) numeracy1 = models.IntegerField( label="Suppose this bowl has 10 white balls and no red balls. You will be asked to draw one ball without " "looking. On a scale from 0 percent to 100 percent, what is the percent chance that the ball " "you draw is red?", min=0, max=100, ) numeracy2 = models.IntegerField( label="Suppose that the bowl has 7 white balls and 3 red balls. You will be asked to draw one ball without " "looking. On a scale from 0 percent to 100 percent, what is the percent chance that the ball you draw " "is white?", min=0, max=100, ) numeracy3 = models.IntegerField( label="Imagine that the weather report tells you that the chance it will rain tomorrow is 70%. Assuming the " "weather report accurately reports the chance of rain and on a scale from 0 percent to 100 percent, what " "is the chance it will NOT rain tomorrow?", min=0, max=100, ) numeracy4 = models.IntegerField( label="Imagine that whether it rains in your town and whether it rains in New York City are unrelated. " "The chance that it will rain in your town tomorrow is 50%. The chance that it will rain in New York " "City is also 50%. On a scale from 0 percent to 100 percent, what is the chance that it will rain both " "in your town and in New York City tomorrow?", min=0, max=100, ) risk_preference = models.FloatField( label="Suppose in a lottery game, the possibility to win $100 is 10%, then how much would you pay at most " "to buy a lottery ticket? ($)", min=0, max=999, blank=True, initial=None ) employment = models.IntegerField( label="Are you currently employed?", choices=[[1, 'Yes, full-time'], [2, 'Yes, part-time'], [0, 'No']] ) employment_sector = models.IntegerField( label="Which of the following best describes your current employment?", choices=[[1, 'For profit company or organization'], [2, 'Non-profit organization (including tax-exempt and charitable organizations)'], [3, 'Local government (for example: city or county school district)'], [4, 'State government (including state colleges)'], [5, 'Active Duty US Armed Forces or Commissioned Corps'], [6, 'Federal government civilian employee'], [7, 'Owner of Non-incorporated business, professional practice or farm'], [8, 'Owner of incorporated business, professional practice or farm'], [9, 'Worked without pay in a for-profit family business for 15 hours or more per week'] ] ) paid_sick_leave_avail = models.IntegerField( label="Do you have access to paid sick leave benefits?", choices=[[1, 'Yes'], [0, 'No'], [2, "Don't know"]] ) health_insurance_co = models.IntegerField( label="Are you currently covered by any kind of health insurance?", choices=[[1, 'Yes'], [0, 'No'], [2, "Don't know"]] ) paid_sick_leave2 = models.IntegerField( label="During the past month, were there times when you were sick and " "needed to take off from work but COULD OR DID NOT?", choices=[[1, 'Yes'], [0, 'No'], [2, "Don't know"]] ) paid_sick_leave3 = models.IntegerField( label=" Imagine your employer would provide you with 8 days of paid sick leave per year and you could use it " "for health care visits.Do you think that would make it “much more likely” that you would get a " "mammogram in the next year?", choices=[[1, 'Yes'], [0, 'No'], [2, "Don't know"]] ) paid_sick_leave4 = models.IntegerField( label="Have you ever used a half or full paid sick day to get a mammogram or other preventive " "cancer screenings.", choices=[[1, 'Yes'], [0, 'No'], [2, "Don't know"]] ) mammogram_frequency = models.IntegerField( label="How many mammograms have you gotten in the past two years?", choices=[[0, "0"], [1, '1'], [2, '2'], [3, "3"], [4, "4 or more"] ] ) dependent = models.IntegerField( label="How many dependents do you have?", choices=[[1, '1-2'], [0, 'None'], [2, "3-4"], [3, 'More than 4'], [4, 'Prefer not to say']] )