import random from otree.api import ( Page, WaitPage, models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) doc = """ Survey """ class Constants(BaseConstants): name_in_url = 'my_survey' players_per_group = None num_rounds = 1 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): state = models.StringField(label='In what country(state) have you spent the most of your life?') age = models.IntegerField(label='What is your age?', min=18, max=125) male = models.IntegerField( choices=[[1, 'Male'], [0, 'Female'], [99, 'Prefer not to say']], label='What is your biological (born) gender?', widget=widgets.RadioSelectHorizontal, ) education = models.IntegerField( choices=[ [0, 'Less than high school'], [1, 'High school'], [2, 'Some college'], [3, 'College or higher'], ], label='What is the highest level of education you have completed?', widget=widgets.RadioSelectHorizontal, ) wage = models.IntegerField( min=0, max=1000000, label='What is the most recent wage (in US Dollars) you ever earned?' ) wagefreq = models.IntegerField( choices=[[1920, 'Yearly'], [160, 'Monthly'], [40, 'Weekly'], [8, 'Daily'], [1, 'Hourly']], label='The wage above is/was earned ...', widget=widgets.RadioSelectHorizontal, ) wagerate = models.FloatField() cig100 = models.IntegerField( choices=[[1, 'Yes'], [0, 'No'], [99, 'I have no idea']], label='Have you smoked 100 cigarettes (roughly 5 packs) of cigarettes or more in your life ?', widget=widgets.RadioSelectHorizontal, ) smoke = models.IntegerField( choices=[[4, 'Cigarettes & something else'], [3, 'Cigarettes/Cigars/Cigarillas/Other Combustible Tobacco'], [2, 'Only Electronic Cigarettes/Vape products'], [1, 'Nicotine Patch/Other smokeless tobacco'], [0, 'No tobacco at all']], label='Do you currently consume any tobacco ?', widget=widgets.RadioSelectHorizontal, ) smokefreq = models.IntegerField( choices=[[2, 'Daily'], [1, 'Occasionally'], [0, 'Never']], label='How frequently do you smoke nowadays ?', widget=widgets.RadioSelectHorizontal, ) smokeday = models.IntegerField( label='How many times per day do you smoke/vape ?', choices=[[4, 'Four times and more'], [3, 'Three times'], [2, 'Twice'], [1, 'Once'], [0, 'I do not smoke daily']], widget=widgets.RadioSelectHorizontal, ) smokelength = models.IntegerField( choices=[[5, 'More than 5 years ago'], [4, 'Few years ago'], [3, 'A year ago'], [2, 'Several months ago'], [1, 'Last month'], [0, 'Last week'], [99, 'Not ever']], label='When did you start smoking/vaping regularly?', widget=widgets.RadioSelectHorizontal, ) smokepast = models.IntegerField( choices=[[99, 'I currently smoke - this question does not apply to me'], [3, 'Cigarettes/Cigars/Cigarillas'], [2, 'Electronic Cigarettes/Vape products only'], [1, 'Nicotine Patch/Other smokeless tobacco'], [0, 'Nothing at all']], label='If you do not smoke now, did you use any tobacco in the past ?', widget=widgets.RadioSelectHorizontal, ) smokepastime = models.IntegerField( choices=[[99, 'I currently smoke - this question does not apply to me'], [5, 'More than 5 years'], [4, '5-3 years'], [3, '2-1 years'], [2, '12-7 months'], [1, '2-6 months'], [0, 'A month or less'], [99, 'Not ever']], label='If you smoked in the past, how long was it ?', widget=widgets.RadioSelectHorizontal, ) smokepastfreq = models.IntegerField( choices=[[99, 'I currently smoke - this question does not apply to me'], [2, 'Daily'], [1, 'Occasionally'], [0, 'Never']], label='How frequently did you smoke in the past ?', widget=widgets.RadioSelectHorizontal, ) worksmoke = models.IntegerField( choices=[[1, 'Yes'], [0, 'No'] , [99, 'I was never employed']], label='Does (or did) your employer allow smoking/vaping at work ?', widget=widgets.RadioSelectHorizontal, ) barsmoke = models.IntegerField( choices=[[1, 'Yes'], [0, 'No'] , [99, 'I never go to a bar/nightclub']], label='Is smoking/vaping allowed at the bar/nightclub you visit the most ?', widget=widgets.RadioSelectHorizontal, ) eatsmoke = models.IntegerField( choices=[[1, 'Yes'], [0, 'No'], [99, 'I never eat out']], label='Is smoking/vaping allowed at the restaurant/eatery you visit the most ?', widget=widgets.RadioSelectHorizontal, ) barpref = models.IntegerField( choices=[ [1, 'Yes'], [0, 'No'] ], widget=widgets.RadioSelectHorizontal, label='' ) workpref = models.IntegerField( choices=[ [1, 'Yes'], [0, 'No'] ], widget=widgets.RadioSelectHorizontal, label='' ) eatpref = models.IntegerField( choices=[ [1, 'Yes'], [0, 'No'] ], widget=widgets.RadioSelectHorizontal, label='' ) barfreq = models.IntegerField( choices=[[5, 'Daily'], [4, 'Few times a week'], [3, 'Once a week'], [2, 'Few times a month'], [1, 'Once a month'], [0, 'Few times a year'], [99, 'Not ever']], label='How frequently do you visit bars or nightclubs?', widget=widgets.RadioSelectHorizontal, ) eatfreq = models.IntegerField( choices=[[5, 'Daily'], [4, 'Few times a week'], [3, 'Once a week'], [2, 'Few times a month'], [1, 'Once a month'], [0, 'Few times a year'], [99, 'Not ever']], label='How frequently do you visit eateries/restaurants?', widget=widgets.RadioSelectHorizontal, ) taxi = models.IntegerField() ride = models.IntegerField() wagecut = models.FloatField() choicebar = models.IntegerField( choices=[[1, 'Taxi'], [0, 'Stay here'],], widget=widgets.RadioSelectHorizontal, label='' ) choiceeat = models.IntegerField( choices=[[1, 'Drive'], [0, 'Eat here']], widget=widgets.RadioSelectHorizontal, label='' ) choicework = models.IntegerField( choices=[[1, 'Yes'], [0, 'No']], widget=widgets.RadioSelectHorizontal, label='' ) # FUNCTIONS def creating_session(subsession): for p in subsession.get_players(): p.taxi = random.choice([10, 20, 30]) p.ride = random.choice([10, 20, 30]) # PAGES class Intro(Page): def is_displayed(player: Player): return player.round_number == 1 class Socdem(Page): def is_displayed(player: Player): return player.round_number == 1 form_model = 'player' form_fields = ['state', 'age', 'male', 'education', 'cig100', 'smoke', 'smokefreq', 'smokeday', 'smokelength', 'smokepast', 'smokepastime', 'smokepastfreq', 'wage', 'wagefreq', 'worksmoke', 'barfreq', 'eatfreq', 'barsmoke', 'eatsmoke', ] @staticmethod def before_next_page(p: Player, timeout_happened): p.wagerate = p.wage / p.wagefreq if p.wagerate > 20: p.wagecut = p.wagerate * random.choice([0.95, 0.85, 0.75]) else: p.wagecut = 20 * random.choice([0.95, 0.85, 0.75]) class ResultsWaitPage(WaitPage): pass class Smoke(Page): def is_displayed(player: Player): return player.round_number == 1 form_model = 'player' form_fields = ['workpref', 'barpref', 'eatpref'] class Tasks(Page): ## def is_displayed(player: Player): ## return player.round_number == 2 form_model = 'player' form_fields = ['choicework', 'choicebar', 'choiceeat'] page_sequence = [Intro, Socdem, Smoke, Tasks]