Repository navigation
chore(nws): offset the zone request and place the alerts locally - #448
systems-monitor wants to merge 4 commits into
Conversation
Round 3 of seevee#316. A zone request calculated from the position itself can be turned back into the position by anyone who has the zone shapes. This module gives the request a different centre. Nothing calls it yet, and it has no Home Assistant imports. The centre is the position moved in a random direction by 15 to 35 percent of the radius, and never by less than 15 to 35 miles. The request radius is enlarged by the largest offset that could have been drawn plus the hold distance, so the circle asked about always covers the radius around the position. An offset is drawn once for a place and kept as a lock record: where it was drawn, how far the position may move before it is drawn again, and the offset. A position inside a record's hold radius gets that record's offset. A new draw for the same place would let the requests be averaged back to it. The store holds at most 20,000 records and remembering can be switched off. Records can be written out and read back. A stored record that could not have been made is left out and the rest are kept, and records still written whole in a damaged text are recovered. Refs: seevee#316
Round 3 of seevee#316. providers/nws_matching.py decides, on this system, what a zone request should name and where each alert in the reply lies. Nothing calls it yet, and it has no Home Assistant imports. request_codes() names every zone in the circle it is given, with the codes sorted so that the order says nothing about the centre, and split_codes() divides a list too long for one request. place_alerts() marks each alert as here, nearby with its distance to the nearest edge, or beyond the radius, and only the last is discarded. Here is what a request by point returns: an alert with a polygon when the point is inside it, and an alert with zones only when one of them is within its simplification tolerance of the point, with the land and sea rule banded the same way. An alert that cannot be placed is kept. Refs: seevee#316
Round 3 of seevee#316. The parity script now makes the request the local mode will make: zones around an offset centre, over the enlarged circle, split when the list is long. It places the reply with the integration's own matching and compares the alerts placed at the point with what point= returns. The verdicts are MATCH, MATCH+ when the tolerance band alone admitted the extra alerts, and DIFFER, which is the only one that fails. tests/test_nws_zone_parity.py runs the check against a stand-in for the service. tests/test_zone_dataset_acceptance.py gains two checks on the real zones, skipped without the shapefiles: that a request from an offset centre names every zone a position needs, and that a tracker's minimum hold shows only the position's own alerts where zones are smaller than it. Refs: seevee#316
Round 3 of seevee#316. The parity check called it a difference whenever the local placing kept an alert that point= did not return and a zone containing the point explained it. On 25 November 2026 that happened at two points on the coast of Santa Catalina Island, every time they were asked: each lies 70 to 90 m inside the dataset's outline of the island's zones, and the service did not return two advisories that the placing kept. The dataset's shapes are simplified to within each zone's tolerance, 567 m here. Nearer an edge than that, the dataset cannot say which side of the surveyed edge a point is on, and the service decides on the surveyed one. An alert kept there is the tolerance's cost, the same as an alert the band admits from just outside a zone. The check now reports such an alert as "extra, at a zone's edge", lists the zones concerned, and gives MATCH+. An extra alert still fails when the point is inside the alert's own polygon, which comes from the service as drawn, or deeper inside one of its zones than the tolerance. Something point= returned and the placing lacks fails as before. Refs: seevee#316
|
Thanks, this is a big piece and it reads carefully. Catalina is a nice catch, and I agree with passing an extra alert at a zone's edge. On the radius, I'd like the default at 0. Local mode should give what On the cap, a soft one. The form takes anything up to 400 km, the largest you've measured, and above 200 km it asks the user to confirm with the cost spelled out. Does that work for you? Since you're not running a dev instance, I'll take the form piece when we get there, confirm step included, and load each piece before that on my dev box as it comes in. For the docs I still need reply size in bytes per poll on a busy day, and timings on small hardware. I can run the Yellow side if you give me a script. Two things before I merge:
Last one, small. |
Round 3 of #316, first part. Two modules and the parity script. Nothing calls the modules yet, so this changes nothing for any entry.
What is here
chore(nws): calculate the zone request from an offset positionproviders/nws_offset.py: where the zone request is centred, and the record of that choice.chore(nws): ask about every zone in range and place each alertproviders/nws_matching.py: which zones a request names, and where each alert in the reply lies relative to the position.chore(scripts): compare the placing with point= on the live servicescripts/nws_zone_parity.pymakes the request the mode will make and compares the result withpoint=.chore(scripts): count an extra alert at a zone's edge as a matchNeither module imports Home Assistant. Each commit passes the gates on its own.
Two things that changed since #435
1. The radius means every alert within it. Earlier drafts kept only the alerts for the exact point and asked about a few zones per layer. I use this to follow weather that is on its way, at about 100 miles, so the request now names every zone in the circle and each alert in the reply is placed:
point=returns. An alert with a polygon when the point is inside it; an alert with zones only when one of them is within its simplification tolerance of the point (567 m; 2.2 km in the states the dataset lists), with the land and sea rule banded the same way;An alert that cannot be placed is kept. How nearby alerts show up in entities is a later piece and is yours to shape; it touches Feat - Differentiating your current zone versus neighboring zones. #430.
2. The request is not made from the position. A zone list calculated from the exact position can be turned back into an area of about 2 to 430 km² by anyone who holds the zone shapes, which are public, and a wider radius can make that area smaller. So the request is centred somewhere else:
Your question about a cap on the radius
I have left the radius without an upper limit in these modules, with 100 km as the intended default. The cost grows with the radius and I would leave that choice to the user. If you want a cap, tell me the number: it is one line in the form, which comes in the last piece.
What a poll's local work costs, on the real dataset (11,651 zones,
c985ed4f), on an x86 machine, with an alert on every zone as the worst case, over 162 polls at nine places:Building the request took 5.4 ms at the median and 164 ms at worst; placing the reply took 2.7 ms at the median and 77 ms at worst. The worst cases are the 400 km ones. The later piece that calls these runs them in the executor, never on the event loop. I have not measured this on a Yellow or a Pi.
A request is at most 300 zones. NWS accepted 426 zones in one request and answered HTTP 500 at 462, so a longer list is divided and the replies merged.
How it was checked
pytest 2808 passed, 20 skipped; cov 98%; flow cov 100%; ruff check ok; ruff format ok; mypy ok.tests/test_zone_dataset_acceptance.py, which skip without the shapefiles. With the 16 April shapefiles they pass here.point=, some with extra alerts that the tolerance band explains (32 of the 228 points in the last two runs).What the live check found
Two points differed every time they were asked, four times each. Both are on the coast of Santa Catalina Island (
33.3205,-118.3785and33.4777,-118.5824). The placing kept a Coastal Flood Advisory and a High Surf Advisory there thatpoint=did not return. Nothingpoint=returned was missing.The two points lie 72 m and 90 m inside the dataset's outline of the island's zones (
CAZ087,CAC037,CAZ287). The shapes are simplified to within 567 m, and the service decides on the shape as surveyed, so the outline reaches a little past the real coastline and a point in that margin is on the island for the dataset and in the water for the service. A point 3.7 km inland agrees withpoint=.This is the tolerance band seen from the other side. The band covers a point just outside a zone; this is a point just inside one. Either way the entry shows an alert for a place a few hundred metres away, and the marine zone counts at those two points as well. The placing is unchanged. The last commit changes the check: an extra alert for a zone whose edge is within the tolerance of the point is reported as "extra, at a zone's edge" and passes. An extra alert still fails when the point is inside the alert's own polygon or deeper inside one of its zones than the tolerance. Asked again with that commit, the two points read
MATCH+and the inland oneMATCH.One further point differed in the first run. I did not capture it, and I cannot say whether it was the same thing.
A note for anyone running the check: the two replies the service gives for one point were stamped up to 288 seconds apart, with a median of zero, so an alert issued or ended between them can also show as a difference. None of the differences I captured was of that kind.
What comes after
So you can see where this leads. Each is a separate pull request, and nothing is reachable by a user until the last.
Refs NWS: area-scoped GPS/tracker mode that never sends coordinates (local point matching, multiple areas) #316