fix(site-finder): correct POI-score mock shape+values, routing empty assert (#1486 review)
Some checks failed
CI / changes (pull_request) Successful in 8s
CI / changes (push) Successful in 9s
CI / backend-tests (push) Has been skipped
CI / frontend-tests (push) Has been skipped
CI / openapi-codegen-check (push) Has been skipped
CI / frontend-tests (pull_request) Successful in 49s
CI / openapi-codegen-check (pull_request) Failing after 1m35s
CI / backend-tests (pull_request) Failing after 8m47s

- 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)
This commit is contained in:
bot-backend 2026-06-17 20:47:01 +03:00
parent 68eb6ded89
commit b534579e1b
3 changed files with 31 additions and 32 deletions

View file

@ -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):

View file

@ -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

View file

@ -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
}
]