pvforecast: Some values optional. Closes #292 (#293)
Some checks failed
pre-commit / pre-commit (push) Has been cancelled
Run Pytest on Pull Request / test (push) Has been cancelled

* 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 09e54b9989
commit 38968a941a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 11726 additions and 22 deletions

View File

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

View File

@ -34,7 +34,7 @@ class OptimizationParameters(BaseModel):
wechselrichter: WechselrichterParameters = WechselrichterParameters() wechselrichter: WechselrichterParameters = WechselrichterParameters()
eauto: Optional[EAutoParameters] eauto: Optional[EAutoParameters]
dishwasher: Optional[HomeApplianceParameters] = None dishwasher: Optional[HomeApplianceParameters] = None
temperature_forecast: Optional[list[float]] = Field( temperature_forecast: Optional[list[Optional[float]]] = Field(
default=None, default=None,
description="An array of floats representing the temperature forecast in degrees Celsius for different time intervals.", 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 power: float
sunTilt: float sunTilt: float
sunAzimuth: float sunAzimuth: float
temperature: float temperature: Optional[float]
relativehumidity_2m: float relativehumidity_2m: Optional[float]
windspeed_10m: float windspeed_10m: Optional[float]
class AkkudoktorForecast(BaseModel): class AkkudoktorForecast(BaseModel):
@ -109,8 +109,8 @@ def validate_pv_forecast_data(data: dict[str, Any]) -> Optional[str]:
class ForecastResponse(BaseModel): class ForecastResponse(BaseModel):
temperature: list[float] temperature: list[Optional[float]]
pvpower: list[float] pvpower: list[Optional[float]]
class ForecastData: class ForecastData:

View File

@ -89,7 +89,7 @@ class VisualizationReport:
def create_line_chart( def create_line_chart(
self, self,
start_hour: Optional[int], 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, title: str,
xlabel: str, xlabel: str,
ylabel: 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.""" """Test fetching temperature forecast for a specific date."""
forecast_temps = pv_forecast_instance.get_temperature_forecast_for_date(sample_forecast_start) forecast_temps = pv_forecast_instance.get_temperature_forecast_for_date(sample_forecast_start)
assert len(forecast_temps) == 24 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[1] == 6.5
assert forecast_temps[2] == 6.0 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 sample_forecast_start, end_date
) )
assert len(forecast_temps) == 48 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[1] == 6.5
assert forecast_temps[2] == 6.0 assert forecast_temps[2] == 6.0
@ -273,7 +273,7 @@ def test_timezone_behaviour(
# Test fetching temperature forecast for a specific date. # Test fetching temperature forecast for a specific date.
forecast_temps = pv_forecast_instance.get_temperature_forecast_for_date(sample_forecast_start) forecast_temps = pv_forecast_instance.get_temperature_forecast_for_date(sample_forecast_start)
assert len(forecast_temps) == 24 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[1] == 6.5
assert forecast_temps[2] == 6.0 assert forecast_temps[2] == 6.0

File diff suppressed because one or more lines are too long