diff --git a/backend/app/ml/feature_engineering.py b/backend/app/ml/feature_engineering.py index bbcd261..6b99872 100644 --- a/backend/app/ml/feature_engineering.py +++ b/backend/app/ml/feature_engineering.py @@ -1,5 +1,7 @@ from __future__ import annotations +from datetime import date, timedelta + import pandas as pd from sqlalchemy import text from sqlalchemy.ext.asyncio import AsyncSession @@ -97,6 +99,7 @@ async def get_portfolio_monthly_returns(db: AsyncSession, user_id: str) -> pd.Da async def get_daily_cash_flow(db: AsyncSession, user_id: str, days: int = 90) -> pd.DataFrame: + cutoff = date.today() - timedelta(days=days) result = await db.execute(text(""" SELECT t.date::date AS ds, @@ -107,10 +110,10 @@ async def get_daily_cash_flow(db: AsyncSession, user_id: str, days: int = 90) -> AND t.deleted_at IS NULL AND t.status != 'void' AND t.type IN ('income', 'expense') - AND t.date >= CURRENT_DATE - :days + AND t.date >= :cutoff GROUP BY t.date ORDER BY t.date ASC - """), {"uid": str(user_id), "days": days}) + """), {"uid": str(user_id), "cutoff": cutoff}) rows = result.fetchall() if not rows: return pd.DataFrame(columns=["ds", "inflow", "outflow"])