feat(parcels): competitors endpoint (Forgejo #112 Phase 1 backend) #191
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#191
Loading…
Add table
Reference in a new issue
No description provided.
Delete branch "feat/112-competitors-backend"
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
Active competitors analysis для site-finder (priority/high от Макса).
Endpoint
POST /api/v1/parcels/{cad_num}/competitorsBody:
{radius_km (0.1-1.5), time_window (month/quarter/year), obj_class_filter, exclude_obj_ids}Returns list of competitors с distance_m, velocity_per_month, obj_class, lat/lng, is_active flag.
Schema correctness (4 critical fixed via review)
snapshot_date(NOTsnapshot_at) вdomrf_kn_objectsflat_count(NOTflats_total/flats_sold) — sold_pct return nulldomrf_kn_sale_graph(stale до 2026-01) →objective_corpus_room_monthчерезobjective_complex_mappingJOIN, паттерн как вvelocity.py(coverage ~2.5%)domrf_kn_flats.status(NOTdeal_status)Files
schemas/parcel.py: 4 new Pydantic models, radius_kmge=0.1services/site_finder/competitors.pyNEW (~150 lines):get_competitors()+ SQL CTEs (latest_obj, velocity, distances, avg_price)api/v1/parcels.py: POST endpoint, no exc leak in 500tests/api/v1/test_parcel_competitors.pyNEW: 9 mock testsTest plan
Depends on: nothing (independent of #115).
Blocks: #113 (best layouts needs competitor obj_ids).
Closes part of #112 (Phase 1 backend). Frontend separate PR.
Auto-review — verdict: approve ✅
CI ✅ (backend 1m12s + frontend 2m14s).
Schema verification: ALL 4 claims CORRECT
snapshot_dateвlatest_objCTE ✅flat_count→ mappedflats_total, sold/pct=null ✅objective_corpus_room_month+objective_complex_mappingJOIN ✅ (паттерн какvelocity.py)status = 'sold'в_AVG_PRICE_SQL✅Security: clean
cad_num,obj_class_filter,radius_m— all через bound paramsexclude_obj_idsфильтруется в Python (set), не SQLwindow_intervalстроится из hardcoded dict (time_window_months: float), не user inputMinor (не блокирующие, fix later)
competitors.py:244—distancesCTE computes ST_Distance для ВСЕХ rows вlatest_obj, фильтруетWHERE distance_m <= :radius_mв outer SELECT. БезST_DWithinpre-filter — full-table scan на каждый запрос. Phase 1 acceptable (dataset bounded), но для Phase 2/scaling → заменить distances CTE наST_DWithin(geog, ref_point::geography, :radius_m)— index-assisted.competitors.py:408— полеweighted_avg_velocityэто арифметическое mean (total / n), не weighted. Misleading name. Rename →avg_velocity_per_monthв follow-up.parcel.py:97—velocity_per_month: floatnon-nullable, в сервисеCOALESCE(v.velocity_per_month, 0.0). Consistent но добавь короткий comment про COALESCE guarantee.Positive
text()с bound paramstry/except Exceptionwraps service call в endpoint → no exc leak в 500Anyв public response modelsRecommended action
Merge approved. Follow-up issue:
ST_DWithinradius pre-filter before scaling.