use crate::analysis::types::BifurcationType;
use scirs2_core::ndarray::Array1;
use std::collections::{HashMap, VecDeque};
use std::sync::{Arc, Mutex};
#[derive(Debug)]
pub struct RealTimeBifurcationMonitor {
pub data_buffer: Arc<Mutex<VecDeque<Array1<f64>>>>,
pub prediction_models: Vec<super::neural_network::BifurcationPredictionNetwork>,
pub alert_system: AlertSystemConfig,
pub monitoring_config: MonitoringConfig,
pub performance_tracker: PerformanceTracker,
pub adaptive_thresholds: AdaptiveThresholdSystem,
}
#[derive(Debug, Clone, Default)]
pub struct AlertSystemConfig {
pub alert_thresholds: HashMap<BifurcationType, f64>,
pub escalation_levels: Vec<EscalationLevel>,
pub notification_methods: Vec<NotificationMethod>,
pub suppression_config: AlertSuppressionConfig,
}
#[derive(Debug, Clone)]
pub struct EscalationLevel {
pub level_name: String,
pub threshold: f64,
pub escalation_delay: std::time::Duration,
pub actions: Vec<AlertAction>,
}
#[derive(Debug, Clone)]
pub enum AlertAction {
LogToFile(String),
SendEmail(String),
SystemShutdown,
ExecuteScript(String),
UpdateModel,
}
#[derive(Debug, Clone)]
pub enum NotificationMethod {
Email {
recipients: Vec<String>,
smtp_config: String,
},
SMS {
phone_numbers: Vec<String>,
service_config: String,
},
Webhook {
url: String,
headers: HashMap<String, String>,
},
FileLog { log_path: String, format: LogFormat },
}
#[derive(Debug, Clone, Copy)]
pub enum LogFormat {
JSON,
CSV,
PlainText,
XML,
}
#[derive(Debug, Clone)]
pub struct AlertSuppressionConfig {
pub min_interval: std::time::Duration,
pub max_alerts_per_window: usize,
pub time_window: std::time::Duration,
pub maintenance_mode: bool,
}
#[derive(Debug, Clone)]
pub struct MonitoringConfig {
pub sampling_rate: f64,
pub buffer_size: usize,
pub update_frequency: f64,
pub ensemble_config: MonitoringEnsembleConfig,
pub preprocessing: super::preprocessing::PreprocessingPipeline,
}
#[derive(Debug, Clone)]
pub struct MonitoringEnsembleConfig {
pub use_ensemble: bool,
pub voting_strategy: VotingStrategy,
pub confidence_threshold: f64,
pub agreement_threshold: f64,
}
#[derive(Debug, Clone, Copy)]
pub enum VotingStrategy {
Majority,
Weighted,
ConfidenceBased,
Unanimous,
}
#[derive(Debug, Clone)]
pub struct PerformanceTracker {
pub latency_metrics: LatencyMetrics,
pub accuracy_metrics: AccuracyMetrics,
pub resource_metrics: ResourceMetrics,
pub alert_metrics: AlertMetrics,
}
#[derive(Debug, Clone)]
pub struct LatencyMetrics {
pub avg_prediction_latency: f64,
pub max_prediction_latency: f64,
pub p95_latency: f64,
pub processing_latency: f64,
}
#[derive(Debug, Clone)]
pub struct AccuracyMetrics {
pub true_positive_rate: f64,
pub false_positive_rate: f64,
pub precision: f64,
pub recall: f64,
pub f1_score: f64,
}
#[derive(Debug, Clone)]
pub struct ResourceMetrics {
pub cpu_usage: f64,
pub memory_usage: usize,
pub network_usage: f64,
pub disk_io: f64,
}
#[derive(Debug, Clone)]
pub struct AlertMetrics {
pub total_alerts: usize,
pub true_alerts: usize,
pub false_alerts: usize,
pub avg_response_time: f64,
}
#[derive(Debug, Clone)]
pub struct AdaptiveThresholdSystem {
pub current_thresholds: HashMap<BifurcationType, f64>,
pub adaptation_method: ThresholdAdaptationMethod,
pub feedback_mechanism: FeedbackMechanism,
pub performance_history: Vec<f64>,
}
#[derive(Debug, Clone, Copy)]
pub enum ThresholdAdaptationMethod {
Fixed,
Statistical,
MachineLearning,
FeedbackBased,
}
#[derive(Debug, Clone, Copy)]
pub enum FeedbackMechanism {
Manual,
Automated,
Hybrid,
}
impl Default for AlertSuppressionConfig {
fn default() -> Self {
Self {
min_interval: std::time::Duration::from_secs(60),
max_alerts_per_window: 10,
time_window: std::time::Duration::from_secs(3600),
maintenance_mode: false,
}
}
}
impl Default for AlertMetrics {
fn default() -> Self {
Self {
total_alerts: 0,
true_alerts: 0,
false_alerts: 0,
avg_response_time: 0.0,
}
}
}
impl Default for AdaptiveThresholdSystem {
fn default() -> Self {
Self {
current_thresholds: HashMap::new(),
adaptation_method: ThresholdAdaptationMethod::Statistical,
feedback_mechanism: FeedbackMechanism::Automated,
performance_history: Vec::new(),
}
}
}