-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstation_manager.py
More file actions
62 lines (52 loc) · 2.27 KB
/
Copy pathstation_manager.py
File metadata and controls
62 lines (52 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from interruption_system import InterruptionSystem
import time
from contextlib import contextmanager
class StationManager:
def __init__(self):
self.stations = {}
def add_station(self, station_id: str, custom_config: dict = None):
"""Adds a new station to the system"""
system = InterruptionSystem(station_id)
if custom_config:
system.update_configuration(**custom_config)
self.stations[station_id] = system
print(f"✅ Station {station_id} added")
return system
@contextmanager
def run_all_stations(self):
"""Context manager for automatic station management"""
try:
self.start_all_stations()
yield self
finally:
self.stop_all_stations()
def start_all_stations(self):
"""Starts all stations"""
print("🌊 Starting all stations...")
for station_id, system in self.stations.items():
system.start_system()
time.sleep(0.5)
print(f"✅ {len(self.stations)} stations started")
def stop_all_stations(self):
"""Stops all stations"""
print("\n🛑 Stopping all stations...")
for station_id, system in self.stations.items():
system.stop_system()
print("✅ All stations stopped")
def show_general_summary(self):
"""Shows a summary of all stations"""
print("\n" + "="*70)
print("📊 GENERAL STATION SUMMARY")
print("="*70)
total_interruptions = 0
for station_id, system in self.stations.items():
state = system.get_system_state()
stats = state['statistics']
print(f"\n📍 Station: {station_id}")
print(f" State: {'🟢 Active' if state['running'] else '🔴 Inactive'}")
print(f" Total interruptions: {stats['total_interruptions']}")
print(f" ├─ Sensor failures: {stats['sensor_failure']}")
print(f" ├─ Extreme conditions: {stats['extreme_conditions']}")
total_interruptions += stats['total_interruptions']
print(f"\n🔢 SYSTEM TOTAL: {total_interruptions} interruptions")
print("="*70)