From b534579e1b48141c48bae7b255417529f0e94fc0 Mon Sep 17 00:00:00 2001 From: bot-backend Date: Wed, 17 Jun 2026 20:47:01 +0300 Subject: [PATCH] fix(site-finder): correct POI-score mock shape+values, routing empty assert (#1486 review) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Rename top_poi → items in poi-score.json to match PoiScoreResponse TS type (mock was cast as PoiScoreResponse but had wrong field name → items undefined at runtime in MOCK_POI_SCORE mode → PoiList2Gis crashed at [...items].sort) - Recompute all score_contribution values using backend formula (weight / _MAX_STRAIGHT_SCORE * 100, _MAX_STRAIGHT_SCORE=0.315) and poi_weighted_score=19.9 (was 72, which was inconsistent with the new normalization) - Add assert result.poi_weighted_score == 0.0 to test_routing_decay_empty_db to match the straight-line empty-db assertion - Remove stale comment in PoiList2Gis.tsx saying normalization needs fixing in site-finder-api.ts (already done backend-side in this PR) --- backend/tests/test_poi_score.py | 1 + .../site-finder/analysis/PoiList2Gis.tsx | 6 +- frontend/src/lib/mocks/poi-score.json | 56 +++++++++---------- 3 files changed, 31 insertions(+), 32 deletions(-) diff --git a/backend/tests/test_poi_score.py b/backend/tests/test_poi_score.py index 711db6c0..ae5aeae3 100644 --- a/backend/tests/test_poi_score.py +++ b/backend/tests/test_poi_score.py @@ -373,6 +373,7 @@ def test_routing_decay_empty_db(monkeypatch): monkeypatch.setattr(ors_client, "is_configured", lambda: True) result = compute_poi_routing_decay(db, "cad", 56.838, 60.605) assert result.top_poi == [] + assert result.poi_weighted_score == 0.0 def test_routing_decay_score_spread_wider_than_straight_line(monkeypatch): diff --git a/frontend/src/components/site-finder/analysis/PoiList2Gis.tsx b/frontend/src/components/site-finder/analysis/PoiList2Gis.tsx index fc5f042d..e2e23ae2 100644 --- a/frontend/src/components/site-finder/analysis/PoiList2Gis.tsx +++ b/frontend/src/components/site-finder/analysis/PoiList2Gis.tsx @@ -72,10 +72,8 @@ interface Props { // ── Component ───────────────────────────────────────────────────────────────── export function PoiList2Gis({ items, totalScore }: Props) { - // POI-weighted score is presented as «X / 100», so clamp to 0..100 defensively: - // the adapter sums round(weight*100) per POI без нормировки и при достаточном - // числе POI может выдать >100 → бессмысленное «137 / 100» (#1470). Корневую - // нормировку нужно чинить в site-finder-api.ts (useParcelPoiScoreQuery). + // poi_weighted_score is normalized to 0..100 on the backend (#1486). + // Clamp defensively in case of floating-point edge cases. const displayScore = Math.min(100, Math.max(0, totalScore)); // Top-7, sorted by score_contribution desc diff --git a/frontend/src/lib/mocks/poi-score.json b/frontend/src/lib/mocks/poi-score.json index bf71df77..315ea39f 100644 --- a/frontend/src/lib/mocks/poi-score.json +++ b/frontend/src/lib/mocks/poi-score.json @@ -1,22 +1,22 @@ { "cad_num": "66:41:0701045:42", "radius_m": 2000, - "poi_weighted_score": 72, - "top_poi": [ + "poi_weighted_score": 19.9, + "items": [ + { + "category": "park", + "name": "Сквер Попова", + "distance_m": 150, + "weight": 0.014, + "score_contribution": 4.4, + "address": null + }, { "category": "metro_stop", "name": "Площадь 1905 года", "distance_m": 340, - "weight": 0.013559, - "score_contribution": 22.3, - "address": null - }, - { - "category": "school", - "name": "Школа № 32", - "distance_m": 480, - "weight": 0.00885, - "score_contribution": 14.5, + "weight": 0.013636, + "score_contribution": 4.3, "address": null }, { @@ -24,15 +24,15 @@ "name": "Детский сад № 111", "distance_m": 260, "weight": 0.0125, - "score_contribution": 12.7, + "score_contribution": 4.0, "address": null }, { - "category": "park", - "name": "Сквер Попова", - "distance_m": 150, - "weight": 0.014, - "score_contribution": 10.8, + "category": "school", + "name": "Школа № 32", + "distance_m": 480, + "weight": 0.008621, + "score_contribution": 2.7, "address": null }, { @@ -40,15 +40,7 @@ "name": "Городская больница № 7", "distance_m": 650, "weight": 0.005333, - "score_contribution": 8.8, - "address": null - }, - { - "category": "shop_mall", - "name": "МЕГА Екатеринбург", - "distance_m": 1200, - "weight": 0.003077, - "score_contribution": 5.0, + "score_contribution": 1.7, "address": null }, { @@ -56,7 +48,15 @@ "name": "Гимназия № 9", "distance_m": 820, "weight": 0.005435, - "score_contribution": 4.4, + "score_contribution": 1.7, + "address": null + }, + { + "category": "shop_mall", + "name": "МЕГА Екатеринбург", + "distance_m": 1200, + "weight": 0.003077, + "score_contribution": 1.0, "address": null } ]