scirs2_integrate/analysis/ml_prediction/
monitoring.rs1use crate::analysis::types::BifurcationType;
7use scirs2_core::ndarray::Array1;
8use std::collections::{HashMap, VecDeque};
9use std::sync::{Arc, Mutex};
10
11#[derive(Debug)]
13pub struct RealTimeBifurcationMonitor {
14 pub data_buffer: Arc<Mutex<VecDeque<Array1<f64>>>>,
16 pub prediction_models: Vec<super::neural_network::BifurcationPredictionNetwork>,
18 pub alert_system: AlertSystemConfig,
20 pub monitoring_config: MonitoringConfig,
22 pub performance_tracker: PerformanceTracker,
24 pub adaptive_thresholds: AdaptiveThresholdSystem,
26}
27
28#[derive(Debug, Clone, Default)]
30pub struct AlertSystemConfig {
31 pub alert_thresholds: HashMap<BifurcationType, f64>,
33 pub escalation_levels: Vec<EscalationLevel>,
35 pub notification_methods: Vec<NotificationMethod>,
37 pub suppression_config: AlertSuppressionConfig,
39}
40
41#[derive(Debug, Clone)]
43pub struct EscalationLevel {
44 pub level_name: String,
46 pub threshold: f64,
48 pub escalation_delay: std::time::Duration,
50 pub actions: Vec<AlertAction>,
52}
53
54#[derive(Debug, Clone)]
56pub enum AlertAction {
57 LogToFile(String),
59 SendEmail(String),
61 SystemShutdown,
63 ExecuteScript(String),
65 UpdateModel,
67}
68
69#[derive(Debug, Clone)]
71pub enum NotificationMethod {
72 Email {
74 recipients: Vec<String>,
75 smtp_config: String,
76 },
77 SMS {
79 phone_numbers: Vec<String>,
80 service_config: String,
81 },
82 Webhook {
84 url: String,
85 headers: HashMap<String, String>,
86 },
87 FileLog { log_path: String, format: LogFormat },
89}
90
91#[derive(Debug, Clone, Copy)]
93pub enum LogFormat {
94 JSON,
95 CSV,
96 PlainText,
97 XML,
98}
99
100#[derive(Debug, Clone)]
102pub struct AlertSuppressionConfig {
103 pub min_interval: std::time::Duration,
105 pub max_alerts_per_window: usize,
107 pub time_window: std::time::Duration,
109 pub maintenance_mode: bool,
111}
112
113#[derive(Debug, Clone)]
115pub struct MonitoringConfig {
116 pub sampling_rate: f64,
118 pub buffer_size: usize,
120 pub update_frequency: f64,
122 pub ensemble_config: MonitoringEnsembleConfig,
124 pub preprocessing: super::preprocessing::PreprocessingPipeline,
126}
127
128#[derive(Debug, Clone)]
130pub struct MonitoringEnsembleConfig {
131 pub use_ensemble: bool,
133 pub voting_strategy: VotingStrategy,
135 pub confidence_threshold: f64,
137 pub agreement_threshold: f64,
139}
140
141#[derive(Debug, Clone, Copy)]
143pub enum VotingStrategy {
144 Majority,
146 Weighted,
148 ConfidenceBased,
150 Unanimous,
152}
153
154#[derive(Debug, Clone)]
156pub struct PerformanceTracker {
157 pub latency_metrics: LatencyMetrics,
159 pub accuracy_metrics: AccuracyMetrics,
161 pub resource_metrics: ResourceMetrics,
163 pub alert_metrics: AlertMetrics,
165}
166
167#[derive(Debug, Clone)]
169pub struct LatencyMetrics {
170 pub avg_prediction_latency: f64,
172 pub max_prediction_latency: f64,
174 pub p95_latency: f64,
176 pub processing_latency: f64,
178}
179
180#[derive(Debug, Clone)]
182pub struct AccuracyMetrics {
183 pub true_positive_rate: f64,
185 pub false_positive_rate: f64,
187 pub precision: f64,
189 pub recall: f64,
191 pub f1_score: f64,
193}
194
195#[derive(Debug, Clone)]
197pub struct ResourceMetrics {
198 pub cpu_usage: f64,
200 pub memory_usage: usize,
202 pub network_usage: f64,
204 pub disk_io: f64,
206}
207
208#[derive(Debug, Clone)]
210pub struct AlertMetrics {
211 pub total_alerts: usize,
213 pub true_alerts: usize,
215 pub false_alerts: usize,
217 pub avg_response_time: f64,
219}
220
221#[derive(Debug, Clone)]
223pub struct AdaptiveThresholdSystem {
224 pub current_thresholds: HashMap<BifurcationType, f64>,
226 pub adaptation_method: ThresholdAdaptationMethod,
228 pub feedback_mechanism: FeedbackMechanism,
230 pub performance_history: Vec<f64>,
232}
233
234#[derive(Debug, Clone, Copy)]
236pub enum ThresholdAdaptationMethod {
237 Fixed,
239 Statistical,
241 MachineLearning,
243 FeedbackBased,
245}
246
247#[derive(Debug, Clone, Copy)]
249pub enum FeedbackMechanism {
250 Manual,
252 Automated,
254 Hybrid,
256}
257
258impl Default for AlertSuppressionConfig {
259 fn default() -> Self {
260 Self {
261 min_interval: std::time::Duration::from_secs(60),
262 max_alerts_per_window: 10,
263 time_window: std::time::Duration::from_secs(3600),
264 maintenance_mode: false,
265 }
266 }
267}
268
269impl Default for AlertMetrics {
270 fn default() -> Self {
271 Self {
272 total_alerts: 0,
273 true_alerts: 0,
274 false_alerts: 0,
275 avg_response_time: 0.0,
276 }
277 }
278}
279
280impl Default for AdaptiveThresholdSystem {
281 fn default() -> Self {
282 Self {
283 current_thresholds: HashMap::new(),
284 adaptation_method: ThresholdAdaptationMethod::Statistical,
285 feedback_mechanism: FeedbackMechanism::Automated,
286 performance_history: Vec::new(),
287 }
288 }
289}