from otree.api import * import random doc = '' class C(BaseConstants): NAME_IN_URL = 'presurvey' PLAYERS_PER_GROUP = None NUM_ROUNDS = 1 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): email = models.StringField( label="Please enter your email address so we can send your gift card:", blank=False ) gender = models.StringField( choices=['Male', 'Female', 'Non-binary', 'Prefer not to say'], label='What is your gender?', widget=widgets.RadioSelect ) major = models.StringField(label='What is your major?') year_of_study = models.StringField( choices=['1st Year', '2nd Year', '3rd Year', '4th Year', 'Graduate', 'Other'], label='What year of study are you?', widget=widgets.RadioSelect ) trust_digital_tools = models.IntegerField( choices=[1, 2, 3, 4, 5], label='How much do you trust digital tools in decision making? (1 = Not at all, 5 = Completely)', widget=widgets.RadioSelectHorizontal ) decision_confidence = models.IntegerField( choices=[1, 2, 3, 4, 5], label='How confident are you in your decision-making abilities? (1 = Not confident, 5 = Very confident)', widget=widgets.RadioSelectHorizontal ) newsvendor_knowledge = models.IntegerField( choices=[1, 2, 3, 4, 5], label='How familiar are you with the newsvendor model? (1 = Not familiar, 5 = Very familiar)', widget=widgets.RadioSelectHorizontal ) digital_tool_usage = models.IntegerField( choices=[1, 2, 3, 4, 5], label='How often do you use digital tools (e.g., apps, software) for decision-making in your studies or daily life? (1 = Never, 5 = Very frequently)', widget=widgets.RadioSelectHorizontal ) comfort_with_advanced_tools = models.IntegerField( choices=[1, 2, 3, 4, 5], label='How comfortable are you with using advanced digital tools (e.g., simulations, forecasting tools) in making decisions? (1 = Not comfortable, 5 = Very comfortable)', widget=widgets.RadioSelectHorizontal ) decision_making_frequency = models.IntegerField( choices=[1, 2, 3, 4, 5], label='In your studies, how much decision-making do you do regarding problems or case studies? (1 = None, 5 = A lot)', widget=widgets.RadioSelectHorizontal ) academic_digital_tools = models.LongStringField( label='What types of digital tools have you used in academic settings? (Excel, forecasting software, decision-support apps, ChatGPT and other AI models, etc.) (List multiple tools separated by commas)' ) decision_making_effectiveness = models.IntegerField( choices=[1, 2, 3, 4, 5], label='How would you rate the effectiveness of your current decision-making process in assignments or projects? (1 = Very ineffective, 5 = Very effective)', widget=widgets.RadioSelectHorizontal ) formal_training = models.BooleanField( choices=[[True, 'Yes'], [False, 'No']], label='Have you received any formal training on using digital tools for decision-making in your courses?' ) # Boolean field to identify smart groups based on initial newsvendor knowledge is_smart_group = models.BooleanField(initial=False) class Info(Page): form_model = 'player' form_fields = [ 'gender', 'major', 'year_of_study', 'trust_digital_tools', 'decision_confidence', 'newsvendor_knowledge', 'digital_tool_usage', 'comfort_with_advanced_tools', 'decision_making_frequency', 'academic_digital_tools', 'decision_making_effectiveness', 'formal_training' ] @staticmethod def before_next_page(player: Player, timeout_happened): # Set smart group classification based on initial newsvendor knowledge (over 3 = smart) player.is_smart_group = player.newsvendor_knowledge > 3 # Store only the presurvey knowledge & smart flag (avoid duplicate keys) player.participant.vars['presurvey_newsvendor_knowledge'] = player.newsvendor_knowledge player.participant.vars['is_smart_group'] = player.is_smart_group # Assign into subgroups A/B within smart vs non-smart cohorts subgroup = random.choice(['A', 'B']) segment = f"{'smart' if player.is_smart_group else 'nonsmart'}_{subgroup}" player.participant.vars['subgroup'] = subgroup player.participant.vars['segment'] = segment # Randomly assign a digital tool count (1-4) with equal probability across the session # Implement round-robin cycling to keep groups balanced within a session. sess = player.session cohort_key = 'smart' if player.is_smart_group else 'nonsmart' cycle_key = f'tool_cycle_{cohort_key}' index_key = f'tool_index_{cohort_key}' if cycle_key not in sess.vars: sess.vars[cycle_key] = [1, 2, 3, 4] random.shuffle(sess.vars[cycle_key]) sess.vars[index_key] = 0 idx = sess.vars[index_key] tool_count = sess.vars[cycle_key][idx] sess.vars[index_key] = (idx + 1) % len(sess.vars[cycle_key]) player.participant.vars['tool_count'] = tool_count # Debugging output to ensure the value is saved correctly print(f"Debug: presurvey_newsvendor_knowledge saved as {player.newsvendor_knowledge}") print(f"Debug: is_smart_group set to {player.is_smart_group}") print(f"Debug: subgroup assigned {subgroup}, segment {segment}") print(f"Debug: tool_count assigned {player.participant.vars['tool_count']}") class NewsExplained(Page): # Reuse the existing template from the intro app template_name = 'intro/NewsExplained.html' @staticmethod def is_displayed(player: Player): # Show only to participants NOT in the smart group return not player.is_smart_group page_sequence = [Info, NewsExplained]