mirror of
https://github.com/Akkudoktor-EOS/EOS.git
synced 2026-11-25 23:16:18 +01:00
feat(pvforecast): add adaptive per-plane PV learning and diagnostics (#1422)
PV arrays with different orientations and curtailment need separate plant calibration and weather correction. This opt-in provider publishes normal EOS AC/DC forecast keys at 15-minute resolution. - Preserve daily per-plane energy/shape calibration and validated short-term local/trend selection. Curtailment-sensitive arrays require a fresh release flag or an explicitly configured learning guard. - Add switchable empirical solar-angle response relative to separate eligible reference arrays, removing their common weather error. This learns angular residuals, not physical angles or a measured geometric horizon. - Archive actually received weather model inputs, first local receipt and frozen per-member PV candidates. Returned past weather is excluded; unknown source issuance remains explicit. Learn model weights and forecast-regime bias separately at 2–6, 6–24 and 24–48 hours. - New long-horizon candidates remain in shadow until their genuinely issued outputs improve equal-day MAE by the configured margin, win on at least 60% of validation days and pass a matched-support energy-bias guard. Insufficient evidence retains calibration. Daily yields still require complete local days, including DST. - Expose fitted parameters, independent training/validation day counts, errors, selected methods and persistence in the existing status API, with additional normal prediction keys for Grafana. Retain physical DC through angular/weather corrections an enforce individual inverter AC limits. Co-authored-by: Normann <github@koldrack.com> Co-authored-by: Christin <chrissi@von-perbandt.de> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: YMT <yn276364@dal.ca> Co-authored-by: sarankumar1325 <120080287+sarankumar1325@users.noreply.github.com>
This commit is contained in:
co-authored by
Normann
Christin
Claude Opus 5.5
YMT
sarankumar1325
parent
298d46a527
commit
f804d48072
@@ -80,6 +80,7 @@ from akkudoktoreos.server.rest.error import (
|
||||
register_problem_handlers,
|
||||
)
|
||||
from akkudoktoreos.server.rest.measurement import router as measurement_router
|
||||
from akkudoktoreos.server.rest.pvakkuadaptrest import router as pvadaptive_router
|
||||
from akkudoktoreos.server.rest.starteosdash import supervise_eosdash
|
||||
from akkudoktoreos.server.retentionmanager import RetentionManager
|
||||
from akkudoktoreos.server.server import (
|
||||
@@ -262,6 +263,7 @@ The genetic optimization API fields were renamed from German to English. For bac
|
||||
# ----------------------
|
||||
|
||||
app.include_router(measurement_router)
|
||||
app.include_router(pvadaptive_router)
|
||||
|
||||
register_problem_handlers(app)
|
||||
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
"""Learning status, issued comparisons and bounded raw PV ingestion for Grafana."""
|
||||
|
||||
import asyncio
|
||||
from typing import Any
|
||||
|
||||
import pandas as pd
|
||||
from fastapi import APIRouter, Body, HTTPException, Query
|
||||
|
||||
from akkudoktoreos.core.coreabc import get_prediction
|
||||
from akkudoktoreos.measurement.quality import MeasurementSample
|
||||
from akkudoktoreos.prediction.pvakkuadapt import (
|
||||
PVForecastAdaptiveAkkudoktor,
|
||||
)
|
||||
|
||||
router = APIRouter(prefix="/v1/prediction/pv-adaptive", tags=["prediction"])
|
||||
|
||||
|
||||
def provider() -> PVForecastAdaptiveAkkudoktor:
|
||||
"""Resolve the registered singleton without creating a separate predictor."""
|
||||
return next(
|
||||
p for p in get_prediction().providers if isinstance(p, PVForecastAdaptiveAkkudoktor)
|
||||
)
|
||||
|
||||
|
||||
@router.get("/status")
|
||||
async def status() -> dict[str, Any]:
|
||||
"""Status contains honest cold-start counts and matched per-lead error metrics."""
|
||||
store = await asyncio.to_thread(provider().store)
|
||||
value = await asyncio.to_thread(store.metadata, "status")
|
||||
return value or dict(
|
||||
state="initializing",
|
||||
state_code=0,
|
||||
training_days=0,
|
||||
trained_leads=0,
|
||||
message="Noch keine adaptive Prognose ausgegeben.",
|
||||
metrics=[],
|
||||
)
|
||||
|
||||
|
||||
@router.put("/samples")
|
||||
async def samples(values: list[MeasurementSample] = Body(max_length=10000)) -> dict[str, int]:
|
||||
"""Store original power readings in the bounded adaptive archive, without zero filling."""
|
||||
instance = provider()
|
||||
allowed = instance._sample_keys()
|
||||
if any(sample.key not in allowed for sample in values):
|
||||
raise HTTPException(422, "Measurement key is not assigned to an adaptive PV string.")
|
||||
if any(sample.value is not None and sample.value < 0 for sample in values):
|
||||
raise HTTPException(422, "PV production must not be negative.")
|
||||
flags = {
|
||||
plane.curtailment_key for plane in instance._learning_planes() if plane.curtailment_key
|
||||
}
|
||||
if any(sample.key in flags and sample.value not in (None, 0, 1) for sample in values):
|
||||
raise HTTPException(
|
||||
422, "Curtailment flags must be 0 (unrestricted), 1 (curtailed), or null."
|
||||
)
|
||||
try:
|
||||
store = await asyncio.to_thread(instance.store)
|
||||
updated = await asyncio.to_thread(store.import_samples, values, pd.Timestamp.now(tz="UTC"))
|
||||
return dict(updated=updated)
|
||||
except ValueError as exc:
|
||||
raise HTTPException(422, str(exc)) from exc
|
||||
|
||||
|
||||
@router.get("/comparisons")
|
||||
async def comparisons(
|
||||
days: int = Query(default=2, ge=1, le=30),
|
||||
limit: int = Query(default=2000, ge=1, le=20000),
|
||||
since_ms: int = Query(default=0, ge=0),
|
||||
) -> list[dict[str, Any]]:
|
||||
"""Export genuinely issued forecasts with later measured truth, issuance and lead."""
|
||||
instance = provider()
|
||||
store = await asyncio.to_thread(instance.store)
|
||||
state = await asyncio.to_thread(store.metadata, "status")
|
||||
if not state:
|
||||
return []
|
||||
now = pd.Timestamp.now(tz="UTC")
|
||||
return await asyncio.to_thread(
|
||||
store.comparisons,
|
||||
state["signature"],
|
||||
store.milliseconds(now - pd.Timedelta(days=days)),
|
||||
store.milliseconds(now),
|
||||
limit,
|
||||
since_ms,
|
||||
)
|
||||
|
||||
|
||||
@router.get("/latest")
|
||||
async def latest() -> list[dict[str, Any]]:
|
||||
"""Latest complete output curve; validation uses the separate immutable archive."""
|
||||
instance = provider()
|
||||
store = await asyncio.to_thread(instance.store)
|
||||
start = pd.Timestamp.now(tz=instance.config.general.timezone).normalize()
|
||||
return await asyncio.to_thread(store.latest, store.milliseconds(start))
|
||||
Reference in New Issue
Block a user