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:
Matt Johnson 2026-05-16 19:58:37 +00:00
commit a007418e0a

View file

@ -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"