()
| 26 | |
| 27 | |
| 28 | def main() -> None: |
| 29 | parser = argparse.ArgumentParser(description="Simulate a small historical case with 2-3 sampled users.") |
| 30 | parser.add_argument("--start-date", type=str, default="20260301", help="Start date YYYYMMDD") |
| 31 | parser.add_argument("--end-date", type=str, default="20260310", help="End date YYYYMMDD") |
| 32 | parser.add_argument("--drift-probability", type=float, default=0.5, help="Drift probability") |
| 33 | parser.add_argument("--seed", type=int, default=42, help="Random seed") |
| 34 | parser.add_argument("--min-users", type=int, default=2, help="Minimum sampled users") |
| 35 | parser.add_argument("--max-users", type=int, default=3, help="Maximum sampled users") |
| 36 | parser.add_argument( |
| 37 | "--llm-model", |
| 38 | type=str, |
| 39 | default=os.environ.get("LLM_PARSER_OPENAI_MODEL", "gemini-3-flash-preview"), |
| 40 | help="LLM model label used in benchmark summaries", |
| 41 | ) |
| 42 | parser.add_argument("--embedding-model", type=str, default="Qwen/Qwen3-Embedding-8B", help="Embedding model label") |
| 43 | parser.add_argument("--sources", nargs="*", default=None, help="Paper sources collected each day") |
| 44 | parser.add_argument("--limit-per-source", type=int, default=None, help="Optional daily max papers per source") |
| 45 | parser.add_argument("--skip-paper-collection", action="store_true", help="Skip daily paper collection") |
| 46 | parser.add_argument("--skip-reading-reports", action="store_true", help="Skip reading report generation for recommendation-only case runs") |
| 47 | parser.add_argument("--show-count", type=int, default=sim.DEFAULT_SIMULATION_SHOW_COUNT, help="Displayed papers per episode after real-ranking fallback fill") |
| 48 | parser.add_argument("--output-dir", type=str, default=None, help="Output directory") |
| 49 | args = parser.parse_args() |
| 50 | |
| 51 | random.seed(args.seed) |
| 52 | sim.embedding_module._default_service = None |
| 53 | if hasattr(sim.reading_agent, "READING_REPORT_EVIDENCE_CACHE_ENABLED"): |
| 54 | sim.reading_agent.READING_REPORT_EVIDENCE_CACHE_ENABLED = False |
| 55 | sim._patch_real_usage_logging() |
| 56 | |
| 57 | start_date = datetime.strptime(args.start_date, "%Y%m%d") |
| 58 | end_date = datetime.strptime(args.end_date, "%Y%m%d") |
| 59 | |
| 60 | conn = sqlite3.connect(sim.DB_PATH) |
| 61 | users = sim.get_all_users(conn) |
| 62 | conn.close() |
| 63 | |
| 64 | if not users: |
| 65 | raise RuntimeError("No user profiles found in database.") |
| 66 | |
| 67 | sample_size = random.randint(args.min_users, args.max_users) |
| 68 | sampled_users = random.sample(users, min(sample_size, len(users))) |
| 69 | sampled_user_ids = {user["user_id"] for user in sampled_users} |
| 70 | |
| 71 | print(f"Case simulation from {start_date.date()} to {end_date.date()}") |
| 72 | print(f"Sampled users: {sorted(sampled_user_ids)}") |
| 73 | print(f"Drift probability: {args.drift_probability}") |
| 74 | print() |
| 75 | |
| 76 | checkfiles = sim.load_checkfiles(sim.DRIFT_CHECKFILES_DIR) |
| 77 | print(f"Loaded {len(checkfiles)} drift checkfiles") |
| 78 | drift_engine = sim.DriftEngine(checkfiles) |
| 79 | |
| 80 | output_dir = ( |
| 81 | Path(args.output_dir) |
| 82 | if args.output_dir |
| 83 | else PROJECT_ROOT / "data" / f"simulation_case_{args.start_date}_{args.end_date}" |
| 84 | ) |
| 85 | if not output_dir.is_absolute(): |
no test coverage detected