pvforecast: Some values optional. Closes #292 (#293)

* temperature, relativehumidity_2m, windspeed_10m can be null
 * prettify pv_forecast_input_1.json (and add null value)
This commit is contained in:
Dominique Lasserre 2024-12-29 16:43:37 +01:00 committed by GitHub
parent 4f51c891d3
commit f195edb07d
6 changed files with 11726 additions and 22 deletions

View File

@ -307,7 +307,9 @@
}
},
"type": "object",
"required": ["kapazitaet_wh"],
"required": [
"kapazitaet_wh"
],
"title": "EAutoParameters"
},
"EAutoResult": {
@ -439,21 +441,38 @@
"properties": {
"temperature": {
"items": {
"type": "number"
"anyOf": [
{
"type": "number"
},
{
"type": "null"
}
]
},
"type": "array",
"title": "Temperature"
},
"pvpower": {
"items": {
"type": "number"
"anyOf": [
{
"type": "number"
},
{
"type": "null"
}
]
},
"type": "array",
"title": "Pvpower"
}
},
"type": "object",
"required": ["temperature", "pvpower"],
"required": [
"temperature",
"pvpower"
],
"title": "ForecastResponse"
},
"GesamtlastRequest": {
@ -475,7 +494,11 @@
}
},
"type": "object",
"required": ["year_energy", "measured_data", "hours"],
"required": [
"year_energy",
"measured_data",
"hours"
],
"title": "GesamtlastRequest"
},
"HTTPValidationError": {
@ -507,7 +530,10 @@
}
},
"type": "object",
"required": ["consumption_wh", "duration_h"],
"required": [
"consumption_wh",
"duration_h"
],
"title": "HomeApplianceParameters"
},
"OptimizationParameters": {
@ -548,7 +574,14 @@
"anyOf": [
{
"items": {
"type": "number"
"anyOf": [
{
"type": "number"
},
{
"type": "null"
}
]
},
"type": "array"
},
@ -576,7 +609,11 @@
}
},
"type": "object",
"required": ["ems", "pv_akku", "eauto"],
"required": [
"ems",
"pv_akku",
"eauto"
],
"title": "OptimizationParameters"
},
"OptimizeResponse": {
@ -735,7 +772,9 @@
}
},
"type": "object",
"required": ["kapazitaet_wh"],
"required": [
"kapazitaet_wh"
],
"title": "PVAkkuParameters"
},
"SimulationResult": {
@ -957,7 +996,11 @@
}
},
"type": "object",
"required": ["loc", "msg", "type"],
"required": [
"loc",
"msg",
"type"
],
"title": "ValidationError"
},
"WechselrichterParameters": {
@ -974,4 +1017,4 @@
}
}
}
}
}

View File

@ -34,7 +34,7 @@ class OptimizationParameters(BaseModel):
wechselrichter: WechselrichterParameters = WechselrichterParameters()
eauto: Optional[EAutoParameters]
dishwasher: Optional[HomeApplianceParameters] = None
temperature_forecast: Optional[list[float]] = Field(
temperature_forecast: Optional[list[Optional[float]]] = Field(
default=None,
description="An array of floats representing the temperature forecast in degrees Celsius for different time intervals.",
)

View File

@ -80,9 +80,9 @@ class AkkudoktorForecastValue(BaseModel):
power: float
sunTilt: float
sunAzimuth: float
temperature: float
relativehumidity_2m: float
windspeed_10m: float
temperature: Optional[float]
relativehumidity_2m: Optional[float]
windspeed_10m: Optional[float]
class AkkudoktorForecast(BaseModel):
@ -109,8 +109,8 @@ def validate_pv_forecast_data(data: dict[str, Any]) -> Optional[str]:
class ForecastResponse(BaseModel):
temperature: list[float]
pvpower: list[float]
temperature: list[Optional[float]]
pvpower: list[Optional[float]]
class ForecastData:

View File

@ -89,7 +89,7 @@ class VisualizationReport:
def create_line_chart(
self,
start_hour: Optional[int],
y_list: list[Union[np.ndarray, list[float]]],
y_list: list[Union[np.ndarray, list[Optional[float]], list[float]]],
title: str,
xlabel: str,
ylabel: str,

View File

@ -138,7 +138,7 @@ def test_get_temperature_forecast_for_date(pv_forecast_instance, sample_forecast
"""Test fetching temperature forecast for a specific date."""
forecast_temps = pv_forecast_instance.get_temperature_forecast_for_date(sample_forecast_start)
assert len(forecast_temps) == 24
assert forecast_temps[0] == 7.0
assert forecast_temps[0] is None
assert forecast_temps[1] == 6.5
assert forecast_temps[2] == 6.0
@ -162,7 +162,7 @@ def test_get_temperature_for_date_range(pv_forecast_instance, sample_forecast_st
sample_forecast_start, end_date
)
assert len(forecast_temps) == 48
assert forecast_temps[0] == 7.0
assert forecast_temps[0] is None
assert forecast_temps[1] == 6.5
assert forecast_temps[2] == 6.0
@ -273,7 +273,7 @@ def test_timezone_behaviour(
# Test fetching temperature forecast for a specific date.
forecast_temps = pv_forecast_instance.get_temperature_forecast_for_date(sample_forecast_start)
assert len(forecast_temps) == 24
assert forecast_temps[0] == 7.0
assert forecast_temps[0] is None
assert forecast_temps[1] == 6.5
assert forecast_temps[2] == 6.0

File diff suppressed because one or more lines are too long