fix: bind knowledge maps to explicit regions

This commit is contained in:
xuelong committed 2026-08-26 02:26:24 -07:00
1 parent 329a94d457
commit 90f75d41ae
15 files changed
+1126 -275

No files matched your search

+37
View File
@@ -5,6 +5,7 @@ from app.api.plaza import (
_graph_map_poi_items,
_graph_poi_detail_payload,
_graph_zone_payload,
_resolve_spatial_graph_name,
)
@@ -48,6 +49,42 @@ class PlazaGraphFallbackTests(unittest.TestCase):
self.assertEqual(items[1]["categories"], ["公交站"])
self.assertEqual(items[0]["zone_id"], "A01")
def test_city_place_nodes_use_place_type_as_dynamic_business_category(self) -> None:
items = _graph_map_poi_items(
[[
None,
["Place"],
{
"element_id": "city:mall-1",
"name": "测试商场",
"place_type": "mall",
"longitude": 106.63,
"latitude": 26.65,
"adcode": "520102",
},
]]
)
self.assertEqual(items[0]["category"], "商场")
self.assertEqual(items[0]["categories"], ["商场"])
self.assertEqual(items[0]["lng"], 106.63)
self.assertEqual(items[0]["adcode"], "520102")
def test_coordinate_helper_nodes_are_not_rendered_as_business_pois(self) -> None:
items = _graph_map_poi_items(
[[
"cell-1",
["GeoCell"],
{"name": "网格", "lng": 106.63, "lat": 26.65},
]]
)
self.assertEqual(items, [])
def test_legacy_city_project_uses_its_explicit_spatial_companion(self) -> None:
self.assertEqual(_resolve_spatial_graph_name("guiyang_new2"), "guiyang_spatial_v1")
self.assertEqual(_resolve_spatial_graph_name("city_import_v3"), "city_import_v3")
def test_graph_zones_decode_serialized_geometry(self) -> None:
payload = _graph_zone_payload(
[[{"towncode": "522722100000", "name": "玉屏街道"}, 12, 107.8, 25.3, 107.9, 25.5]],
+80 -3
View File
@@ -111,15 +111,92 @@ class ProjectPayloadValidationTests(unittest.TestCase):
def test_spatial_map_defaults_to_disabled_libo_scope(self) -> None:
payload = normalize_provision_payload(valid_payload())
self.assertEqual(payload["spatial_map"], {"enabled": False, "scope": "libo"})
self.assertEqual(payload["spatial_map"], {
"enabled": False,
"scope": "libo",
"region_name": "",
"region_adcode": "",
"region_level": "province",
})
def test_spatial_map_option_is_normalized(self) -> None:
body = valid_payload()
body["spatial_map"] = {"enabled": True, "scope": "guizhou"}
body["schema"]["entity_types"]["Place"]["fields"].update({
"lng": {"type": "number"},
"lat": {"type": "number"},
"adcode": {"type": "string"},
"place_type": {"type": "string"},
})
body["graph_data"]["nodes"][0]["properties"].update({
"lng": 106.63,
"lat": 26.65,
"adcode": "520102",
"place_type": "mall",
})
body["spatial_map"] = {
"enabled": True,
"scope": "guizhou",
"region_name": "贵阳市",
"region_adcode": "520100",
"region_level": "city",
}
payload = normalize_provision_payload(body)
self.assertEqual(payload["spatial_map"], {"enabled": True, "scope": "guizhou"})
self.assertEqual(payload["spatial_map"], body["spatial_map"])
def test_spatial_map_rejects_data_outside_selected_city(self) -> None:
body = valid_payload()
body["schema"]["entity_types"]["Place"]["fields"].update({
"lng": {"type": "number"},
"lat": {"type": "number"},
"adcode": {"type": "string"},
"type_label": {"type": "string"},
})
body["graph_data"]["nodes"][0]["properties"].update({
"lng": 107.0,
"lat": 27.0,
"adcode": "520302",
"type_label": "美食",
})
body["spatial_map"] = {
"enabled": True,
"scope": "guizhou",
"region_name": "贵阳市",
"region_adcode": "520100",
"region_level": "city",
}
with self.assertRaises(ProjectValidationError) as raised:
normalize_provision_payload(body)
self.assertIn("数据与所选区域 贵阳市 不一致", ";".join(raised.exception.errors))
def test_spatial_map_accepts_legacy_city_name_when_adcode_is_missing(self) -> None:
body = valid_payload()
body["schema"]["entity_types"]["Place"]["fields"].update({
"lng": {"type": "number"},
"lat": {"type": "number"},
"city": {"type": "string"},
"place_type": {"type": "string"},
})
body["graph_data"]["nodes"][0]["properties"].update({
"lng": 106.63,
"lat": 26.65,
"city": "贵阳",
"place_type": "transit_stop",
})
body["spatial_map"] = {
"enabled": True,
"scope": "guizhou",
"region_name": "贵阳市",
"region_adcode": "520100",
"region_level": "city",
}
payload = normalize_provision_payload(body)
self.assertEqual(payload["spatial_map"]["region_name"], "贵阳市")
def test_invalid_spatial_map_is_rejected(self) -> None:
body = valid_payload()