mirror of
https://github.com/Akkudoktor-EOS/EOS.git
synced 2025-04-19 08:55:15 +00:00
* Dockerfile: Use non-root user, buildx cache, setup for readonly container, remove unused apt deps. For now don't install pip package and keep development flask server as this will be replaced in the future (fastapi). Then a proper webserver (e.g. nginx) should be used and the pip package can be created and deployed just to the run-stage (with the webserver). * docker-compose: Set to readonly (anonymous volumes declared in Dockerfile should maintain all writable data). Mount config.py for easier development. Should be replaced by environment support for all config file variables. * Remove unused runtime dependencies: mariadb, joblib, pytest, pytest-cov. * Move pytest-cov to dev dependencies. * Add output_dir to config.py. * Fix visualization_results.pdf endpoint. * Update docs.
41 lines
1.3 KiB
Python
41 lines
1.3 KiB
Python
import json
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from akkudoktoreos.class_optimize import optimization_problem
|
|
from akkudoktoreos.config import output_dir
|
|
|
|
DIR_TESTDATA = Path(__file__).parent / "testdata"
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"fn_in, fn_out", [("optimize_input_1.json", "optimize_result_1.json")]
|
|
)
|
|
def test_optimize(fn_in, fn_out):
|
|
# Load input and output data
|
|
with open(DIR_TESTDATA / fn_in, "r") as f_in:
|
|
input_data = json.load(f_in)
|
|
|
|
with open(DIR_TESTDATA / fn_out, "r") as f_out:
|
|
expected_output_data = json.load(f_out)
|
|
|
|
opt_class = optimization_problem(
|
|
prediction_hours=48, strafe=10, optimization_hours=24, fixed_seed=42
|
|
)
|
|
start_hour = 10
|
|
|
|
# Call the optimization function
|
|
ergebnis = opt_class.optimierung_ems(
|
|
parameter=input_data, start_hour=start_hour, ngen=3
|
|
)
|
|
|
|
# Assert that the output contains all expected entries.
|
|
# This does not assert that the optimization always gives the same result!
|
|
# Reproducibility and mathematical accuracy should be tested on the level of individual components.
|
|
assert set(ergebnis) == set(expected_output_data)
|
|
|
|
# The function creates a visualization result PDF as a side-effect.
|
|
fp_viz = Path(output_dir) / "visualization_results.pdf"
|
|
assert fp_viz.exists()
|