perf: cache IEM SBW globally, clip alerts to viewport, slim properties
National storm-based warnings are fetched once (45s TTL) and clipped to the quantized bbox. Popup fields only — NWS descriptions stay off the wire.
This commit is contained in:
parent
84532d505a
commit
fdd59052c5
2 changed files with 162 additions and 20 deletions
|
|
@ -3,10 +3,12 @@
|
|||
from live_layers import (
|
||||
MARKER_FIELDS,
|
||||
bbox_center_radius_nm,
|
||||
clip_fc_to_bbox,
|
||||
filter_points_bbox,
|
||||
parse_bbox,
|
||||
quantize_bbox,
|
||||
rainviewer_tile_url,
|
||||
slim_alert_properties,
|
||||
to_marker,
|
||||
transform_adsb_lol,
|
||||
transform_ais_frame,
|
||||
|
|
@ -15,6 +17,7 @@ from live_layers import (
|
|||
transform_wfigs_incidents,
|
||||
_cache,
|
||||
_ttl_get,
|
||||
_wfigs_params,
|
||||
)
|
||||
|
||||
from camera_scraper import parse_caltrans_json
|
||||
|
|
@ -287,3 +290,64 @@ def test_ttl_get_does_not_block_other_keys():
|
|||
assert _cache["slow"][1] == "S"
|
||||
assert _cache["fast"][1] == "F"
|
||||
_cache.clear()
|
||||
|
||||
|
||||
def test_clip_fc_to_bbox_drops_far_features_and_empty_geometry():
|
||||
fc = {
|
||||
"type": "FeatureCollection",
|
||||
"features": [
|
||||
{
|
||||
"type": "Feature",
|
||||
"properties": {"event": "near"},
|
||||
"geometry": {"type": "Point", "coordinates": [-78.7, 35.8]},
|
||||
},
|
||||
{
|
||||
"type": "Feature",
|
||||
"properties": {"event": "far"},
|
||||
"geometry": {"type": "Point", "coordinates": [-120.0, 45.0]},
|
||||
},
|
||||
{
|
||||
"type": "Feature",
|
||||
"properties": {"event": "nogeom"},
|
||||
"geometry": None,
|
||||
},
|
||||
{
|
||||
"type": "Feature",
|
||||
"properties": {"event": "poly-overlap"},
|
||||
"geometry": {
|
||||
"type": "Polygon",
|
||||
"coordinates": [[
|
||||
[-79.0, 35.0], [-78.0, 35.0], [-78.0, 36.0],
|
||||
[-79.0, 36.0], [-79.0, 35.0],
|
||||
]],
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
clipped = clip_fc_to_bbox(fc, -79.0, 35.5, -78.0, 36.0)
|
||||
events = [f["properties"]["event"] for f in clipped["features"]]
|
||||
assert events == ["near", "poly-overlap"]
|
||||
|
||||
|
||||
def test_slim_alert_properties_keeps_popup_fields_only():
|
||||
fat = {
|
||||
"event": "Tornado Warning",
|
||||
"severity": "Extreme",
|
||||
"headline": "TORNADO WARNING",
|
||||
"areaDesc": "Wake",
|
||||
"wfo": "RAH",
|
||||
"source": "nws",
|
||||
"parameters": {"WIND": ["70"]},
|
||||
"description": "A long narrative " * 40,
|
||||
"instruction": "Take shelter.",
|
||||
"geocode": {"SAME": ["037183"]},
|
||||
}
|
||||
slim = slim_alert_properties(fat)
|
||||
assert slim == {
|
||||
"event": "Tornado Warning",
|
||||
"severity": "Extreme",
|
||||
"headline": "TORNADO WARNING",
|
||||
"areaDesc": "Wake",
|
||||
"wfo": "RAH",
|
||||
"source": "nws",
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue