mirror of
https://github.com/Akkudoktor-EOS/EOS.git
synced 2025-04-19 08:55:15 +00:00
Prediction: Support manual update (#319)
* Provide /v1/prediction/update and /v1/prediction/update/{provider_id} as POST endpoints to update provider data. * Update description for deprecated endpoints how to use new API.
This commit is contained in:
parent
c0ea13d0f4
commit
69eac26885
@ -666,10 +666,131 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"/v1/prediction/update": {
|
||||||
|
"post": {
|
||||||
|
"summary": "Fastapi Prediction Update",
|
||||||
|
"description": "Update predictions for all providers.\n\nArgs:\n force_update: Update data even if it is already cached.\n Defaults to False.\n force_enable: Update data even if provider is disabled.\n Defaults to False.",
|
||||||
|
"operationId": "fastapi_prediction_update_v1_prediction_update_post",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"name": "force_update",
|
||||||
|
"in": "query",
|
||||||
|
"required": false,
|
||||||
|
"schema": {
|
||||||
|
"type": "boolean",
|
||||||
|
"default": false,
|
||||||
|
"title": "Force Update"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "force_enable",
|
||||||
|
"in": "query",
|
||||||
|
"required": false,
|
||||||
|
"schema": {
|
||||||
|
"type": "boolean",
|
||||||
|
"default": false,
|
||||||
|
"title": "Force Enable"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "Successful Response",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"422": {
|
||||||
|
"description": "Validation Error",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/HTTPValidationError"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/v1/prediction/update/{provider_id}": {
|
||||||
|
"post": {
|
||||||
|
"summary": "Fastapi Prediction Update Provider",
|
||||||
|
"description": "Update predictions for given provider ID.\n\nArgs:\n provider_id: ID of provider to update.\n force_update: Update data even if it is already cached.\n Defaults to False.\n force_enable: Update data even if provider is disabled.\n Defaults to False.",
|
||||||
|
"operationId": "fastapi_prediction_update_provider_v1_prediction_update__provider_id__post",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"name": "provider_id",
|
||||||
|
"in": "path",
|
||||||
|
"required": true,
|
||||||
|
"schema": {
|
||||||
|
"type": "string",
|
||||||
|
"title": "Provider Id"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "force_update",
|
||||||
|
"in": "query",
|
||||||
|
"required": false,
|
||||||
|
"schema": {
|
||||||
|
"anyOf": [
|
||||||
|
{
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "null"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"default": false,
|
||||||
|
"title": "Force Update"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "force_enable",
|
||||||
|
"in": "query",
|
||||||
|
"required": false,
|
||||||
|
"schema": {
|
||||||
|
"anyOf": [
|
||||||
|
{
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "null"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"default": false,
|
||||||
|
"title": "Force Enable"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "Successful Response",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"422": {
|
||||||
|
"description": "Validation Error",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/HTTPValidationError"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"/strompreis": {
|
"/strompreis": {
|
||||||
"get": {
|
"get": {
|
||||||
"summary": "Fastapi Strompreis",
|
"summary": "Fastapi Strompreis",
|
||||||
"description": "Deprecated: Electricity Market Price Prediction per Wh (\u20ac/Wh).\n\nNote:\n Use '/v1/prediction/list?key=elecprice_marketprice_wh' or\n '/v1/prediction/list?key=elecprice_marketprice_kwh' instead.",
|
"description": "Deprecated: Electricity Market Price Prediction per Wh (\u20ac/Wh).\n\nNote:\n Set ElecPriceAkkudoktor as elecprice_provider, then update data with\n '/v1/prediction/update'\n and then request data with\n '/v1/prediction/list?key=elecprice_marketprice_wh' or\n '/v1/prediction/list?key=elecprice_marketprice_kwh' instead.",
|
||||||
"operationId": "fastapi_strompreis_strompreis_get",
|
"operationId": "fastapi_strompreis_strompreis_get",
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
@ -735,7 +856,7 @@
|
|||||||
"/gesamtlast_simple": {
|
"/gesamtlast_simple": {
|
||||||
"get": {
|
"get": {
|
||||||
"summary": "Fastapi Gesamtlast Simple",
|
"summary": "Fastapi Gesamtlast Simple",
|
||||||
"description": "Deprecated: Total Load Prediction.\n\nEndpoint to handle total load prediction.\n\nNote:\n Use '/v1/prediction/list?key=load_mean' instead.",
|
"description": "Deprecated: Total Load Prediction.\n\nEndpoint to handle total load prediction.\n\nNote:\n Set LoadAkkudoktor as load_provider, then update data with\n '/v1/prediction/update'\n and then request data with\n '/v1/prediction/list?key=load_mean' instead.",
|
||||||
"operationId": "fastapi_gesamtlast_simple_gesamtlast_simple_get",
|
"operationId": "fastapi_gesamtlast_simple_gesamtlast_simple_get",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
@ -779,6 +900,7 @@
|
|||||||
"/pvforecast": {
|
"/pvforecast": {
|
||||||
"get": {
|
"get": {
|
||||||
"summary": "Fastapi Pvforecast",
|
"summary": "Fastapi Pvforecast",
|
||||||
|
"description": "Deprecated: PV Forecast Prediction.\n\nEndpoint to handle PV forecast prediction.\n\nNote:\n Set PVForecastAkkudoktor as pvforecast_provider, then update data with\n '/v1/prediction/update'\n and then request data with\n '/v1/prediction/list?key=pvforecast_ac_power' and\n '/v1/prediction/list?key=pvforecastakkudoktor_temp_air' instead.",
|
||||||
"operationId": "fastapi_pvforecast_pvforecast_get",
|
"operationId": "fastapi_pvforecast_pvforecast_get",
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
|
@ -1645,7 +1645,7 @@ class DataContainer(SingletonMixin, DataBase, MutableMapping):
|
|||||||
force_enable (bool, optional): If True, forces the update even if a provider is disabled.
|
force_enable (bool, optional): If True, forces the update even if a provider is disabled.
|
||||||
force_update (bool, optional): If True, forces the providers to update the data even if still cached.
|
force_update (bool, optional): If True, forces the providers to update the data even if still cached.
|
||||||
"""
|
"""
|
||||||
for provider in self.enabled_providers:
|
for provider in self.providers:
|
||||||
provider.update_data(force_enable=force_enable, force_update=force_update)
|
provider.update_data(force_enable=force_enable, force_update=force_update)
|
||||||
|
|
||||||
def key_to_series(
|
def key_to_series(
|
||||||
|
@ -391,13 +391,57 @@ def fastapi_prediction_list_get(
|
|||||||
return prediction_list
|
return prediction_list
|
||||||
|
|
||||||
|
|
||||||
|
@app.post("/v1/prediction/update")
|
||||||
|
def fastapi_prediction_update(force_update: bool = False, force_enable: bool = False) -> Response:
|
||||||
|
"""Update predictions for all providers.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
force_update: Update data even if it is already cached.
|
||||||
|
Defaults to False.
|
||||||
|
force_enable: Update data even if provider is disabled.
|
||||||
|
Defaults to False.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
prediction_eos.update_data(force_update=force_update, force_enable=force_enable)
|
||||||
|
except Exception as e:
|
||||||
|
raise HTTPException(status_code=400, detail=f"Error while trying to update provider: {e}")
|
||||||
|
return Response()
|
||||||
|
|
||||||
|
|
||||||
|
@app.post("/v1/prediction/update/{provider_id}")
|
||||||
|
def fastapi_prediction_update_provider(
|
||||||
|
provider_id: str, force_update: Optional[bool] = False, force_enable: Optional[bool] = False
|
||||||
|
) -> Response:
|
||||||
|
"""Update predictions for given provider ID.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
provider_id: ID of provider to update.
|
||||||
|
force_update: Update data even if it is already cached.
|
||||||
|
Defaults to False.
|
||||||
|
force_enable: Update data even if provider is disabled.
|
||||||
|
Defaults to False.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
provider = prediction_eos.provider_by_id(provider_id)
|
||||||
|
except ValueError:
|
||||||
|
raise HTTPException(status_code=404, detail=f"Provider '{provider_id}' not found.")
|
||||||
|
try:
|
||||||
|
provider.update_data(force_update=force_update, force_enable=force_enable)
|
||||||
|
except Exception as e:
|
||||||
|
raise HTTPException(status_code=400, detail=f"Error while trying to update provider: {e}")
|
||||||
|
return Response()
|
||||||
|
|
||||||
|
|
||||||
@app.get("/strompreis")
|
@app.get("/strompreis")
|
||||||
def fastapi_strompreis() -> list[float]:
|
def fastapi_strompreis() -> list[float]:
|
||||||
"""Deprecated: Electricity Market Price Prediction per Wh (€/Wh).
|
"""Deprecated: Electricity Market Price Prediction per Wh (€/Wh).
|
||||||
|
|
||||||
Note:
|
Note:
|
||||||
Use '/v1/prediction/list?key=elecprice_marketprice_wh' or
|
Set ElecPriceAkkudoktor as elecprice_provider, then update data with
|
||||||
'/v1/prediction/list?key=elecprice_marketprice_kwh' instead.
|
'/v1/prediction/update'
|
||||||
|
and then request data with
|
||||||
|
'/v1/prediction/list?key=elecprice_marketprice_wh' or
|
||||||
|
'/v1/prediction/list?key=elecprice_marketprice_kwh' instead.
|
||||||
"""
|
"""
|
||||||
settings = SettingsEOS(
|
settings = SettingsEOS(
|
||||||
elecprice_provider="ElecPriceAkkudoktor",
|
elecprice_provider="ElecPriceAkkudoktor",
|
||||||
@ -480,7 +524,10 @@ def fastapi_gesamtlast_simple(year_energy: float) -> list[float]:
|
|||||||
Endpoint to handle total load prediction.
|
Endpoint to handle total load prediction.
|
||||||
|
|
||||||
Note:
|
Note:
|
||||||
Use '/v1/prediction/list?key=load_mean' instead.
|
Set LoadAkkudoktor as load_provider, then update data with
|
||||||
|
'/v1/prediction/update'
|
||||||
|
and then request data with
|
||||||
|
'/v1/prediction/list?key=load_mean' instead.
|
||||||
"""
|
"""
|
||||||
settings = SettingsEOS(
|
settings = SettingsEOS(
|
||||||
load_provider="LoadAkkudoktor",
|
load_provider="LoadAkkudoktor",
|
||||||
@ -507,6 +554,17 @@ class ForecastResponse(PydanticBaseModel):
|
|||||||
|
|
||||||
@app.get("/pvforecast")
|
@app.get("/pvforecast")
|
||||||
def fastapi_pvforecast() -> ForecastResponse:
|
def fastapi_pvforecast() -> ForecastResponse:
|
||||||
|
"""Deprecated: PV Forecast Prediction.
|
||||||
|
|
||||||
|
Endpoint to handle PV forecast prediction.
|
||||||
|
|
||||||
|
Note:
|
||||||
|
Set PVForecastAkkudoktor as pvforecast_provider, then update data with
|
||||||
|
'/v1/prediction/update'
|
||||||
|
and then request data with
|
||||||
|
'/v1/prediction/list?key=pvforecast_ac_power' and
|
||||||
|
'/v1/prediction/list?key=pvforecastakkudoktor_temp_air' instead.
|
||||||
|
"""
|
||||||
###############
|
###############
|
||||||
# PV Forecast
|
# PV Forecast
|
||||||
###############
|
###############
|
||||||
|
Loading…
x
Reference in New Issue
Block a user