fix(site-finder): normalize POI weighted score to 0..100 on backend (#1486) #1674

Merged
lekss361 merged 2 commits from fix/poi-score-scale-1486 into main 2026-06-17 17:54:53 +00:00
Owner

Проблема (#1486)

Фронт делал Math.round(weight*100), считая weight∈[0..1], но backend отдаёт weight=cat_weight/(dist+100) ≈0.0001–0.06 → сумма ~5/100 для участка с отличной инфраструктурой; пороги badge (≥0.2/0.12/0.08) недостижимы → все POI амбер.

Решение (нормировка на backend)

  • poi_score.py: константы _TOP7_WEIGHT_SUM/_MAX_STRAIGHT_SCORE/_MAX_ROUTING_SCORE; новые поля PoiScoreItem.score_contribution и PoiScoreResponse.poi_weighted_score (0..100). Нормировка обоих режимов (straight/routing) + фикс early-return в routing.
  • Фронт site-finder-api.ts: убран *100, рендерит готовые backend-поля. PoiList2Gis.tsx: пороги badge → 0..100 (≥20/12/8), бейдж показывает score_contribution. Мок обновлён.

Verify

  • ruff clean; pytest tests/test_poi_score.py28 passed (7 новых тестов на шкалу/диапазон/сумму).
  • tsc --noEmit → 0 ошибок.
  • Sanity: метро@0м+инфра → 100/100; метро@400м+школа@500м+парк@200м → ~11/100 (не 5).

Closes #1486

## Проблема (#1486) Фронт делал `Math.round(weight*100)`, считая weight∈[0..1], но backend отдаёт `weight=cat_weight/(dist+100)` ≈0.0001–0.06 → сумма ~5/100 для участка с отличной инфраструктурой; пороги badge (≥0.2/0.12/0.08) недостижимы → все POI амбер. ## Решение (нормировка на backend) - `poi_score.py`: константы `_TOP7_WEIGHT_SUM`/`_MAX_STRAIGHT_SCORE`/`_MAX_ROUTING_SCORE`; новые поля `PoiScoreItem.score_contribution` и `PoiScoreResponse.poi_weighted_score` (0..100). Нормировка обоих режимов (straight/routing) + фикс early-return в routing. - Фронт `site-finder-api.ts`: убран `*100`, рендерит готовые backend-поля. `PoiList2Gis.tsx`: пороги badge → 0..100 (≥20/12/8), бейдж показывает `score_contribution`. Мок обновлён. ## Verify - `ruff` clean; `pytest tests/test_poi_score.py` → **28 passed** (7 новых тестов на шкалу/диапазон/сумму). - `tsc --noEmit` → 0 ошибок. - Sanity: метро@0м+инфра → 100/100; метро@400м+школа@500м+парк@200м → ~11/100 (не 5). Closes #1486
lekss361 added 1 commit 2026-06-17 17:30:54 +00:00
fix(site-finder): normalize POI weighted score to 0..100 on backend (#1486)
Some checks failed
CI / changes (push) Successful in 10s
CI / changes (pull_request) Successful in 12s
CI / frontend-tests (push) Successful in 49s
CI / openapi-codegen-check (push) Failing after 1m45s
CI / backend-tests (push) Failing after 8m57s
CI / frontend-tests (pull_request) Successful in 45s
CI / openapi-codegen-check (pull_request) Failing after 1m37s
CI / backend-tests (pull_request) Failing after 8m53s
68eb6ded89
Backend now computes poi_weighted_score and per-POI score_contribution in
0..100 range. Normalization denominator = sum of top-7 category weights / 100
(straight-line mode) or sum of top-7 category weights (routing-decay mode).
Frontend stops reconstructing score from raw weight × 100.
bot-backend added 1 commit 2026-06-17 17:47:13 +00:00
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
b534579e1b
- 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)
lekss361 merged commit 7d5962e7b4 into main 2026-06-17 17:54:53 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: lekss361/gendesign#1674
No description provided.