feat(site-finder): inline POI weights pass-through в /analyze (#201 Phase 1) #206

Merged
lekss361 merged 4 commits from feat/201-inline-weights into main 2026-05-16 11:00:42 +00:00

4 commits

Author SHA1 Message Date
lekss361
cada96e874 fix(parcels): NaN/Inf bypass in inline weights validation, dedupe _POI_WEIGHTS (#201 #206 fixup)
- math.isfinite() guard в out_of_range check (NaN bypass: NaN<MIN/MAX → False)
- Same guard в weight_profiles._validate_weights_dict (pre-existing dup bug)
- _POI_WEIGHTS теперь импорт из weight_profiles._SYSTEM_POI_WEIGHTS (SSOT)
- Test test_inline_weights_rejects_nan (raw NaN payload → 422)
2026-05-16 13:53:46 +03:00
lekss361
038e39e2ec feat(site-finder): inline POI weights pass-through в /analyze (#201 Phase 1)
Critical UX fix для #114 — user-drag слайдеры в WeightProfilePanel
теперь применяются immediately к scoring, без обязательного profile save.

Backend (parcels.py + schemas/parcel.py + tests):
- POST /analyze принимает optional AnalyzeRequest { weights: dict[str,float] | None }
- Priority: inline → profile_id → user_default → system defaults
- Validate against ALLOWED_CATEGORIES + [MIN_WEIGHT, MAX_WEIGHT] → 422 на violation
- Partial override semantics
- 5 mock tests

Frontend (useSiteAnalysis.ts + page.tsx):
- weights param в analyze mutation
- handleAnalyze всегда передаёт currentWeights когда activeProfileId=null
- handleWeightsChange re-trigger analyze immediately если parcel loaded

Phase 2 (debounce) + Phase 3 (Edit/Delete UI) — follow-up.
2026-05-16 13:39:14 +03:00
lekss361
434341e98f fix(layouts): address review-bot minor items (#113 PR D)
Backend (parcels.py + layout_tz_pdf.py):
- 🟡 /best-layouts/pdf 404 handling: catch ValueError → 404
  (consistent с JSON endpoint handling геометрия не найдена)
- 🟡 XSS defense-in-depth: html.escape() для r.room_bucket,
  r.area_bin, m.room_bucket в HTML row generators

Frontend (BestLayoutsBlock.tsx):
- 🟡 data_window dates → ru-RU locale (toLocaleDateString)
- 🟢 target_total_flats clamped к [1, 10000] перед submit
  (paste-bypass на client защищён, backend Pydantic le=10000)

Tests: 5+27 backend pass, frontend tsc/lint/build clean.
2026-05-16 12:50:10 +03:00
lekss361
5878596bc5 feat(layouts): PDF ТЗ endpoint + BestLayoutsBlock UI (#113 PR D)
Backend (~330 LOC):
- POST /api/v1/parcels/{cad_num}/best-layouts/pdf via WeasyPrint
- services/exporters/layout_tz_pdf.py — HTML template с XSS-escape (html.escape)
  для cad_num/parcel_address/rationale_text/time_window
- 5 unit tests (skip on Windows если WeasyPrint deps missing)

Frontend (~800 LOC):
- BestLayoutsBlock.tsx — DataQualityCard + TopLayoutsTable + RecommendationCard
  + PDF download button (Blob → revokeObjectURL)
- useBestLayouts.ts — TanStack useMutation hook
- types/best-layouts.ts — manual TS types
- MarketTab.tsx +4 LOC integration после competitors

Pre-push fixes per review:
- XSS escape user-data в PDF HTML
- sold_pct_of_supply — убрать double ×100 (backend уже 0..100)
- alert() → pdfError state
- isNaN → Number.isNaN
- 7 inline-styles → Tailwind utilities

Phase 2.1 complete. Phase 2.2 (layout_type/balcony_count via B2B Объектив
#52) — follow-up issue.
2026-05-16 12:38:23 +03:00