feat(velocity): migrate D2 sales source → objective_corpus_room_month (#156) #157

Closed
lekss361 wants to merge 4 commits from feat/migrate-velocity-to-objective-data into main
lekss361 commented 2026-05-15 06:15:54 +00:00 (Migrated from github.com)

Why

D2 velocity-score returns null для prod cad 66:41:0204016:10 — `domrf_kn_sale_graph` table не обновлялся с 2026-01 (4+ мес stale).

`objective_corpus_room_month` — weekly updated через Objective API (Tuesday cron). Newest data May 2026 vs sale_graph Jan 2026.

Source Newest month Rows w/ deals (6мо)
objective_corpus_room_month 2026-05-01 3486
domrf_kn_sale_graph 2026-01-01 849

Changes

velocity.py — 2 SQL queries migrated

  • sales_rows: `sale_graph WHERE obj_id ANY` → JOIN `objective_complex_mapping` → `objective_corpus_room_month.project_name`
  • _get_ekb_median: same migration, percentile from objective per_complex velocity
  • Both wrapped в `with db.begin_nested()` (SAVEPOINT preserved)

analytics_queries.py — 4 functions migrated

Function Decision
`_velocity_baseline` MIGRATE — core recommend_mix
`_district_velocity_trend` MIGRATE — H1/H2 2025
`_elasticity_coef` MIGRATE — log-scale invariant
`_elasticity_per_bucket_coef` MIGRATE — room_bucket native
`object_sale_graph` ⏸ KEEP — admin history view
`prinzip_objects_with_velocity` ⏸ KEEP — admin sparkline (separate task)

Frontend label

`velocity_source: "sale_graph"` → `"objective"` (line 2068)

Coverage caveat

`objective_complex_mapping` has 114 mappings (2.5% of 4548 ДомРФ ЖК). Для test cad 66:41:0204016:10 — 3 из 32 конкурентов mapped → velocity will return result с `confidence='low'` (better than null).

Future task: expand mapping coverage (auto-match by name/coords/address).

E2E test after merge

```bash
curl -X POST "https://gendsgn.ru/api/v1/parcels/66:41:0204016:10/analyze?profile_user_id=admin"

expect: velocity field non-null, competitors_count > 0, velocity_score 0..1

```

Vault

`code/modules/Module_Velocity_Service.md` updated.

Closes #156

## Why D2 velocity-score returns null для prod cad 66:41:0204016:10 — \`domrf_kn_sale_graph\` table не обновлялся с **2026-01** (4+ мес stale). \`objective_corpus_room_month\` — weekly updated через Objective API (Tuesday cron). Newest data **May 2026** vs sale_graph Jan 2026. | Source | Newest month | Rows w/ deals (6мо) | |---|---|---| | objective_corpus_room_month | 2026-05-01 | 3486 | | domrf_kn_sale_graph | 2026-01-01 | 849 | ## Changes ### velocity.py — 2 SQL queries migrated - **sales_rows**: \`sale_graph WHERE obj_id ANY\` → JOIN \`objective_complex_mapping\` → \`objective_corpus_room_month.project_name\` - **_get_ekb_median**: same migration, percentile from objective per_complex velocity - Both wrapped в \`with db.begin_nested()\` (SAVEPOINT preserved) ### analytics_queries.py — 4 functions migrated | Function | Decision | |---|---| | \`_velocity_baseline\` | ✅ MIGRATE — core recommend_mix | | \`_district_velocity_trend\` | ✅ MIGRATE — H1/H2 2025 | | \`_elasticity_coef\` | ✅ MIGRATE — log-scale invariant | | \`_elasticity_per_bucket_coef\` | ✅ MIGRATE — room_bucket native | | \`object_sale_graph\` | ⏸ KEEP — admin history view | | \`prinzip_objects_with_velocity\` | ⏸ KEEP — admin sparkline (separate task) | ### Frontend label \`velocity_source: \"sale_graph\"\` → \`\"objective\"\` (line 2068) ## Coverage caveat \`objective_complex_mapping\` has **114 mappings** (2.5% of 4548 ДомРФ ЖК). Для test cad 66:41:0204016:10 — 3 из 32 конкурентов mapped → velocity will return result с \`confidence='low'\` (better than null). Future task: expand mapping coverage (auto-match by name/coords/address). ## E2E test after merge \`\`\`bash curl -X POST \"https://gendsgn.ru/api/v1/parcels/66:41:0204016:10/analyze?profile_user_id=admin\" # expect: velocity field non-null, competitors_count > 0, velocity_score 0..1 \`\`\` ## Vault \`code/modules/Module_Velocity_Service.md\` updated. Closes #156
lekss361 commented 2026-05-15 06:24:30 +00:00 (Migrated from github.com)

Closing — history был messy после squash #155 merged on main. Recreating clean branch без duplicate commits.

Closing — history был messy после squash #155 merged on main. Recreating clean branch без duplicate commits.

Pull request closed

Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
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#157
No description provided.