mirror of
https://github.com/zvx-echo6/central.git
synced 2026-05-21 18:14:44 +02:00
feat(models): add fire event subject routing
Update subject_for_event to handle fire.* category events: - Fire events: central.<category> (e.g., central.fire.hotspot.viirs_snpp.high) - Weather events: existing geo-based subject logic Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
0097163edf
commit
a007418e0a
1 changed files with 79 additions and 68 deletions
|
|
@ -24,7 +24,7 @@ class Event(BaseModel):
|
||||||
|
|
||||||
id: str # unique, stable across republish
|
id: str # unique, stable across republish
|
||||||
source: str # adapter identity, e.g. "central/adapters/nws"
|
source: str # adapter identity, e.g. "central/adapters/nws"
|
||||||
category: str # e.g. "wx.alert.severe_thunderstorm_warning"
|
category: str # e.g. "wx.alert.severe_thunderstorm_warning" or "fire.hotspot.viirs_snpp.high"
|
||||||
time: datetime # event-time UTC, not processing-time
|
time: datetime # event-time UTC, not processing-time
|
||||||
expires: datetime | None = None
|
expires: datetime | None = None
|
||||||
severity: int | None = None # 0..4 or None for "Unknown"
|
severity: int | None = None # 0..4 or None for "Unknown"
|
||||||
|
|
@ -32,19 +32,30 @@ class Event(BaseModel):
|
||||||
data: dict[str, Any] # adapter-specific payload
|
data: dict[str, Any] # adapter-specific payload
|
||||||
|
|
||||||
|
|
||||||
def subject_for_event(ev: Event, prefix: str = "central.wx") -> str:
|
def subject_for_event(ev: Event) -> str:
|
||||||
"""
|
"""
|
||||||
Compute the NATS subject for an alert-style event.
|
Compute the NATS subject for an event based on its category.
|
||||||
|
|
||||||
For weather alerts the subject is:
|
Dispatch by category prefix:
|
||||||
|
- fire.*: returns central.<category> directly
|
||||||
|
- wx.*: uses weather alert subject logic
|
||||||
|
|
||||||
|
Weather alert subjects:
|
||||||
central.wx.alert.us.<state_lower>.county.<county_lower>
|
central.wx.alert.us.<state_lower>.county.<county_lower>
|
||||||
or
|
or
|
||||||
central.wx.alert.us.<state_lower>.zone.<zone_lower>
|
central.wx.alert.us.<state_lower>.zone.<zone_lower>
|
||||||
based on whether the primary_region encodes a county or a zone.
|
based on whether the primary_region encodes a county or a zone.
|
||||||
|
|
||||||
If primary_region is None or unparseable, returns:
|
Fire hotspot subjects:
|
||||||
central.wx.alert.us.unknown
|
central.fire.hotspot.<satellite>.<confidence>
|
||||||
"""
|
"""
|
||||||
|
# Fire events: subject is just central.<category>
|
||||||
|
if ev.category.startswith("fire."):
|
||||||
|
return f"central.{ev.category}"
|
||||||
|
|
||||||
|
# Weather events: use geo-based subject logic
|
||||||
|
prefix = "central.wx"
|
||||||
|
|
||||||
if ev.geo.primary_region is None:
|
if ev.geo.primary_region is None:
|
||||||
return f"{prefix}.alert.us.unknown"
|
return f"{prefix}.alert.us.unknown"
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue