Implement zone-based alerting for P.1 (Nawarat Bridge) station

- Add 8 water level zones plus NewEdge threshold for P.1 station
- Zone 1: 3.7m (Info), Zone 2: 3.9m (Info)
- Zone 3-5: 4.0-4.2m (Warning levels)
- Zone 6-7: 4.3-4.6m (Critical levels)
- Zone 8/NewEdge: 4.8m (Emergency level)
- Implement special zone-based checking logic for P.1
- Maintain backward compatibility with standard warning/critical/emergency thresholds
- Keep standard threshold checking for other stations

Zone progression for P.1:
- 3.7m: Zone 1 alert (Info)
- 3.9m: Zone 2 alert (Info)
- 4.0m: Zone 3 alert (Warning)
- 4.1m: Zone 4 alert (Warning)
- 4.2m: Zone 5 alert (Warning)
- 4.3m: Zone 6 alert (Critical)
- 4.6m: Zone 7 alert (Critical)
- 4.8m: Zone 8/NewEdge alert (Emergency)

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-10-03 16:04:12 +07:00
parent dff4dd067d
commit c93d340f8e

View File

@@ -134,7 +134,22 @@ class WaterLevelAlertSystem:
"""Load alert thresholds from config or database"""
# Default thresholds for Northern Thailand stations
return {
"P.1": {"warning": 5.0, "critical": 6.5, "emergency": 8.0},
"P.1": {
# Zone-based thresholds for Nawarat Bridge (P.1)
"zone_1": 3.7,
"zone_2": 3.9,
"zone_3": 4.0,
"zone_4": 4.1,
"zone_5": 4.2,
"zone_6": 4.3,
"zone_7": 4.6,
"zone_8": 4.8,
"newedge": 4.8, # Same as zone 8 or adjust as needed
# Keep legacy thresholds for compatibility
"warning": 3.7,
"critical": 4.3,
"emergency": 4.8
},
"P.4A": {"warning": 4.5, "critical": 6.0, "emergency": 7.5},
"P.20": {"warning": 3.0, "critical": 4.5, "emergency": 6.0},
"P.21": {"warning": 4.0, "critical": 5.5, "emergency": 7.0},
@@ -192,18 +207,42 @@ class WaterLevelAlertSystem:
threshold_value = None
alert_type = None
if water_level >= station_thresholds['emergency']:
alert_level = AlertLevel.EMERGENCY
threshold_value = station_thresholds['emergency']
alert_type = "Emergency Water Level"
elif water_level >= station_thresholds['critical']:
alert_level = AlertLevel.CRITICAL
threshold_value = station_thresholds['critical']
alert_type = "Critical Water Level"
elif water_level >= station_thresholds['warning']:
alert_level = AlertLevel.WARNING
threshold_value = station_thresholds['warning']
alert_type = "High Water Level"
# Special handling for P.1 with zone-based thresholds
if station_code == "P.1" and 'zone_1' in station_thresholds:
# Check all zones in reverse order (highest to lowest)
zones = [
("zone_8", 4.8, AlertLevel.EMERGENCY, "Zone 8 - Emergency"),
("newedge", 4.8, AlertLevel.EMERGENCY, "NewEdge Alert Level"),
("zone_7", 4.6, AlertLevel.CRITICAL, "Zone 7 - Critical"),
("zone_6", 4.3, AlertLevel.CRITICAL, "Zone 6 - Critical"),
("zone_5", 4.2, AlertLevel.WARNING, "Zone 5 - Warning"),
("zone_4", 4.1, AlertLevel.WARNING, "Zone 4 - Warning"),
("zone_3", 4.0, AlertLevel.WARNING, "Zone 3 - Warning"),
("zone_2", 3.9, AlertLevel.INFO, "Zone 2 - Info"),
("zone_1", 3.7, AlertLevel.INFO, "Zone 1 - Info"),
]
for zone_name, zone_threshold, zone_alert_level, zone_description in zones:
if water_level >= zone_threshold:
alert_level = zone_alert_level
threshold_value = zone_threshold
alert_type = zone_description
break
else:
# Standard threshold checking for other stations
if water_level >= station_thresholds.get('emergency', float('inf')):
alert_level = AlertLevel.EMERGENCY
threshold_value = station_thresholds['emergency']
alert_type = "Emergency Water Level"
elif water_level >= station_thresholds.get('critical', float('inf')):
alert_level = AlertLevel.CRITICAL
threshold_value = station_thresholds['critical']
alert_type = "Critical Water Level"
elif water_level >= station_thresholds.get('warning', float('inf')):
alert_level = AlertLevel.WARNING
threshold_value = station_thresholds['warning']
alert_type = "High Water Level"
if alert_level:
alert = WaterAlert(