mirror of
https://github.com/Akkudoktor-EOS/EOS.git
synced 2026-07-31 14:16:11 +00:00
Bump Version / Bump Version Workflow (push) Waiting to run
CodeQL Advanced / Analyze (actions) (push) Waiting to run
CodeQL Advanced / Analyze (python) (push) Waiting to run
docker-build / platform-excludes (push) Waiting to run
docker-build / build (push) Blocked by required conditions
docker-build / merge (push) Blocked by required conditions
pre-commit / pre-commit (push) Waiting to run
Run Pytest on Pull Request / test (push) Waiting to run
Ensure the deprecated endpoints get /strompreis, post /gesamtlast, get /gesamtlast_simple,
get /pvforecast to work on 1-hour intervalls even if the prediction provides 15-minutes
intervall data. This keeps the interface compliant to the legacy functionality.
Besides this adaptations several other improvements and fixes are included in this PR.
* feat: extend data management method key_to array by resample_method
One can now define the resample method on how to aggregate the values in an interval
for resampling. Three methods are provided:
- "first": Use the first value in each interval.
- "mean": Compute the arithmetic mean of all samples in each interval.
- "interval_mean": Compute the time-weighted mean assuming each value remains valid
until the next timestamp (piecewise-constant signal).
* feat: extend the get /v1/prediction/dataframe endpoint with resampling parameters
Make all parameters for resampling available at the endpoint.
* feat: extend the get /v1/prediction/list endpoint with resampling parameters
Make all parameters for resampling available at the endpoint.
* feat: add new delete /v1/prediction/range endpoint
The endpoint allows to delete prediction values for a given time span.
* fix: adapt for PVForecastAkkudoktor server side cache handling
/api.akkudoktor/forecast does it's own caching on requests. Call it with slightly
randomized request values to avoid getting cached values in the case we need fresh
data. The requests are anyway rate limited to one request per hour on our side.
* chore: add core.types
This module centralizes reusable type definitions shared across multiple
packages. Defining common types here avoids duplication of complex type
annotations (such as Literal aliases), ensures consistent typing across the
code base, and helps prevent circular import dependencies between modules.
* chore: extend cache testing
* chore: add system test for deprecated /strompreis endpoint
* chore: add unit test module for server endpoints
Add a new test module to do unit tests on server endpoints. First test added
for deprecated get /strompreis endpoint.
Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
74 lines
1.9 KiB
Python
74 lines
1.9 KiB
Python
"""Test server endpoints directly calling the endpoint function (unit tests)."""
|
|
|
|
import numpy as np
|
|
import pytest
|
|
|
|
from akkudoktoreos.server.eos import fastapi_strompreis
|
|
from akkudoktoreos.utils.datetimeutil import to_duration
|
|
|
|
|
|
class _FakeConfig:
|
|
def __init__(self):
|
|
self.settings = None
|
|
|
|
def merge_settings(self, settings):
|
|
self.settings = settings
|
|
|
|
|
|
class _FakeEms:
|
|
def __init__(self):
|
|
self.run_kwargs = None
|
|
|
|
async def run(self, **kwargs):
|
|
self.run_kwargs = kwargs
|
|
|
|
|
|
class TestServerEndpointDirect:
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_fastapi_strompreis(self, monkeypatch):
|
|
class _FakePrediction:
|
|
def __init__(self):
|
|
self.key_to_array_kwargs = None
|
|
|
|
async def key_to_array(self, **kwargs):
|
|
self.key_to_array_kwargs = kwargs
|
|
|
|
# two hours of hourly values
|
|
return np.array([4.0, 16.0])
|
|
|
|
config = _FakeConfig()
|
|
ems = _FakeEms()
|
|
prediction = _FakePrediction()
|
|
|
|
monkeypatch.setattr(
|
|
"akkudoktoreos.server.eos.get_config",
|
|
lambda: config,
|
|
)
|
|
monkeypatch.setattr(
|
|
"akkudoktoreos.server.eos.get_ems",
|
|
lambda: ems,
|
|
)
|
|
monkeypatch.setattr(
|
|
"akkudoktoreos.server.eos.get_prediction",
|
|
lambda: prediction,
|
|
)
|
|
|
|
result = await fastapi_strompreis()
|
|
|
|
assert ems.run_kwargs is not None
|
|
assert prediction.key_to_array_kwargs is not None
|
|
assert result == [4.0, 16.0]
|
|
|
|
assert ems.run_kwargs == {
|
|
"mode": ems.run_kwargs["mode"], # see below
|
|
"force_update": True,
|
|
}
|
|
|
|
kwargs = prediction.key_to_array_kwargs
|
|
|
|
assert kwargs["key"] == "elecprice_marketprice_wh"
|
|
assert kwargs["interval"] == to_duration("1 hour")
|
|
assert kwargs["fill_method"] == "ffill"
|
|
assert kwargs["resample_method"] == "interval_mean"
|