fix(site_finder): make Location demand_index city-relative (#948) #1167
No reviewers
Labels
No labels
admin
analytics
auth
automation
bug
business
chore
ci
compliance
data
data-moat
docs
duplicate
dx
enhancement
Fable 5 ревью
feedback/max
generative
GG-форсайт
needs-discussion
needs-human
observability
pause-bots
performance
priority/p0
priority/p1
priority/p2
priority/p3
scope/backend
scope/db
scope/devops
scope/frontend
scope/qa
scrapers
security
site-finder
stage/1
stage/2
status/blocked
status/done
status/needs-analysis
status/needs-fix
status/qa
status/ready
status/review
status/wip
tech-debt
tradein
ux
week ревью 1
wontfix
вторичка
ИРД
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: lekss361/gendesign#1167
Loading…
Add table
Reference in a new issue
No description provided.
Delete branch "fix/location-demand-relative-948"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
location.demand_index(district-level Site-Finder index, #948 Part B) wasclamp01(unit_velocity / 50)with a fixed magic constant. On a live prod refresh all 8 ЕКБ districts came backdemand=1.0— every district sells ≥50 apartments/mo, so the index saturated flat and gave zero discrimination between districts (the other 3 indices spread fine: infra 0.747–1.0, competition 0.540–0.837, future_supply 0–0.096).Redesign demand to be city-relative, mirroring how
infra_indexalready normalizes_district_poi_score / _city_avg_poi_score:normalize_demand(velocity, *, city_reference_velocity)— pure, graceful (None stays None; reference ≤ 0 → honest0.0, no ZeroDivisionError;clamp01).refresh_locationsis now two-pass: pass 1 collects each district's rawunit_velocity(onecompute_market_metricsper district, no O(n²)); derivecity_reference_velocity = max(non-None velocities); pass 2 normalizes demand relative to it and upserts. SAVEPOINT-per-row + single commit + counters preserved._DEMAND_SATURATION_UPM. Added acity_reference_velocitylog line (so the next prod refresh surfaces the real max-velocity figure).Why relative > absolute: self-calibrating — always discriminates for any non-degenerate distribution, and never rots as the ЕКБ market grows (a fixed constant is wrong today and gets more wrong over time).
compute_location_indicesis write-path-only (called solely byrefresh_locations+ tests; the GET API reads the stored column), so no read-path/blast-radius impact. No schema/migration change (raw_unit_velocityis an in-memory dataclass carrier only).Test plan
uv run pytest tests/services/site_finder/test_locations.py -q→ 34 passed; fullsite_finder/dir → 366 passed (no regressions)ruff checkboth files → clean;mypy locations.py→ 0 errors in filetest_discriminates_realistic_spread_regression_948): velocities[60,120,180,300,450]→ distinct, strictly increasing, min < 0.2, max == 1.0 (the old/50clamp gave five 1.0s)refresh_locations()on prod, confirmdemand_indexnow spreads across the 8 districts instead of all-1.0; thecity_reference_velocitylog line will show the real max.Note
Semantic shift on the persisted column: stored
demand_indexnow means "relative to the busiest district this run" (comparable within a run), same propertyinfra_indexalready has. No frontend consumesdemand_indexyet, so no UI copy to update at this time.Refs #948