Skip to main content

trustformers_debug/environmental_monitor/
config.rs

1//! Configuration for environmental monitoring
2
3use serde::{Deserialize, Serialize};
4
5/// Configuration for environmental monitoring
6#[derive(Debug, Clone, Serialize, Deserialize)]
7pub struct EnvironmentalConfig {
8    /// Enable carbon footprint tracking
9    pub enable_carbon_tracking: bool,
10    /// Enable detailed energy monitoring
11    pub enable_energy_monitoring: bool,
12    /// Enable efficiency optimization recommendations
13    pub enable_efficiency_analysis: bool,
14    /// Enable sustainability reporting
15    pub enable_sustainability_reporting: bool,
16    /// Enable real-time environmental alerts
17    pub enable_environmental_alerts: bool,
18    /// Geographic region for carbon intensity calculations
19    pub region: String,
20    /// Carbon intensity override (gCO2/kWh) - use regional average if None
21    pub carbon_intensity_override: Option<f64>,
22    /// Energy price per kWh (USD)
23    pub energy_price_per_kwh: f64,
24    /// Monitoring interval (seconds)
25    pub monitoring_interval_secs: u64,
26    /// Carbon footprint alert threshold (kg CO2)
27    pub carbon_alert_threshold: f64,
28    /// Energy consumption alert threshold (kWh)
29    pub energy_alert_threshold: f64,
30    /// Include scope 2 emissions (electricity)
31    pub include_scope2_emissions: bool,
32    /// Include scope 3 emissions (infrastructure, manufacturing)
33    pub include_scope3_emissions: bool,
34}
35
36impl Default for EnvironmentalConfig {
37    fn default() -> Self {
38        Self {
39            enable_carbon_tracking: true,
40            enable_energy_monitoring: true,
41            enable_efficiency_analysis: true,
42            enable_sustainability_reporting: true,
43            enable_environmental_alerts: true,
44            region: "US-West".to_string(),
45            carbon_intensity_override: None,
46            energy_price_per_kwh: 0.12, // US average
47            monitoring_interval_secs: 60,
48            carbon_alert_threshold: 10.0,  // kg CO2
49            energy_alert_threshold: 100.0, // kWh
50            include_scope2_emissions: true,
51            include_scope3_emissions: false,
52        }
53    }
54}
55
56/// Regional configuration presets
57impl EnvironmentalConfig {
58    /// US West Coast configuration (low carbon intensity)
59    pub fn us_west() -> Self {
60        Self {
61            region: "US-West".to_string(),
62            carbon_intensity_override: Some(350.0), // gCO2/kWh
63            energy_price_per_kwh: 0.15,
64            ..Default::default()
65        }
66    }
67
68    /// US East Coast configuration (medium carbon intensity)
69    pub fn us_east() -> Self {
70        Self {
71            region: "US-East".to_string(),
72            carbon_intensity_override: Some(450.0), // gCO2/kWh
73            energy_price_per_kwh: 0.13,
74            ..Default::default()
75        }
76    }
77
78    /// European configuration (low carbon intensity)
79    pub fn europe() -> Self {
80        Self {
81            region: "EU".to_string(),
82            carbon_intensity_override: Some(300.0), // gCO2/kWh
83            energy_price_per_kwh: 0.20,
84            ..Default::default()
85        }
86    }
87
88    /// Asia-Pacific configuration (high carbon intensity)
89    pub fn asia_pacific() -> Self {
90        Self {
91            region: "APAC".to_string(),
92            carbon_intensity_override: Some(600.0), // gCO2/kWh
93            energy_price_per_kwh: 0.10,
94            ..Default::default()
95        }
96    }
97
98    /// High-precision monitoring configuration
99    pub fn high_precision() -> Self {
100        Self {
101            monitoring_interval_secs: 10,
102            enable_environmental_alerts: true,
103            carbon_alert_threshold: 1.0,
104            energy_alert_threshold: 10.0,
105            include_scope3_emissions: true,
106            ..Default::default()
107        }
108    }
109
110    /// Low-overhead monitoring configuration
111    pub fn low_overhead() -> Self {
112        Self {
113            monitoring_interval_secs: 300, // 5 minutes
114            enable_environmental_alerts: false,
115            enable_efficiency_analysis: false,
116            include_scope3_emissions: false,
117            ..Default::default()
118        }
119    }
120
121    /// Compliance monitoring configuration (detailed tracking)
122    pub fn compliance_focused() -> Self {
123        Self {
124            enable_carbon_tracking: true,
125            enable_energy_monitoring: true,
126            enable_efficiency_analysis: true,
127            enable_sustainability_reporting: true,
128            enable_environmental_alerts: true,
129            include_scope2_emissions: true,
130            include_scope3_emissions: true,
131            monitoring_interval_secs: 30,
132            ..Default::default()
133        }
134    }
135
136    /// Development environment configuration (minimal monitoring)
137    pub fn development() -> Self {
138        Self {
139            enable_carbon_tracking: false,
140            enable_energy_monitoring: true,
141            enable_efficiency_analysis: false,
142            enable_sustainability_reporting: false,
143            enable_environmental_alerts: false,
144            monitoring_interval_secs: 120,
145            ..Default::default()
146        }
147    }
148}
149
150#[cfg(test)]
151mod tests {
152    use super::*;
153
154    #[test]
155    fn test_default_config() {
156        let config = EnvironmentalConfig::default();
157        assert!(config.enable_carbon_tracking);
158        assert!(config.enable_energy_monitoring);
159        assert_eq!(config.region, "US-West");
160        assert_eq!(config.monitoring_interval_secs, 60);
161    }
162
163    #[test]
164    fn test_regional_configs() {
165        let us_west = EnvironmentalConfig::us_west();
166        assert_eq!(us_west.region, "US-West");
167        assert_eq!(us_west.carbon_intensity_override, Some(350.0));
168
169        let europe = EnvironmentalConfig::europe();
170        assert_eq!(europe.region, "EU");
171        assert_eq!(europe.carbon_intensity_override, Some(300.0));
172    }
173
174    #[test]
175    fn test_specialized_configs() {
176        let high_precision = EnvironmentalConfig::high_precision();
177        assert_eq!(high_precision.monitoring_interval_secs, 10);
178        assert!(high_precision.include_scope3_emissions);
179
180        let low_overhead = EnvironmentalConfig::low_overhead();
181        assert_eq!(low_overhead.monitoring_interval_secs, 300);
182        assert!(!low_overhead.enable_environmental_alerts);
183
184        let development = EnvironmentalConfig::development();
185        assert!(!development.enable_carbon_tracking);
186        assert!(!development.enable_sustainability_reporting);
187    }
188}