"""Print the full model_summary block the API will emit at the end of every detection that runs the iforest. Verifies every key the planning doc promises is populated and well-formed. """ import json import sys from pathlib import Path sys.path.insert(0, str(Path(__file__).parent)) from telecom_anomaly.core.detector import TelecomAnomalyDetector from telecom_anomaly.core.models import TelecomConfig CSV = ( r"C:\my_project\work\GH_Police\main project\backend" r"\telecom_anomaly_detection\data\strictly_cleaned_data" r"\591296805 calls (1)_strictly_cleaned.csv" ) cfg = TelecomConfig() det = TelecomAnomalyDetector(cfg) det.load_data([CSV]) # Cover all three modes. for label, kwargs in [ ("Rules-only", {"use_model": False, "run_rules": True}), ("AI-only", {"use_model": True, "run_rules": False}), ("Both", {"use_model": True, "run_rules": True}), ]: # Reset tracking between modes. det.anomalies = [] det.rows_with_anomalies = set() det.row_anomaly_map.clear() det.row_anomaly_reasons.clear() det.row_anomaly_attribution.clear() det.subscriber_anomalies.clear() det.detect_anomalies(**kwargs) stats = det.get_statistics() print(f"\n=== {label} ({kwargs}) ===") print(f"total_anomalies_detected: {stats.total_anomalies_detected}") print(f"anomaly_types : {stats.anomaly_types}") print(f"model_feature_drivers : {stats.model_feature_drivers}") print("model_summary:") print(json.dumps(stats.model_summary, indent=2, default=str))