from otree.api import * import random doc = """ This short experiment will require you to read and evaluate two short articles about popular science """ class C(BaseConstants): NAME_IN_URL = 'articlesurvey' PLAYERS_PER_GROUP = None NUM_ROUNDS = 1 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): age = models.IntegerField(label='What is your age?', min=15, max=100) gender = models.StringField( choices=[['Male', 'Male'], ['Female', 'Female'], ['Other', 'Other']], label='What is your gender?', widget=widgets.RadioSelect, ) degree = models.StringField( choices=[['School', 'School'], ['College', 'College'], ['Bachelor`s Degree', 'Bachelor`s degree'], ['Master`s degree', 'Master`s degree'], ['Doctorate (Ph.D.)', 'Doctorate (Ph.D.)'], ['Other', 'Other']], label='What is your highest degree?', widget=widgets.RadioSelect, ) science1 = models.StringField( choices=[['No', 'No'], ['Yes, I am a scientist', 'Yes, I am a scientist'], ['Yes, I work with popular science', 'Yes, I work with popular science'], ['Yes, other', 'Yes, other']], label='Is your career path related to science?*', widget=widgets.RadioSelect, ) science2 = models.StringField( choices=[['Daily, it is the part of my job', 'Daily, it is the part of my job'], ['Almost every day, for hobby/other reasons', 'Almost every day, for hobby/other reasons'], ['Frequently but definitely not every day', 'Frequently but definitely not every day'], ['Occasionally when something catches my interest', 'Occasionally when something catches my interest'], ['Rarely, I am not that interested', 'Rarely, I am not that interested']], label='How often do you purposely look for scientific news?', widget=widgets.RadioSelect, ) science3 = models.IntegerField( label="How confident are you in your ability to understand and critically evaluate scientific information?", widget=widgets.RadioSelect, choices=[1, 2, 3, 4, 5] ) sur_rate1 = models.IntegerField( label=''' From 1 to 10, how interesting was the first article to you?* ''', min=1, max=10 ) sur_rate12 = models.StringField( choices=[['Yes', 'Yes'], ['No', 'No']], label='Did you get to know something new from the first article?', widget=widgets.RadioSelect ) sur_rate21 = models.StringField( choices=[['Yes', 'Yes'], ['No', 'No']], label='Did you get to know something new from the second article?', widget=widgets.RadioSelect ) sur_rate2 = models.IntegerField( label=''' From 1 to 10, how interesting was the second article to you?* ''', min=1, max=10 ) sur_fungus_att = models.StringField( choices=[['Not informed', 'Not informed'], ['Somewhat informed', 'Somewhat informed'], ['Well informed', 'Well informed']], label='Before the survey how well were you informed about fungi biology?', widget=widgets.RadioSelect ) sur_fungus_att2 = models.StringField( choices=[['Up to 10 centimeters in diameter', 'Up to 10 centimeters in diameter'], ['Up to a meter in diameter', 'Up to a meter in diameter'], ['Around 10 meters in diameter', 'Around 10 meters in diameter'], ['Over 100 meters in diameter', 'Over 100 meters in diameter'], ['Around several square kilometers in diameter', 'Around several square kilometers in diameter']], label='How big can a fungus grow?', widget=widgets.RadioSelect ) sur_gmo_att = models.StringField( choices=[['Not informed', 'Not informed'], ['Somewhat informed', 'Somewhat informed'], ['Well informed', 'Well informed']], label='Before the survey how well were you informed about GM foods or organisms?', widget=widgets.RadioSelect ) sur_gmo_att2 = models.StringField( choices=[['Yes', 'Yes'], ['No', 'No']], label='Would you buy a fruit/vegetable if you know they were genetically modified?', widget=widgets.RadioSelect ) sur_gmo_att3 = models.StringField( choices=[['Extremely unsafe', 'Extremely unsafe'], ['Somewhat unsafe', 'Somewhat unsafe'], ['Somewhat safe', 'Somewhat safe'], ['Quite safe', 'Quite safe']], label='What is your perception of the safety of genetically modified organisms (GMOs) in food?', widget=widgets.RadioSelect ) sur_vacc_att = models.StringField( choices=[['It is an individual`s choice whether to get vaccinated or not', 'It is an individual`s choice whether to get vaccinated or not'], ['Getting vaccinated is a collective responsibility to protect public health', 'Getting vaccinated is a collective responsibility to protect public health'], ['Getting vaccinated is harmful for public health', 'Getting vaccinated is harmful for public health'], ['I am unsure or have no opinion on this matter', 'I am unsure or have no opinion on this matter']], label='How important do you believe vaccinations are for public health?', widget=widgets.RadioSelect ) def assign_a_group(player): participant = player.participant participant.group_assigned = random.choice(['Positive', 'Negative', 'Neutral']) # PAGES class Demographics(Page): form_model = 'player' form_fields = ['age', 'gender', 'degree', 'science1', 'science2', 'science3'] class Article(Page): @staticmethod def vars_for_template(player: Player): assign_a_group(player) # Assign the group to the participant group_assignment = player.participant.group_assigned if group_assignment == "Positive": html_content = "positive_content.html" elif group_assignment == "Negative": html_content = "negative_content.html" else: html_content = "neutral_content.html" return dict(html_content=html_content) class Article2(Page): @staticmethod def vars_for_template(player: Player): assign_a_group(player) # Assign the group to the participant group_assignment = player.participant.group_assigned if group_assignment == "Positive": html_content = "second_article.html" elif group_assignment == "Negative": html_content = "second_article.html" else: html_content = "second_article.html" return dict(html_content=html_content) class Reflection(Page): form_model = 'player' form_fields = ['sur_rate1', 'sur_rate12', 'sur_rate2', 'sur_rate21', 'sur_fungus_att', 'sur_fungus_att2', 'sur_gmo_att', 'sur_gmo_att2', 'sur_gmo_att3', 'sur_vacc_att'] class Disclaimer(Page): pass page_sequence = [Disclaimer, Demographics, Article, Article2, Reflection]