fix(sf-21b): _INLINE_VELOCITY_SQL weighted AVG (P0 follow-up) #291

Merged
lekss361 merged 1 commit from fix/sf-21b-inline-velocity-weighted into main 2026-05-17 14:02:44 +00:00

View file

@ -118,9 +118,16 @@ _INLINE_VELOCITY_SQL = text("""
ELSE crm.room_bucket
END AS room_bucket,
SUM(crm.deals_total_count) AS deals_window,
AVG(crm.deals_total_avg_area_m2) AS avg_area_m2,
AVG(crm.deals_total_avg_price_thousand_rub_per_m2)
* 1000.0 AS avg_price_per_m2_rub,
COALESCE(
SUM(crm.deals_total_avg_area_m2 * crm.deals_total_count)
/ NULLIF(SUM(crm.deals_total_count), 0),
0
)::numeric(10, 2) AS avg_area_m2,
COALESCE(
SUM(crm.deals_total_avg_price_thousand_rub_per_m2 * crm.deals_total_count)
/ NULLIF(SUM(crm.deals_total_count), 0),
0
)::numeric(12, 2) * 1000.0 AS avg_price_per_m2_rub,
array_agg(DISTINCT cm.domrf_obj_id) AS competitor_obj_ids,
COUNT(DISTINCT cm.domrf_obj_id) AS competitor_count,
MIN(crm.report_month) AS window_start,