mirror of
https://github.com/Akkudoktor-EOS/EOS.git
synced 2026-08-05 16:36:12 +00:00
Change PDF visualization to be created on demand and per optimization algorithm. The PDF for the GENETIC0 optimization is provided by the /visualization_results.pdf endpoint. There is no change in the interface. By this the optimization algorithm is offloaded from the PDF generation which spares some time. To cope with several users may call the /visualization_results.pdf endpoint at the same time the PDF is generated on the fly without any intermediate file taking the stored GENETIC0 solution as an input. SVG picture generation is removed as this would again create intermediate files. Chart pictures can easily be taken from the PDF. To allow on demand creation of the optimization results visualization the optimisation solution stored is extended by several new attributes. To keep the deprecated /optimize endpoint compatible the optimization solution is stripped to the legacy content before returned. Due to the extension of the solution the optimization tests were adapted to cover the extended content. The optimization tests are adapted to test the generated visualization report by the pypdf reader. Pypdf is added to the development dependencies. Besides the adaptation several fixes and improvements are added: * feat: extend /v1/prediction/series endpoint by resampling and filling Add parameters for resampling and filling. Add the processing parameter to control wether raw data or resampled data shall be returned. * feat: extend /v1/measurement/series endpoint by resampling and filling Add parameters for resampling and filling: Add the processing parameter to control wether raw data or resampled data shall be returned. * feat: standardize and improve API error response Use FASTApi exception handlers to provide a standardized API exception handling. All exceptions are logged. Exception traces are only returned if the new logging configuration parameter logging.api_logging_level is set to "DEBUG" or "TRACE". Avoids unwanted leackage of server internals on exceptions. * fix: align to intervall when resampling Ensure resampling is aligned to interval also when the buckets are shifted due to the align_to_intervall parameter is set. * chore: make dropna mandatory and default to True * chore: refactor key_to_xxx data management methods Make key_to_series the central method for data resampling and fill. Add a new key_to_raw_series to retrieve the data as it is stored (without resampling and filling). Users of key_to_series were mostly moved to key_to_raw_series as this resembles the former interface. Especially in predictions and tests this was done. * chore: create test data sub-directory for each optimization algorithm To prevent cluttering the test data directory and ease test data management for optimization algorithms each algorithm got it's own sub-directory. The current test data was moved to these sub-directories. * chore: update version Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
37 lines
1.1 KiB
Python
37 lines
1.1 KiB
Python
from pathlib import Path
|
|
|
|
from matplotlib.testing.compare import compare_images
|
|
|
|
from akkudoktoreos.optimization.genetic.geneticvisualize import (
|
|
genetic_generate_example_report,
|
|
)
|
|
|
|
filename = "example_report.pdf"
|
|
|
|
|
|
DIR_TESTDATA = Path(__file__).parent / "testdata" / "genetic"
|
|
reference_file = DIR_TESTDATA / "test_example_report.pdf"
|
|
reference_png_file = DIR_TESTDATA / "test_example_report_pdf.png"
|
|
output_file = DIR_TESTDATA / "test_example_report_new.pdf"
|
|
output_png_file = DIR_TESTDATA / "test_example_report_new_pdf.png"
|
|
|
|
|
|
def test_generate_pdf_example(config_eos):
|
|
"""Test generation of example visualization report."""
|
|
# Generate PDF
|
|
genetic_generate_example_report(filename=str(output_file))
|
|
|
|
# Check if the file exists
|
|
assert output_file.exists()
|
|
|
|
# Compare the generated file with the reference file
|
|
comparison = compare_images(str(reference_file), str(output_file), tol=0)
|
|
|
|
# Assert that there are no differences
|
|
assert comparison is None, f"Images differ: {comparison}"
|
|
|
|
# Everything passed, remove compare file
|
|
reference_png_file.unlink()
|
|
output_file.unlink()
|
|
output_png_file.unlink()
|