gendesign/backend/app/services
Light1YT 888c225029 fix(tradein): per-bucket velocity formula + realistic срок продажи (#574)
Root causes fixed:

1. Bug_Velocity_Mix_Static: bucket_v = market_vel_pm × share/100 made all
   bucket velocities proportional to market share, so Σ bucket_v ≡ market_vel_pm
   regardless of mix. Moving a slider changed share_pct but not the aggregate
   срок продажи (velocity numerator and denominator both scaled with share).

2. Bug_Velocity_Unrealistic: rosreestr fallback used city-wide total_deals
   (region 66, ~3815 deals/24 mo = 159 кв/мес) divided by district-only
   competitors_weighted (~5-10 ЖК), yielding 16-32 кв/мес per project
   and срок ~0.7 мес instead of realistic months.

Changes:
- Add _n_active_zhk_region(db, region_code): COUNT DISTINCT active ЖК
  in the full region — used as city-wide denominator for rosreestr fallback.
  Lazy-cached to avoid duplicate DB round-trips.
- Add _velocity_baseline_per_bucket(db, ...): query objective_corpus_room_month
  grouped by room_bucket (same mapping as _elasticity_per_bucket_coef) to get
  per-bucket median velocity. Returns None when < 3 observations.
- Replace static bucket_market_velocities computation in recommend_mix:
  - Objective path: use _velocity_baseline_per_bucket per-bucket medians.
    Each bucket is an independent constant (not share-derived).
  - Rosreestr fallback: bucket_deals / months / N_active_region.
    N_active_region (200-400+ for EKB) replaces competitors_district (5-10),
    giving realistic per-project velocities (~0.1-0.6 кв/мес per bucket).
- Add bucket["velocity_source"] = "objective_per_bucket" | "rosreestr_fallback"
  for transparency in API response and UI warnings.
- Add scope["n_active_region"] for debugging.
- Add 19 unit tests in test_recommend_mix_velocity.py covering both bugs.
2026-05-28 20:19:20 +05:00
..
cadastre fix(#265 review): CRS 3857→4326 + stable zone_id hash + rename 102 + tx comment 2026-05-17 10:45:52 +03:00
etl feat(etl): fuzzy matcher v2 — pruned threshold 0.85→0.80 for objective mapping coverage 2026-05-17 16:28:20 +03:00
exporters feat(sf-b7): GET /parcels/{cad}/snapshot.pdf — 1-page WeasyPrint export (#334) 2026-05-17 21:11:03 +00:00
generative deploy.yml: sync compose+Caddyfile from git, reload caddy after up 2026-04-26 13:31:26 +03:00
photos fix ui lag 2026-04-27 20:26:55 +03:00
scrapers fix(tradein): backfill kn price_per_m2 via sale_graph + peer median (#573) (#625) 2026-05-28 13:50:45 +00:00
site_finder feat(sf-b6): GET /parcels/{cad}/poi-score — weighted top-7 (#333) 2026-05-17 21:11:25 +00:00
__init__.py init 2026-04-25 13:45:19 +03:00
analytics_queries.py fix(tradein): per-bucket velocity formula + realistic срок продажи (#574) 2026-05-28 20:19:20 +05:00
analytics_refresh.py fix(scrape): SQLAlchemy text() парсил ':00:' regex как named-param 2026-04-30 23:16:11 +03:00
job_settings.py fix(cadastre,nspd_sync): SQL syntax bugs surfaced by ekb_full v2 (#186) 2026-05-15 19:18:43 +03:00
objective_etl.py fix(worker): port objective_etl from psycopg2 → psycopg v3 2026-05-11 12:07:57 +03:00
objective_sync_config.py feat(objective): full sync pipeline + dynamic admin config 2026-05-10 19:54:15 +03:00