quantrs2_device/performance_analytics_dashboard/
config.rs

1//! Configuration Management for Performance Analytics Dashboard
2//!
3//! This module contains all configuration structures and types for the dashboard,
4//! including analytics, visualization, alerting, and export configurations.
5
6use serde::{Deserialize, Serialize};
7use std::collections::HashMap;
8use std::time::Duration;
9
10/// Configuration for the Performance Analytics Dashboard
11#[derive(Debug, Clone)]
12pub struct PerformanceDashboardConfig {
13    /// Enable real-time monitoring
14    pub enable_realtime_monitoring: bool,
15    /// Data collection interval in seconds
16    pub collection_interval: u64,
17    /// Historical data retention in days
18    pub retention_days: u32,
19    /// Dashboard refresh rate in seconds
20    pub dashboard_refresh_rate: u64,
21    /// Analytics configuration
22    pub analytics_config: AnalyticsConfig,
23    /// Visualization configuration
24    pub visualization_config: VisualizationConfig,
25    /// Alert configuration
26    pub alert_config: AlertConfig,
27    /// Export configuration
28    pub export_config: ExportConfig,
29    /// Prediction configuration
30    pub prediction_config: PredictionConfig,
31}
32
33/// Advanced analytics configuration
34#[derive(Debug, Clone)]
35pub struct AnalyticsConfig {
36    /// Enable statistical analysis
37    pub enable_statistical_analysis: bool,
38    /// Enable trend analysis
39    pub enable_trend_analysis: bool,
40    /// Enable correlation analysis
41    pub enable_correlation_analysis: bool,
42    /// Enable anomaly detection
43    pub enable_anomaly_detection: bool,
44    /// Enable performance modeling
45    pub enable_performance_modeling: bool,
46    /// Statistical confidence level
47    pub confidence_level: f64,
48    /// Anomaly detection sensitivity
49    pub anomaly_sensitivity: f64,
50    /// Trend analysis window size
51    pub trend_window_size: usize,
52}
53
54/// Visualization configuration
55#[derive(Debug, Clone)]
56pub struct VisualizationConfig {
57    /// Enable interactive charts
58    pub enable_interactive_charts: bool,
59    /// Chart types to display
60    pub chart_types: Vec<ChartType>,
61    /// Dashboard layout
62    pub dashboard_layout: DashboardLayout,
63    /// Color scheme
64    pub color_scheme: ColorScheme,
65    /// Aggregation levels
66    pub aggregation_levels: Vec<AggregationLevel>,
67    /// Custom visualizations
68    pub custom_visualizations: Vec<CustomVisualization>,
69}
70
71/// Alert configuration
72#[derive(Debug, Clone)]
73pub struct AlertConfig {
74    /// Enable alerting
75    pub enable_alerts: bool,
76    /// Alert thresholds
77    pub alert_thresholds: HashMap<String, AlertThreshold>,
78    /// Notification channels
79    pub notification_channels: Vec<NotificationChannel>,
80    /// Alert suppression rules
81    pub suppression_rules: Vec<SuppressionRule>,
82    /// Escalation policies
83    pub escalation_policies: Vec<EscalationPolicy>,
84}
85
86/// Export configuration
87#[derive(Debug, Clone)]
88pub struct ExportConfig {
89    /// Enable data export
90    pub enable_export: bool,
91    /// Export formats
92    pub export_formats: Vec<ExportFormat>,
93    /// Automatic export schedule
94    pub auto_export_schedule: Option<ExportSchedule>,
95    /// Report templates
96    pub report_templates: Vec<ReportTemplate>,
97}
98
99/// Prediction configuration
100#[derive(Debug, Clone)]
101pub struct PredictionConfig {
102    /// Enable performance predictions
103    pub enable_predictions: bool,
104    /// Prediction horizon in hours
105    pub prediction_horizon_hours: u32,
106    /// Prediction models
107    pub prediction_models: Vec<PredictionModel>,
108    /// Prediction confidence threshold
109    pub confidence_threshold: f64,
110    /// Enable adaptive learning
111    pub enable_adaptive_learning: bool,
112}
113
114/// Chart types for visualization
115#[derive(Debug, Clone, PartialEq, Eq, Hash)]
116pub enum ChartType {
117    LineChart,
118    BarChart,
119    ScatterPlot,
120    HeatMap,
121    Histogram,
122    BoxPlot,
123    ViolinPlot,
124    Waterfall,
125    Gauge,
126    TreeMap,
127    Sankey,
128    Radar,
129    Candlestick,
130    Custom(String),
131}
132
133/// Dashboard layout options
134#[derive(Debug, Clone, PartialEq)]
135pub enum DashboardLayout {
136    Grid,
137    Fluid,
138    Tabbed,
139    Stacked,
140    Custom(String),
141}
142
143/// Color schemes
144#[derive(Debug, Clone, PartialEq)]
145pub enum ColorScheme {
146    Default,
147    Dark,
148    Light,
149    HighContrast,
150    Scientific,
151    Custom(Vec<String>),
152}
153
154/// Aggregation levels
155#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
156pub enum AggregationLevel {
157    RealTime,
158    Minute,
159    Hour,
160    Day,
161    Week,
162    Month,
163    Quarter,
164    Year,
165}
166
167/// Custom visualization definition
168#[derive(Debug, Clone)]
169pub struct CustomVisualization {
170    pub name: String,
171    pub visualization_type: String,
172    pub data_sources: Vec<String>,
173    pub configuration: HashMap<String, String>,
174    pub filters: Vec<VisualizationFilter>,
175}
176
177/// Visualization filter
178#[derive(Debug, Clone)]
179pub struct VisualizationFilter {
180    pub field: String,
181    pub operator: String,
182    pub value: String,
183}
184
185/// Alert threshold definition
186#[derive(Debug, Clone, Serialize, Deserialize)]
187pub struct AlertThreshold {
188    pub metric_name: String,
189    pub threshold_type: ThresholdType,
190    pub value: f64,
191    pub severity: AlertSeverity,
192    pub duration: Duration,
193    pub enabled: bool,
194}
195
196/// Threshold types
197#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
198pub enum ThresholdType {
199    GreaterThan,
200    LessThan,
201    Equal,
202    NotEqual,
203    PercentageChange,
204    StandardDeviation,
205    Custom(String),
206}
207
208/// Alert severity levels
209#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
210pub enum AlertSeverity {
211    Info,
212    Warning,
213    Error,
214    Critical,
215}
216
217/// Notification channels
218#[derive(Debug, Clone)]
219pub struct NotificationChannel {
220    pub channel_type: ChannelType,
221    pub configuration: HashMap<String, String>,
222    pub enabled: bool,
223    pub filters: Vec<NotificationFilter>,
224}
225
226/// Channel types for notifications
227#[derive(Debug, Clone, PartialEq, Eq, Hash)]
228pub enum ChannelType {
229    Email,
230    Slack,
231    SMS,
232    Webhook,
233    PagerDuty,
234    Discord,
235    Teams,
236    Custom(String),
237}
238
239/// Notification filter
240#[derive(Debug, Clone)]
241pub struct NotificationFilter {
242    pub filter_type: String,
243    pub condition: String,
244    pub value: String,
245}
246
247/// Alert suppression rules
248#[derive(Debug, Clone)]
249pub struct SuppressionRule {
250    pub rule_name: String,
251    pub conditions: Vec<SuppressionCondition>,
252    pub duration: Duration,
253    pub enabled: bool,
254}
255
256/// Suppression condition
257#[derive(Debug, Clone)]
258pub struct SuppressionCondition {
259    pub field: String,
260    pub operator: String,
261    pub value: String,
262}
263
264/// Escalation policies
265#[derive(Debug, Clone)]
266pub struct EscalationPolicy {
267    pub policy_name: String,
268    pub steps: Vec<EscalationStep>,
269    pub enabled: bool,
270}
271
272/// Escalation step
273#[derive(Debug, Clone)]
274pub struct EscalationStep {
275    pub step_number: usize,
276    pub delay: Duration,
277    pub notification_channels: Vec<String>,
278    pub action_type: EscalationActionType,
279}
280
281/// Escalation action types
282#[derive(Debug, Clone, PartialEq)]
283pub enum EscalationActionType {
284    Notify,
285    AutoRemediate,
286    CreateTicket,
287    CallOnDuty,
288    Custom(String),
289}
290
291/// Export formats
292#[derive(Debug, Clone, PartialEq)]
293pub enum ExportFormat {
294    JSON,
295    CSV,
296    Excel,
297    PDF,
298    PNG,
299    SVG,
300    HTML,
301    Custom(String),
302}
303
304/// Export schedule
305#[derive(Debug, Clone)]
306pub struct ExportSchedule {
307    pub frequency: ExportFrequency,
308    pub time_of_day: Option<chrono::NaiveTime>,
309    pub recipients: Vec<String>,
310    pub formats: Vec<ExportFormat>,
311}
312
313/// Export frequency
314#[derive(Debug, Clone, PartialEq)]
315pub enum ExportFrequency {
316    Hourly,
317    Daily,
318    Weekly,
319    Monthly,
320    Quarterly,
321    Custom(String),
322}
323
324/// Report templates
325#[derive(Debug, Clone)]
326pub struct ReportTemplate {
327    pub template_name: String,
328    pub template_type: ReportType,
329    pub sections: Vec<ReportSection>,
330    pub layout: ReportLayout,
331    pub enabled: bool,
332}
333
334/// Report types
335#[derive(Debug, Clone, PartialEq)]
336pub enum ReportType {
337    Executive,
338    Technical,
339    Operational,
340    Compliance,
341    Custom(String),
342}
343
344/// Report section
345#[derive(Debug, Clone)]
346pub struct ReportSection {
347    pub section_name: String,
348    pub section_type: ReportSectionType,
349    pub data_sources: Vec<String>,
350    pub charts: Vec<ChartType>,
351    pub order: usize,
352}
353
354/// Report section types
355#[derive(Debug, Clone, PartialEq)]
356pub enum ReportSectionType {
357    Summary,
358    Charts,
359    Tables,
360    Analysis,
361    Recommendations,
362    Custom(String),
363}
364
365/// Report layout
366#[derive(Debug, Clone, PartialEq)]
367pub enum ReportLayout {
368    Standard,
369    Compact,
370    Detailed,
371    Custom(String),
372}
373
374/// Prediction models
375#[derive(Debug, Clone, PartialEq)]
376pub enum PredictionModel {
377    LinearRegression,
378    ARIMA,
379    LSTM,
380    Prophet,
381    ExponentialSmoothing,
382    RandomForest,
383    GradientBoosting,
384    Custom(String),
385}
386
387impl Default for PerformanceDashboardConfig {
388    fn default() -> Self {
389        Self {
390            enable_realtime_monitoring: true,
391            collection_interval: 30,
392            retention_days: 90,
393            dashboard_refresh_rate: 5,
394            analytics_config: AnalyticsConfig {
395                enable_statistical_analysis: true,
396                enable_trend_analysis: true,
397                enable_correlation_analysis: true,
398                enable_anomaly_detection: true,
399                enable_performance_modeling: true,
400                confidence_level: 0.95,
401                anomaly_sensitivity: 0.05,
402                trend_window_size: 100,
403            },
404            visualization_config: VisualizationConfig {
405                enable_interactive_charts: true,
406                chart_types: vec![
407                    ChartType::LineChart,
408                    ChartType::BarChart,
409                    ChartType::HeatMap,
410                    ChartType::Gauge,
411                    ChartType::BoxPlot,
412                ],
413                dashboard_layout: DashboardLayout::Grid,
414                color_scheme: ColorScheme::Scientific,
415                aggregation_levels: vec![
416                    AggregationLevel::RealTime,
417                    AggregationLevel::Minute,
418                    AggregationLevel::Hour,
419                    AggregationLevel::Day,
420                ],
421                custom_visualizations: Vec::new(),
422            },
423            alert_config: AlertConfig {
424                enable_alerts: true,
425                alert_thresholds: [
426                    (
427                        "fidelity".to_string(),
428                        AlertThreshold {
429                            metric_name: "fidelity".to_string(),
430                            threshold_type: ThresholdType::LessThan,
431                            value: 0.9,
432                            severity: AlertSeverity::Warning,
433                            duration: Duration::from_secs(300),
434                            enabled: true,
435                        },
436                    ),
437                    (
438                        "error_rate".to_string(),
439                        AlertThreshold {
440                            metric_name: "error_rate".to_string(),
441                            threshold_type: ThresholdType::GreaterThan,
442                            value: 0.05,
443                            severity: AlertSeverity::Error,
444                            duration: Duration::from_secs(60),
445                            enabled: true,
446                        },
447                    ),
448                ]
449                .iter()
450                .cloned()
451                .collect(),
452                notification_channels: vec![NotificationChannel {
453                    channel_type: ChannelType::Email,
454                    configuration: [("recipients".to_string(), "admin@example.com".to_string())]
455                        .iter()
456                        .cloned()
457                        .collect(),
458                    enabled: true,
459                    filters: Vec::new(),
460                }],
461                suppression_rules: Vec::new(),
462                escalation_policies: Vec::new(),
463            },
464            export_config: ExportConfig {
465                enable_export: true,
466                export_formats: vec![ExportFormat::JSON, ExportFormat::CSV, ExportFormat::PDF],
467                auto_export_schedule: Some(ExportSchedule {
468                    frequency: ExportFrequency::Daily,
469                    time_of_day: Some(chrono::NaiveTime::from_hms_opt(9, 0, 0).unwrap()),
470                    recipients: vec!["reports@example.com".to_string()],
471                    formats: vec![ExportFormat::PDF],
472                }),
473                report_templates: vec![ReportTemplate {
474                    template_name: "Daily Performance Summary".to_string(),
475                    template_type: ReportType::Executive,
476                    sections: Vec::new(),
477                    layout: ReportLayout::Standard,
478                    enabled: true,
479                }],
480            },
481            prediction_config: PredictionConfig {
482                enable_predictions: true,
483                prediction_horizon_hours: 24,
484                prediction_models: vec![
485                    PredictionModel::ARIMA,
486                    PredictionModel::Prophet,
487                    PredictionModel::ExponentialSmoothing,
488                ],
489                confidence_threshold: 0.8,
490                enable_adaptive_learning: true,
491            },
492        }
493    }
494}
495
496impl AnalyticsConfig {
497    /// Create a basic analytics configuration
498    pub fn basic() -> Self {
499        Self {
500            enable_statistical_analysis: true,
501            enable_trend_analysis: false,
502            enable_correlation_analysis: false,
503            enable_anomaly_detection: true,
504            enable_performance_modeling: false,
505            confidence_level: 0.95,
506            anomaly_sensitivity: 0.1,
507            trend_window_size: 50,
508        }
509    }
510
511    /// Create a comprehensive analytics configuration
512    pub fn comprehensive() -> Self {
513        Self {
514            enable_statistical_analysis: true,
515            enable_trend_analysis: true,
516            enable_correlation_analysis: true,
517            enable_anomaly_detection: true,
518            enable_performance_modeling: true,
519            confidence_level: 0.99,
520            anomaly_sensitivity: 0.01,
521            trend_window_size: 200,
522        }
523    }
524}
525
526impl VisualizationConfig {
527    /// Create a minimal visualization configuration
528    pub fn minimal() -> Self {
529        Self {
530            enable_interactive_charts: false,
531            chart_types: vec![ChartType::LineChart, ChartType::BarChart],
532            dashboard_layout: DashboardLayout::Stacked,
533            color_scheme: ColorScheme::Default,
534            aggregation_levels: vec![AggregationLevel::Hour, AggregationLevel::Day],
535            custom_visualizations: Vec::new(),
536        }
537    }
538
539    /// Create a comprehensive visualization configuration
540    pub fn comprehensive() -> Self {
541        Self {
542            enable_interactive_charts: true,
543            chart_types: vec![
544                ChartType::LineChart,
545                ChartType::BarChart,
546                ChartType::ScatterPlot,
547                ChartType::HeatMap,
548                ChartType::Histogram,
549                ChartType::BoxPlot,
550                ChartType::ViolinPlot,
551                ChartType::Gauge,
552                ChartType::Radar,
553            ],
554            dashboard_layout: DashboardLayout::Grid,
555            color_scheme: ColorScheme::Scientific,
556            aggregation_levels: vec![
557                AggregationLevel::RealTime,
558                AggregationLevel::Minute,
559                AggregationLevel::Hour,
560                AggregationLevel::Day,
561                AggregationLevel::Week,
562                AggregationLevel::Month,
563            ],
564            custom_visualizations: Vec::new(),
565        }
566    }
567}
568
569impl AlertConfig {
570    /// Create a basic alert configuration with essential thresholds
571    pub fn basic() -> Self {
572        Self {
573            enable_alerts: true,
574            alert_thresholds: [(
575                "fidelity".to_string(),
576                AlertThreshold {
577                    metric_name: "fidelity".to_string(),
578                    threshold_type: ThresholdType::LessThan,
579                    value: 0.95,
580                    severity: AlertSeverity::Warning,
581                    duration: Duration::from_secs(300),
582                    enabled: true,
583                },
584            )]
585            .iter()
586            .cloned()
587            .collect(),
588            notification_channels: vec![NotificationChannel {
589                channel_type: ChannelType::Email,
590                configuration: HashMap::new(),
591                enabled: true,
592                filters: Vec::new(),
593            }],
594            suppression_rules: Vec::new(),
595            escalation_policies: Vec::new(),
596        }
597    }
598}