fix(site-finder): compute nearest_top3 metro from osm_poi_ekb (#1667)
All checks were successful
CI / frontend-tests (push) Has been skipped
CI / openapi-codegen-check (push) Successful in 1m39s
CI / backend-tests (pull_request) Successful in 8m41s
CI / backend-tests (push) Successful in 8m40s
CI / frontend-tests (pull_request) Has been skipped
CI / changes (pull_request) Successful in 7s
CI / changes (push) Successful in 7s
CI / openapi-codegen-check (pull_request) Successful in 1m41s
All checks were successful
CI / frontend-tests (push) Has been skipped
CI / openapi-codegen-check (push) Successful in 1m39s
CI / backend-tests (pull_request) Successful in 8m41s
CI / backend-tests (push) Successful in 8m40s
CI / frontend-tests (pull_request) Has been skipped
CI / changes (pull_request) Successful in 7s
CI / changes (push) Successful in 7s
CI / openapi-codegen-check (pull_request) Successful in 1m41s
Replace bare metro_block placeholder ({"nearest_top3": None}, blocked on a
never-merged 22h metro scraper) with a direct KNN query against osm_poi_ekb
category='metro_stop' (loaded by poi_loader). Returns 3 nearest stations with
name + rounded distance_m; empty list when none nearby (vs None on error),
SAVEPOINT + try/except like adjacent SF-B5 blocks. No frontend consumer yet.
Closes #1667
This commit is contained in:
parent
e7901bc1e8
commit
7072d7803e
1 changed files with 38 additions and 2 deletions
|
|
@ -2127,8 +2127,44 @@ def analyze_parcel(
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning("red_lines_block query failed for %s: %s", cad_num, e)
|
logger.warning("red_lines_block query failed for %s: %s", cad_num, e)
|
||||||
|
|
||||||
# B5-4) Metro placeholder — заполнится после merge 22h metro scraper
|
# B5-4) Metro — ближайшие 3 станции метро к участку.
|
||||||
metro_block: dict[str, Any] = {"nearest_top3": None}
|
# Данные уже в osm_poi_ekb (category='metro_stop', грузятся poi_loader.py:44),
|
||||||
|
# скрапер не нужен — прямой KNN-запрос по geom <-> centroid участка.
|
||||||
|
# nearest_top3=[] (НЕ None) когда метро не найдено: отличаем "посчитано, рядом
|
||||||
|
# нет" от "не реализовано". None только при ошибке запроса.
|
||||||
|
metro_block: dict[str, Any] = {"nearest_top3": []}
|
||||||
|
try:
|
||||||
|
with db.begin_nested():
|
||||||
|
metro_rows = (
|
||||||
|
db.execute(
|
||||||
|
text("""
|
||||||
|
SELECT name,
|
||||||
|
ST_Distance(
|
||||||
|
m.geom::geography,
|
||||||
|
ST_Centroid(ST_GeomFromText(:wkt, 4326))::geography
|
||||||
|
) AS dist_m
|
||||||
|
FROM osm_poi_ekb m
|
||||||
|
WHERE m.category = 'metro_stop'
|
||||||
|
ORDER BY m.geom <-> ST_Centroid(ST_GeomFromText(:wkt, 4326))
|
||||||
|
LIMIT 3
|
||||||
|
"""),
|
||||||
|
{"wkt": geom_wkt},
|
||||||
|
)
|
||||||
|
.mappings()
|
||||||
|
.all()
|
||||||
|
)
|
||||||
|
metro_block = {
|
||||||
|
"nearest_top3": [
|
||||||
|
{
|
||||||
|
"name": mr["name"],
|
||||||
|
"distance_m": round(float(mr["dist_m"])) if mr["dist_m"] is not None else None,
|
||||||
|
}
|
||||||
|
for mr in metro_rows
|
||||||
|
]
|
||||||
|
}
|
||||||
|
except Exception as e:
|
||||||
|
logger.warning("metro_block query failed for %s: %s", cad_num, e)
|
||||||
|
metro_block = {"nearest_top3": None}
|
||||||
|
|
||||||
# B5-5) District price ranges из objective_lots (SF-B5)
|
# B5-5) District price ranges из objective_lots (SF-B5)
|
||||||
district_price_block: dict[str, Any] = {
|
district_price_block: dict[str, Any] = {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue