llm_analytics_hub/analytics/
mod.rs1pub 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#[derive(Debug, Clone)]
20pub struct AnalyticsConfig {
21 pub enable_realtime_aggregation: bool,
23
24 pub enable_anomaly_detection: bool,
26
27 pub enable_prediction: bool,
29
30 pub aggregation_windows: Vec<u64>,
32
33 pub anomaly_sensitivity: f64,
35
36 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], anomaly_sensitivity: 0.95,
48 prediction_history_size: 100,
49 }
50 }
51}
52
53pub 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 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 pub fn aggregation(&self) -> &AggregationEngine {
84 &self.aggregation
85 }
86
87 pub fn correlation(&self) -> &CorrelationEngine {
89 &self.correlation
90 }
91
92 pub fn anomaly(&self) -> &AnomalyDetector {
94 &self.anomaly
95 }
96
97 pub fn prediction(&self) -> &PredictionEngine {
99 &self.prediction
100 }
101}