from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) import random as random import itertools import json author = 'Your name here' doc = """ Post survey """ def load_countries(): with open(f'survey/static/survey/countries.json', 'r') as read_file: countries = json.load(read_file) return countries class Constants(BaseConstants): name_in_url = '13Gskwew98' players_per_group = None num_rounds = 1 task = 'Survey' production_profile = ['Linear','Convex'] # Load a list of all countries for the questionnaire countries = load_countries() likert_scale_agree = [(1, 'I completely disagree'), (2, 'I somewhat disagree'), (3, 'Neither agree nor disagree'), (4, 'I somewhat agree'), (5, 'I completely agree')] class Subsession(BaseSubsession): def creating_session(self): ##### This code is for obtaining a balanced session ############ task_profiles = Constants.production_profile.copy() # shuffle the list random.shuffle(task_profiles) # make a cycle out of the shuffled list profiles = itertools.cycle(task_profiles) for p in self.get_players(): # Establishes task ordering & Incentives for Math Task if self.round_number == 1: try: p.participant.vars['production_profile'] except KeyError: #p.participant.vars['task_treatment'] = random.choice(Constants.task_treatment) p.participant.vars['production_profile'] = next(profiles) p.task = Constants.task p.production_profile = p.participant.vars['production_profile'] class Group(BaseGroup): pass class Player(BasePlayer): # Task task = models.StringField() # Production function type production_profile = models.StringField() ###### Questionnaire form fields ########### q_no_social_media_accounts = models.PositiveIntegerField(label="How many different social media accounts do you have? (e.g. Facebook, Instagram, X, etc.)", choices=range(9), initial=None) q_social_media_time = models.StringField(initial=None, label="How much time do you spend on social media per day?", choices=['Less than 15 minutes per day', 'Between 15 and 30 minutes per day', 'Between 30 minutes and 1 hour per day', 'Between 1 and 2 hours per day', 'More than 2 hours per day'], widget=widgets.RadioSelect() ) q_subj_time_management = models.PositiveIntegerField(choices=Constants.likert_scale_agree, label='Generally, I am good at managing my time at work/studying.', widget=widgets.RadioSelectHorizontal()) q_subj_time_on_phone = models.PositiveIntegerField(choices=Constants.likert_scale_agree, label='I often spend more time on my phone than I would like to.', widget=widgets.RadioSelectHorizontal()) q_use_tools = models.BooleanField(choices=[[True, 'Yes'], [False, 'No']], label='Did you use any tools during the study that helped you solve the math task or the code task?', widget=widgets.RadioSelectHorizontal()) q_which_tools = models.LongStringField(blank=True, label='If yes, please explain briefly which tools you used and how you used them:') q_gender = models.StringField(blank=True,label='What is your gender?', widget=widgets.RadioSelectHorizontal, choices=['Female', 'Male', 'Other', 'Prefer not to say']) q_age = models.IntegerField(blank=True,label='What is your current age in years?', min=16, max=130) q_country = models.StringField(blank=True,label='What is your country of residence?', choices=Constants.countries) q_degree = models.CharField(blank=True,initial=None, choices=[ """Master's degree or higher""", """Bachelor's degree""", 'High school diploma or equivalent','No degree'], label='What is the highest level of education you have completed?', widget=widgets.RadioSelect()) # Time Spent Intro_time_spent = models.FloatField(blank=True) Questions_1_time_spent = models.FloatField(blank=True) Questions_2_time_spent = models.FloatField(blank=True) Procedural_Qs_time_spent = models.FloatField(blank=True) Demographics_time_spent = models.FloatField(blank=True) # Warnings Intro_warnings = models.IntegerField() Questions_1_warnings = models.IntegerField() Questions_2_warnings = models.IntegerField() Procedural_Qs_warnings = models.IntegerField() Demographics_warnings = models.IntegerField()