from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) from django.forms import widgets as d_widgets import random import numpy as np from scipy.optimize import curve_fit doc = ''' This app collects demographic data and assesses financial literacy. ''' class Constants(BaseConstants): name_in_url = 'survey' players_per_group = None num_rounds = 1 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): risk_right=models.BooleanField() ret_right=models.BooleanField() perc_right=models.BooleanField() risk_tolerance=models.IntegerField() age = models.IntegerField( label='What is your age?', min=13, max=125) gender = models.StringField( choices=['Male', 'Female', 'Other/Prefer not to answer'], label='What is your gender?', widget=widgets.RadioSelect) education = models.StringField( choices=[ 'Less than high school diploma', 'High School Graduate', "Bachelor's degree (e.g. BA or BS)", "Master's Degree (e.g. MA, MEd, MS)", "Doctorate degree"], label='What is the highest degree or level of school you have completed?', widget=widgets.RadioSelect ) income = models.StringField( choices = [ "Less than $10,000", "$10k - $30k", "$30k - $50k", "$50k - $100k", "$100k - $150k", "Over $150k", "Prefer Not to Answer" ], label = "What is your household income?", widget=widgets.RadioSelect ) crt_ret = models.StringField( choices=['More than $102','Exactly $102','Less than $102', "Do not know, refuse to answer"], label=''' Suppose you had $100 in a savings account and the interest rate was 2% per year. After 5 years, how much do you think you would have in the account if you left the money to grow? ''', widget = widgets.RadioSelect ) crt_perc = models.StringField( choices=['more than','exactly the same as','less than','Do not know, refuse to answer'], label=''' Fill in the blank: Imagine that the interest rate on your savings account was 1% per year and inflation was 2% per year. After 1 year, you would be able to buy _____ today with the money in this account. ''', widget=widgets.RadioSelect ) crt_risk = models.StringField( choices=['True', 'False', "Do not know, refuse to answer"], label=''' Do you think that the following statement is true or false? "Buying a single company stock usually provides a safer return than a stock mutual fund."''', widget=widgets.RadioSelect ) def check_answers(self): if "False" in self.crt_risk: self.risk_right=True else: self.risk_right=False if "More" in self.crt_ret: self.ret_right=True else: self.ret_right=False if "less" in self.crt_perc: self.perc_right=True else: self.perc_right=False self.participant.vars["num_right"] = self.risk_right + self.ret_right + self.perc_right