Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -70,10 +70,12 @@ def load_models():
|
|
| 70 |
# ---------- Эндпоинты ----------
|
| 71 |
|
| 72 |
|
|
|
|
|
|
|
| 73 |
@app.post("/forecast", response_model=ForecastResponse)
|
| 74 |
def forecast(req: ForecastRequest):
|
| 75 |
if not req.transactions:
|
| 76 |
-
raise HTTPException(400, "transactions is empty")
|
| 77 |
|
| 78 |
df = pd.DataFrame([t.dict() for t in req.transactions])
|
| 79 |
|
|
@@ -86,8 +88,14 @@ def forecast(req: ForecastRequest):
|
|
| 86 |
inc_fc = fit_and_forecast(inc, steps, freq, method=method)
|
| 87 |
exp_fc = fit_and_forecast(exp, steps, freq, method=method)
|
| 88 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
return ForecastResponse(
|
| 90 |
-
period_end=
|
| 91 |
income_forecast=[float(x) for x in inc_fc.values.tolist()],
|
| 92 |
expense_forecast=[float(x) for x in exp_fc.values.tolist()],
|
| 93 |
)
|
|
|
|
| 70 |
# ---------- Эндпоинты ----------
|
| 71 |
|
| 72 |
|
| 73 |
+
from datetime import datetime # вверху файла, если ещё не импортирован
|
| 74 |
+
|
| 75 |
@app.post("/forecast", response_model=ForecastResponse)
|
| 76 |
def forecast(req: ForecastRequest):
|
| 77 |
if not req.transactions:
|
| 78 |
+
raise HTTPException(status_code=400, detail="transactions is empty")
|
| 79 |
|
| 80 |
df = pd.DataFrame([t.dict() for t in req.transactions])
|
| 81 |
|
|
|
|
| 88 |
inc_fc = fit_and_forecast(inc, steps, freq, method=method)
|
| 89 |
exp_fc = fit_and_forecast(exp, steps, freq, method=method)
|
| 90 |
|
| 91 |
+
# Преобразуем индексы в RFC3339: "YYYY-MM-DDT00:00:00Z"
|
| 92 |
+
period_end = [
|
| 93 |
+
d.strftime("%Y-%m-%dT%H:%M:%SZ")
|
| 94 |
+
for d in inc_fc.index.to_pydatetime().tolist()
|
| 95 |
+
]
|
| 96 |
+
|
| 97 |
return ForecastResponse(
|
| 98 |
+
period_end=period_end,
|
| 99 |
income_forecast=[float(x) for x in inc_fc.values.tolist()],
|
| 100 |
expense_forecast=[float(x) for x in exp_fc.values.tolist()],
|
| 101 |
)
|