import time import logging from observability import logger as obs_logger from observability import components as obs_components from ..base import BaseAgent from typing import List, Dict, Any from ingestion.features import running_features logger = logging.getLogger(__name__) class FeatureEngineeringAgent(BaseAgent): """ Input: list of runs as returned by parser Output: a features dict with: - per_run summaries (pace_min_per_km, avg_hr) - time series arrays for charts - weekly aggregates (mileage) - consistency score (0-100) """ def run(self, runs: List[Dict[str, Any]]) -> Dict[str, Any]: with obs_logger.start_span("feature_engineering_agent.run", obs_components.AGENT): from ingestion.features import compute_features_batch from ingestion.weekly_features import aggregate_runs_by_week, compute_trends try: # 1. Basic summary and charts summary = running_features(runs) # 2. Detailed per-run features detailed_features = compute_features_batch(runs) return { "summary": summary, "detailed_features": detailed_features, "weekly_stats": {}, # Deprecated in-memory "trends": {}, # Deprecated in-memory } except Exception as e: logger.error(f"Feature engineering failed: {e}") raise