fix(site-finder): dedupe competitors — same domrf_kn_objects 3x snapshots bug
This commit is contained in:
parent
3aeda297ee
commit
a7d7dc9667
1 changed files with 11 additions and 4 deletions
|
|
@ -177,10 +177,18 @@ def analyze_parcel(
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
# 5) Конкуренты в радиусе 3 км из DOM.РФ
|
# 5) Конкуренты в радиусе 3 км из DOM.РФ.
|
||||||
|
# NB: domrf_kn_objects имеет ~3 snapshot per obj_id → DISTINCT ON по
|
||||||
|
# latest snapshot, иначе дубликаты ЖК в выдаче.
|
||||||
competitor_rows = (
|
competitor_rows = (
|
||||||
db.execute(
|
db.execute(
|
||||||
text("""
|
text("""
|
||||||
|
WITH latest_obj AS (
|
||||||
|
SELECT DISTINCT ON (obj_id) *
|
||||||
|
FROM domrf_kn_objects
|
||||||
|
WHERE latitude IS NOT NULL
|
||||||
|
ORDER BY obj_id, snapshot_date DESC NULLS LAST
|
||||||
|
)
|
||||||
SELECT obj_id,
|
SELECT obj_id,
|
||||||
comm_name,
|
comm_name,
|
||||||
dev_name,
|
dev_name,
|
||||||
|
|
@ -191,9 +199,8 @@ def analyze_parcel(
|
||||||
ST_SetSRID(ST_MakePoint(o.longitude, o.latitude), 4326)::geography,
|
ST_SetSRID(ST_MakePoint(o.longitude, o.latitude), 4326)::geography,
|
||||||
ST_Centroid(ST_GeomFromText(:wkt, 4326))::geography
|
ST_Centroid(ST_GeomFromText(:wkt, 4326))::geography
|
||||||
) AS distance_m
|
) AS distance_m
|
||||||
FROM domrf_kn_objects o
|
FROM latest_obj o
|
||||||
WHERE o.latitude IS NOT NULL
|
WHERE ST_DWithin(
|
||||||
AND ST_DWithin(
|
|
||||||
ST_SetSRID(ST_MakePoint(o.longitude, o.latitude), 4326)::geography,
|
ST_SetSRID(ST_MakePoint(o.longitude, o.latitude), 4326)::geography,
|
||||||
ST_Centroid(ST_GeomFromText(:wkt, 4326))::geography,
|
ST_Centroid(ST_GeomFromText(:wkt, 4326))::geography,
|
||||||
3000
|
3000
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue