fix FE 96h forecast
Some checks failed
CI and deploy / migration-check (push) Failing after 17s
CI and deploy / deploy (push) Has been skipped

This commit is contained in:
Dusan Vojacek
2026-04-19 21:40:55 +02:00
parent 70d306961a
commit ee4355f17f
4 changed files with 234 additions and 7 deletions

View File

@@ -481,3 +481,44 @@ async def get_site_forecast_pv(
if not isinstance(pv_b, list):
pv_b = []
return {"pv_a": pv_a, "pv_b": pv_b}
@router.get("/{site_id}/forecast/pv-slots")
async def get_site_forecast_pv_slots_range(
site_id: int,
db: Annotated[asyncpg.Pool, Depends(get_pg_pool)],
from_ts: datetime = Query(
...,
alias="from",
description="Začátek okna [from, to), typicky UTC zaokrouhlené na 15 min",
),
to_ts: datetime = Query(
...,
alias="to",
description="Konec polouzavřeného intervalu (max. cca 120 h za from)",
),
) -> dict[str, list[dict[str, Any]]]:
if to_ts <= from_ts:
raise HTTPException(status_code=422, detail="'to' must be after 'from'")
if to_ts - from_ts > timedelta(hours=120):
raise HTTPException(
status_code=422,
detail="Span between 'from' and 'to' must be at most 120 hours",
)
async with db.acquire() as conn:
site_ok = await conn.fetchval(
"SELECT EXISTS(SELECT 1 FROM ems.site WHERE id = $1)", site_id
)
if not site_ok:
raise HTTPException(status_code=404, detail="Site not found")
raw = await fetch_json(
conn,
"select ems.fn_forecast_pv_slots_range($1::int, $2::timestamptz, $3::timestamptz)",
site_id,
from_ts,
to_ts,
)
slots = raw if isinstance(raw, list) else []
if not isinstance(slots, list):
slots = []
return {"slots": slots}