fix(sf-07): median_12m alias + UI 12mo hint #280

Merged
lekss361 merged 1 commit from fix/sf-07-median-12m-alias into main 2026-05-17 11:31:19 +00:00
2 changed files with 8 additions and 3 deletions

View file

@ -1188,16 +1188,20 @@ def analyze_parcel(
geom_wkt: str = geom_row["wkt"] # type: ignore[index] geom_wkt: str = geom_row["wkt"] # type: ignore[index]
# 2) District context — ближайший район ЕКБ # 2) District context — ближайший район ЕКБ
# median_price_per_m2: предпочитаем median_12m из mv_quarter_price_per_m2 (12 мес),
# fallback на ekb_districts.median_price_per_m2 (24 мес).
district_row = ( district_row = (
db.execute( db.execute(
text(""" text("""
SELECT district_name, SELECT d.district_name,
median_price_per_m2, COALESCE(mq.median_12m, d.median_price_per_m2) AS median_price_per_m2,
ST_Distance( ST_Distance(
d.geom::geography, d.geom::geography,
ST_Centroid(ST_GeomFromText(:wkt, 4326))::geography ST_Centroid(ST_GeomFromText(:wkt, 4326))::geography
) AS dist_to_center ) AS dist_to_center
FROM ekb_districts d FROM ekb_districts d
LEFT JOIN mv_quarter_price_per_m2 mq
ON mq.quarter_cad_number = REGEXP_REPLACE(:cad_num, ':[^:]+$', '')
WHERE ST_DWithin( WHERE ST_DWithin(
d.geom::geography, d.geom::geography,
ST_Centroid(ST_GeomFromText(:wkt, 4326))::geography, ST_Centroid(ST_GeomFromText(:wkt, 4326))::geography,
@ -1206,7 +1210,7 @@ def analyze_parcel(
ORDER BY dist_to_center ASC ORDER BY dist_to_center ASC
LIMIT 1 LIMIT 1
"""), """),
{"wkt": geom_wkt}, {"wkt": geom_wkt, "cad_num": cad_num},
) )
.mappings() .mappings()
.first() .first()

View file

@ -77,6 +77,7 @@ export function OverviewTab({ data, onIsochronesResult }: Props) {
<strong style={{ color: "#374151" }}> <strong style={{ color: "#374151" }}>
{(data.district.median_price_per_m2 / 1000).toFixed(0)} тыс /м² {(data.district.median_price_per_m2 / 1000).toFixed(0)} тыс /м²
</strong> </strong>
<span className="text-xs text-slate-500 ml-1">(12 мес)</span>
<span style={{ marginLeft: 12 }}> <span style={{ marginLeft: 12 }}>
{(data.district.dist_to_center / 1000).toFixed(1)} км до центра {(data.district.dist_to_center / 1000).toFixed(1)} км до центра
</span> </span>