llm_analytics_hub/analytics/
mod.rs

1//! Analytics Engine
2//!
3//! Core analytics capabilities including aggregation, correlation, and prediction.
4
5pub mod aggregation;
6pub mod correlation;
7pub mod anomaly;
8pub mod prediction;
9
10pub use aggregation::AggregationEngine;
11pub use correlation::CorrelationEngine;
12pub use anomaly::AnomalyDetector;
13pub use prediction::PredictionEngine;
14
15use anyhow::Result;
16use std::sync::Arc;
17
18/// Analytics configuration
19#[derive(Debug, Clone)]
20pub struct AnalyticsConfig {
21    /// Enable real-time aggregation
22    pub enable_realtime_aggregation: bool,
23
24    /// Enable anomaly detection
25    pub enable_anomaly_detection: bool,
26
27    /// Enable predictive analytics
28    pub enable_prediction: bool,
29
30    /// Aggregation window sizes (in seconds)
31    pub aggregation_windows: Vec<u64>,
32
33    /// Anomaly detection sensitivity (0.0 - 1.0)
34    pub anomaly_sensitivity: f64,
35
36    /// Number of historical data points for prediction
37    pub prediction_history_size: usize,
38}
39
40impl Default for AnalyticsConfig {
41    fn default() -> Self {
42        Self {
43            enable_realtime_aggregation: true,
44            enable_anomaly_detection: true,
45            enable_prediction: true,
46            aggregation_windows: vec![60, 300, 900, 3600], // 1m, 5m, 15m, 1h
47            anomaly_sensitivity: 0.95,
48            prediction_history_size: 100,
49        }
50    }
51}
52
53/// Main analytics engine orchestrator
54pub struct AnalyticsEngine {
55    #[allow(dead_code)]
56    config: Arc<AnalyticsConfig>,
57    aggregation: AggregationEngine,
58    correlation: CorrelationEngine,
59    anomaly: AnomalyDetector,
60    prediction: PredictionEngine,
61}
62
63impl AnalyticsEngine {
64    /// Create a new analytics engine
65    pub async fn new(config: AnalyticsConfig) -> Result<Self> {
66        let config = Arc::new(config);
67
68        let aggregation = AggregationEngine::new(config.clone()).await?;
69        let correlation = CorrelationEngine::new();
70        let anomaly = AnomalyDetector::new(config.clone()).await?;
71        let prediction = PredictionEngine::new(config.clone()).await?;
72
73        Ok(Self {
74            config,
75            aggregation,
76            correlation,
77            anomaly,
78            prediction,
79        })
80    }
81
82    /// Get aggregation engine
83    pub fn aggregation(&self) -> &AggregationEngine {
84        &self.aggregation
85    }
86
87    /// Get correlation engine
88    pub fn correlation(&self) -> &CorrelationEngine {
89        &self.correlation
90    }
91
92    /// Get anomaly detector
93    pub fn anomaly(&self) -> &AnomalyDetector {
94        &self.anomaly
95    }
96
97    /// Get prediction engine
98    pub fn prediction(&self) -> &PredictionEngine {
99        &self.prediction
100    }
101}