from otree.api import Bot import random from . import __init__ as app class PlayerBot(Bot): def play_round(self): # Randomized answers for required presurvey fields data = dict( gender=random.choice(['Male', 'Female', 'Non-binary', 'Prefer not to say']), major=random.choice(['Business', 'Engineering', 'Economics', 'Math', 'Other']), year_of_study=random.choice(['1st Year', '2nd Year', '3rd Year', '4th Year', 'Graduate', 'Other']), trust_digital_tools=random.randint(1, 5), decision_confidence=random.randint(1, 5), newsvendor_knowledge=random.randint(1, 5), digital_tool_usage=random.randint(1, 5), comfort_with_advanced_tools=random.randint(1, 5), decision_making_frequency=random.randint(1, 5), academic_digital_tools='Excel, forecasting, ChatGPT', decision_making_effectiveness=random.randint(1, 5), formal_training=random.choice([True, False]), ) yield app.Info, data # This page only shows for non-smart participants; harmless to yield unconditionally yield app.NewsExplained # Aggregate into session vars for a summary at the end of the session pvars = self.player.participant.vars cohort = 'Experienced' if pvars.get('is_smart_group') else 'Standard' tool_count = pvars.get('tool_count') sess = self.player.session if 'tool_dist' not in sess.vars: sess.vars['tool_dist'] = { 'Experienced': {1: 0, 2: 0, 3: 0, 4: 0}, 'Standard': {1: 0, 2: 0, 3: 0, 4: 0}, } sess.vars['cohort_totals'] = {'Experienced': 0, 'Standard': 0} if tool_count in (1, 2, 3, 4): sess.vars['tool_dist'][cohort][tool_count] += 1 sess.vars['cohort_totals'][cohort] += 1 # If this is the last participant in the session, print the summary last_id = len(self.player.get_others_in_subsession()) + 1 if self.player.id_in_subsession == last_id: dist = sess.vars['tool_dist'] totals = sess.vars['cohort_totals'] print('\n=== Bot Simulation: Tool Count Distribution by Cohort ===') for cohort_name in ['Experienced', 'Standard']: total = totals.get(cohort_name, 0) print(f"\n{cohort_name} (n={total})") for tc in [1, 2, 3, 4]: count = dist[cohort_name].get(tc, 0) pct = (count / total * 100) if total else 0 print(f" {tc} tools: {count:5d} ({pct:5.1f}%)")