Merge pull request 'Honest pins and paths: geocode precision, type-gated paths, impossible-speed stops (#236)' (#274) from feat/236-honest-pins into main
This commit was merged in pull request #274.
This commit is contained in:
@@ -690,8 +690,15 @@ async def _geocode_location(
|
||||
"""
|
||||
Geocode using Google Maps Geocoding API, biased toward the channel's area.
|
||||
|
||||
Returns {"lat": float, "lng": float}, or None if geocoding fails or the
|
||||
result lands outside the area this channel covers.
|
||||
Returns {"lat": float, "lng": float, "location_type": str}, or None if
|
||||
geocoding fails or the result lands outside the area this channel covers.
|
||||
|
||||
server-26#236: `location_type` (ROOFTOP / RANGE_INTERPOLATED /
|
||||
GEOMETRIC_CENTER) rides along with the coordinates so the map can show how
|
||||
precise a pin is — a route centroid must not draw the same teardrop as a
|
||||
rooftop. It is display-only: every consumer of these coords reads only
|
||||
"lat"/"lng", and the dict is stored as-is on the call doc and, through
|
||||
incident_correlator._resolve_location_pair, on the incident pin.
|
||||
|
||||
THE REFERENCE POINT IS THE TALKGROUP, NOT THE NODE (server-26#6 / #37). This
|
||||
used to reject anything more than geocode_max_km (40km) from the receiving
|
||||
@@ -801,7 +808,7 @@ async def _geocode_location(
|
||||
f"{dist_km:.1f}km from the receiving node, past {max_km:.1f}km — "
|
||||
f"accepted anyway: the query names its own region, not the node's"
|
||||
)
|
||||
coords = {"lat": lat, "lng": lng}
|
||||
coords = {"lat": lat, "lng": lng, "location_type": location_type}
|
||||
logger.info(
|
||||
f"Geocoded '{location_str}' → {coords} "
|
||||
f"({dist_km:.1f}km from {ref_label}) [{location_type}]"
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
"""
|
||||
server-26#236: geocode precision must travel with the coordinates.
|
||||
|
||||
`_geocode_location` already judged a result by Google's `location_type` but
|
||||
returned only {lat, lng}, so a GEOMETRIC_CENTER route centroid and a ROOFTOP
|
||||
address drew the same pin. The type is now part of the returned dict, which
|
||||
is stored as-is on the call doc and carried unchanged onto the incident pin by
|
||||
`incident_correlator._resolve_location_pair`.
|
||||
|
||||
Display-only: every correlator read of location_coords indexes ["lat"] and
|
||||
["lng"] directly, so the extra key cannot change a correlation decision.
|
||||
"""
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
import app.internal.intelligence as intel
|
||||
from app.config import settings
|
||||
from tests.test_geocode_named_region import _maps_result
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def _api_key():
|
||||
with patch.object(settings, "google_maps_api_key", "test-key"):
|
||||
yield
|
||||
|
||||
|
||||
ANCHOR = {"lat": 41.16, "lng": -73.86, "radius_km": 10.0}
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.parametrize("location_type", ["ROOFTOP", "RANGE_INTERPOLATED", "GEOMETRIC_CENTER"])
|
||||
async def test_accepted_location_type_is_returned_with_the_coords(location_type):
|
||||
with _maps_result(41.161, -73.861, location_type=location_type):
|
||||
coords = await intel._geocode_location("1 Main Street, Ossining", anchor=ANCHOR)
|
||||
assert coords == {"lat": 41.161, "lng": -73.861, "location_type": location_type}
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.parametrize("location_type", ["APPROXIMATE", "", "SOMETHING_NEW"])
|
||||
async def test_rejected_location_type_still_returns_none(location_type):
|
||||
with _maps_result(41.161, -73.861, location_type=location_type):
|
||||
coords = await intel._geocode_location("Ossining", anchor=ANCHOR)
|
||||
assert coords is None
|
||||
|
||||
|
||||
def test_location_type_survives_onto_the_incident_pin():
|
||||
"""`_resolve_location_pair` stores the call's coords dict as-is, so the
|
||||
precision reaches the incident without any correlator change."""
|
||||
from app.internal.incident_correlator import _resolve_location_pair
|
||||
|
||||
pin = {"lat": 41.161, "lng": -73.861, "location_type": "GEOMETRIC_CENTER"}
|
||||
fields = _resolve_location_pair({}, "Route 9 and Main Street", pin)
|
||||
assert fields["location_coords"] == pin
|
||||
assert fields["location_coords_source"] == "Route 9 and Main Street"
|
||||
|
||||
@@ -69,7 +69,7 @@ async def test_named_region_geocode_accepted_beyond_node_distance():
|
||||
node_lat=NODE_LAT, node_lon=NODE_LON,
|
||||
trust_named_region=True,
|
||||
)
|
||||
assert coords == {"lat": FAR_LAT, "lng": FAR_LNG}
|
||||
assert coords == {"lat": FAR_LAT, "lng": FAR_LNG, "location_type": "ROOFTOP"}
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -110,7 +110,7 @@ async def test_named_region_geocode_within_node_distance_is_unaffected():
|
||||
node_lat=NODE_LAT, node_lon=NODE_LON,
|
||||
trust_named_region=True,
|
||||
)
|
||||
assert coords == {"lat": near_lat, "lng": near_lng}
|
||||
assert coords == {"lat": near_lat, "lng": near_lng, "location_type": "ROOFTOP"}
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
||||
Reference in New Issue
Block a user