Compare commits

..

No commits in common. "8022be6b2f2ddca300f6d4d9ba85e1a487204db3" and "16990af11c25af37ffdfa4302aff40968bbfc10d" have entirely different histories.

2 changed files with 9 additions and 7 deletions

View file

@ -138,7 +138,7 @@ def leads_stats(
WITH window_leads AS (
SELECT *
FROM prinzip_leads
WHERE created_at >= NOW() - make_interval(months => :m)
WHERE created_at >= NOW() - (:m || ' months')::interval
)
SELECT
(SELECT COUNT(*) FROM prinzip_leads) AS leads_total,

View file

@ -184,7 +184,8 @@ def quartirography(db: Session, source: str, region_id: int = 66) -> list[dict[s
-- ('2025-07-01' расширял «recent»-окно каждую неделю по мере
-- доливки ETL новых report_months перекос в сторону всё
-- более длинной истории). Тот же фикс, что #1203 и _BUCKET_SQL.
AND period_start_date >= NOW() - make_interval(months => :months_window)
AND period_start_date >= NOW()
- (:months_window || ' months')::INTERVAL
),
bucketed AS (
SELECT CASE
@ -1168,7 +1169,7 @@ def prinzip_funnel_monthly(db: Session, months: int = 24) -> list[dict[str, Any]
"""
SELECT month, source, leads, engaged, converted, conv_pct
FROM prinzip_funnel_monthly
WHERE month >= (CURRENT_DATE - make_interval(months => :months))::date
WHERE month >= (CURRENT_DATE - (:months || ' months')::interval)::date
ORDER BY month DESC, leads DESC
"""
),
@ -1202,7 +1203,7 @@ def prinzip_funnel_by_source(db: Session, months: int = 12) -> list[dict[str, An
SUM(converted) AS converted,
ROUND(100.0 * SUM(converted) / NULLIF(SUM(leads), 0), 2) AS conv_pct
FROM prinzip_funnel_monthly
WHERE month >= (CURRENT_DATE - make_interval(months => :months))::date
WHERE month >= (CURRENT_DATE - (:months || ' months')::interval)::date
GROUP BY source
ORDER BY leads DESC
"""
@ -1363,7 +1364,8 @@ _BUCKET_SQL = text(
AND deal_count > 0
AND (area / deal_count) BETWEEN 15 AND 200
AND price_per_sqm BETWEEN 30000 AND 1000000
AND period_start_date >= NOW() - make_interval(months => :months_window)
AND period_start_date >= NOW()
- (:months_window || ' months')::INTERVAL
),
bucketed AS (
SELECT CASE
@ -1993,7 +1995,7 @@ def _elasticity_coef(
{where_district}
{where_class}
AND crm.deals_total_avg_price_thousand_rub_per_m2 > 0
AND crm.report_month >= NOW() - make_interval(months => :ew)
AND crm.report_month >= NOW() - (:ew || ' months')::interval
)
SELECT
regr_slope(y, x) AS slope,
@ -2084,7 +2086,7 @@ def _elasticity_per_bucket_coef(
{where_class}
AND crm.deals_total_count > 0
AND crm.deals_total_avg_price_thousand_rub_per_m2 > 0
AND crm.report_month >= NOW() - make_interval(months => :ew)
AND crm.report_month >= NOW() - (:ew || ' months')::interval
)
SELECT bucket,
regr_slope(y, x) AS slope,