from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) import random author = 'Your name here' doc = """ Your app description """ def make_field(label): return models.IntegerField( choices=[ [1, 'Strongly disagree'], [2, 'Disagree'], [3, 'Somewhat disagree'], [4, 'Neither agree nor disagree'], [5, 'Somewhat agree'], [6, 'Agree'], [7, 'Strongly agree'], ], label=label, widget=widgets.RadioSelect ) class Constants(BaseConstants): name_in_url = 'survey' players_per_group = None num_rounds = 1 bonus = c(10) multiplier = 2.5 states = [ 'Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California', 'Colorado', 'Connecticut', 'Delaware', 'Florida', 'Georgia', 'Hawaii', 'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Louisiana', 'Maine', 'Maryland', 'Massachusetts', 'Michigan', 'Minnesota', 'Mississippi', 'Missouri', 'Montana', 'Nebraska', 'Nevada', 'New Hampshire', 'New Jersey', 'New Mexico', 'New York', 'North Carolina', 'North Dakota', 'Ohio', 'Oklahoma', 'Oregon', 'Pennsylvania', 'Rhode Island', 'South Carolina', 'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont', 'Virginia', 'Washington', 'West Virginia', 'Wisconsin', 'Wyoming', ] tv = [ 'I do not read or watch any news about Covid-19', 'Less than 30 minutes a day', 'Between 30 minutes to 1 hour', '1 to 2 hours', '2 to 4 hours', 'More than 4 hours' ] knowledge = [ 'Far above average', 'Above average', 'Average', 'Below average', 'Far below average' ] class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): describe=models.LongStringField(label='Please briefly describe how did you make you decisions in this study') comments = models.LongStringField(label='Please leave any questions and comments with regard the study, if you do not have any comments please type pass.') risk = models.IntegerField( min=0, ) risk_payoff = models.CurrencyField() prob_payoff = models.CurrencyField() def risk_max(self): return self.session.config['risk'] prob1 = models.IntegerField( choices=[[1, '1/10'], [2, '1/6'], [3, '1/3'], [4, '1/2'], [5, '1']], label='What is the chance that if you roll a fair six-sided die and it comes up 6?', widget=widgets.RadioSelect ) prob2 = models.IntegerField( choices=[[1, '1/36'], [2, '1/18'], [3, '1/12'], [4, '1/3'], [5, '1/2']], label='What is the chance that if you roll two six-sided dice and they both come up 6?', widget=widgets.RadioSelect ) prob3 = models.IntegerField( choices=[[1, '1/36'], [2, '1/18'], [3, '1/12'], [4, '1/3'], [5, '1/2']], label='What is the chance that if you roll two six-sided dice and one is a 1 and the other is 6?', widget=widgets.RadioSelect ) age = models.IntegerField(min=18, label='What is your age in years?') gender = models.IntegerField( choices=[[1, 'Male'], [2, 'Female'], [3, 'Other'], [-1, 'Prefer not to say']], label='Which gender do you identify with?', widget=widgets.RadioSelect ) education = models.IntegerField( choices=[[1, 'Less than high school degree'], [2, 'High school degree or equivalent (GED)'], [3, 'Some college but no degree'], [4, 'Associate degree'], [5, 'Bachelor’s degree'], [6, 'Graduate degree'], [-1, 'Prefer not to say'], ], label='What is the highest level of school you have completed or the highest degree you have received?', widget=widgets.RadioSelect ) income = models.IntegerField( choices=[ [1, 'Less than $20,000'], [2, '$20,000 to $29,999'], [3, '$30,000 to $39,999'], [4, '$40,000 to $49,999'], [5, '$50,000 to $59,999'], [6, '$60,000 to $69,999'], [7, '$70,000 to $79,999'], [8, '$80,000 to $89,999'], [9, '$90,000 to $99,999'], [10, '$100,000 to $149,999'], [11, '$150,000 or more'], [-1, 'Prefer not to say'] ], label='What is your approximate annual household income?' ) dependent = models.BooleanField(widget=widgets.RadioSelect, label='Do you have any dependents under 18?') old_dependent = models.BooleanField(widget=widgets.RadioSelect, label='Do you currently take care of any elderly ' 'relative(s)?') english = models.BooleanField(widget=widgets.RadioSelect, label='Is English your first language?') race = models.IntegerField( choices=[ [1, 'White / Caucasian'], [2, 'Black or African American'], [3, 'Hispanic'], [4, 'Asian / pacific islander'], [5, 'American Indian'], [6, 'Multiple ethnicity / other'], [-1, 'Prefer not to say'] ], label='Which race/ethnicity best describes you?' ) party_affiliation = models.IntegerField( choices=[ [1, 'Republican'], [2, 'Democrat'], [3, 'Independent'], [4, 'Other'] ], label='Generally speaking, do you usually think of yourself as a Republican, a Democrat, an independent, or ' 'other?' ) state = models.IntegerField( choices=[[i + 1, Constants.states[i]] for i in range(len(Constants.states))], label='Which state do you currently reside in?' ) tv = models.IntegerField( choices=[[i + 1, Constants.tv[i]] for i in range(len(Constants.tv))], label='How much time do you spend on average reading or watching the news about Covid-19 per day?' ) knowledge = models.IntegerField( choices=[[i + 1, Constants.knowledge[i]] for i in range(len(Constants.knowledge))], label='How knowledgeable are you about Covid-19? ' ) info_state = make_field('The State government provides accurate information about Covid-19.') info_fed = make_field('The Federal government provides accurate information about Covid-19.') timely_state = make_field('The State government provides timely information about Covid-19. ') timely_fed = make_field('The Federal government provides timely information about Covid-19. ') timely_lockdown = make_field('The lockdown in your area started in a timely manner. ') appropriate_lockdown = make_field('Lock-down is an appropriate measure to control the spread of Covid-19.') long_lockdown = make_field('The lockdown in your area went on/is too long.') strict_lockdown = make_field('In your area, the lockdown is/was too strict. ') enforce_lockdown = make_field('In your area the lockdown was properly enforced.') def set_bonus_risk(self): num = random.randint(0, 100) # print('The random number is', num) if num > 2/3 * 100: payoff = round(self.session.config['risk'] - self.risk + 2.5 * float(self.risk)) self.risk_payoff = c(payoff) # print('my additional payoff is', self.payoff) else: self.risk_payoff = c(self.session.config['risk'] - self.risk) def set_bonus_prob(self): self.prob_payoff = Constants.bonus if self.prob1 == 2 else c(0) self.prob_payoff += Constants.bonus if self.prob2 == 1 else c(0) self.prob_payoff += Constants.bonus if self.prob3 == 2 else c(0)