mirror of
https://github.com/Akkudoktor-EOS/EOS.git
synced 2025-09-13 07:21:16 +00:00
Improve caching. (#431)
* Move the caching module to core. Add an in memory cache that for caching function and method results during an energy management run (optimization run). Two decorators are provided for methods and functions. * Improve the file cache store by load and save functions. Make EOS load the cache file store on startup and save it on shutdown. Add a cyclic task that cleans the cache file store from outdated cache files. * Improve startup of EOSdash by EOS Make EOS starting EOSdash adhere to path configuration given in EOS. The whole environment from EOS is now passed to EOSdash. Should also prevent test errors due to unwanted/ wrong config file creation. Both servers now provide a health endpoint that can be used to detect whether the server is running. This is also used for testing now. * Improve startup of EOS EOS now has got an energy management task that runs shortly after startup. It tries to execute energy management runs with predictions newly fetched or initialized from cached data on first run. * Improve shutdown of EOS EOS has now a shutdown task that shuts EOS down gracefully with some time delay to allow REST API requests for shutdwon or restart to be fully serviced. * Improve EMS Add energy management task for repeated energy management controlled by startup delay and interval configuration parameters. Translate EnergieManagementSystem to english EnergyManagement. * Add administration endpoints - endpoints to control caching from REST API. - endpoints to control server restart (will not work on Windows) and shutdown from REST API * Improve doc generation Use "\n" linenend convention also on Windows when generating doc files. Replace Windows specific 127.0.0.1 address by standard 0.0.0.0. * Improve test support (to be able to test caching) - Add system test option to pytest for running tests with "real" resources - Add new test fixture to start server for test class and test function - Make kill signal adapt to Windows/ Linux - Use consistently "\n" for lineends when writing text files in doc test - Fix test_logging under Windows - Fix conftest config_default_dirs test fixture under Windows From @Lasall * Improve Windows support - Use 127.0.0.1 as default config host (model defaults) and addionally redirect 0.0.0.0 to localhost on Windows (because default config file still has 0.0.0.0). - Update install/startup instructions as package installation is required atm. Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
This commit is contained in:
@@ -562,6 +562,102 @@ class TestDataSequence:
|
||||
assert dates == [to_datetime(datetime(2023, 11, 5)), to_datetime(datetime(2023, 11, 6))]
|
||||
assert values == [0.8, 0.9]
|
||||
|
||||
def test_to_dataframe_full_data(self, sequence):
|
||||
"""Test conversion of all records to a DataFrame without filtering."""
|
||||
record1 = self.create_test_record("2024-01-01T12:00:00Z", 10)
|
||||
record2 = self.create_test_record("2024-01-01T13:00:00Z", 20)
|
||||
record3 = self.create_test_record("2024-01-01T14:00:00Z", 30)
|
||||
sequence.append(record1)
|
||||
sequence.append(record2)
|
||||
sequence.append(record3)
|
||||
|
||||
df = sequence.to_dataframe()
|
||||
|
||||
# Validate DataFrame structure
|
||||
assert isinstance(df, pd.DataFrame)
|
||||
assert not df.empty
|
||||
assert len(df) == 3 # All records should be included
|
||||
assert "data_value" in df.columns
|
||||
|
||||
def test_to_dataframe_with_filter(self, sequence):
|
||||
"""Test filtering records by datetime range."""
|
||||
record1 = self.create_test_record("2024-01-01T12:00:00Z", 10)
|
||||
record2 = self.create_test_record("2024-01-01T13:00:00Z", 20)
|
||||
record3 = self.create_test_record("2024-01-01T14:00:00Z", 30)
|
||||
sequence.append(record1)
|
||||
sequence.append(record2)
|
||||
sequence.append(record3)
|
||||
|
||||
start = to_datetime("2024-01-01T12:30:00Z")
|
||||
end = to_datetime("2024-01-01T14:00:00Z")
|
||||
|
||||
df = sequence.to_dataframe(start_datetime=start, end_datetime=end)
|
||||
|
||||
assert isinstance(df, pd.DataFrame)
|
||||
assert not df.empty
|
||||
assert len(df) == 1 # Only one record should match the range
|
||||
assert df.index[0] == pd.Timestamp("2024-01-01T13:00:00Z")
|
||||
|
||||
def test_to_dataframe_no_matching_records(self, sequence):
|
||||
"""Test when no records match the given datetime filter."""
|
||||
record1 = self.create_test_record("2024-01-01T12:00:00Z", 10)
|
||||
record2 = self.create_test_record("2024-01-01T13:00:00Z", 20)
|
||||
sequence.append(record1)
|
||||
sequence.append(record2)
|
||||
|
||||
start = to_datetime("2024-01-01T14:00:00Z") # Start time after all records
|
||||
end = to_datetime("2024-01-01T15:00:00Z")
|
||||
|
||||
df = sequence.to_dataframe(start_datetime=start, end_datetime=end)
|
||||
|
||||
assert isinstance(df, pd.DataFrame)
|
||||
assert df.empty # No records should match
|
||||
|
||||
def test_to_dataframe_empty_sequence(self, sequence):
|
||||
"""Test when DataSequence has no records."""
|
||||
sequence = DataSequence(records=[])
|
||||
|
||||
df = sequence.to_dataframe()
|
||||
|
||||
assert isinstance(df, pd.DataFrame)
|
||||
assert df.empty # Should return an empty DataFrame
|
||||
|
||||
def test_to_dataframe_no_start_datetime(self, sequence):
|
||||
"""Test when only end_datetime is given (all past records should be included)."""
|
||||
record1 = self.create_test_record("2024-01-01T12:00:00Z", 10)
|
||||
record2 = self.create_test_record("2024-01-01T13:00:00Z", 20)
|
||||
record3 = self.create_test_record("2024-01-01T14:00:00Z", 30)
|
||||
sequence.append(record1)
|
||||
sequence.append(record2)
|
||||
sequence.append(record3)
|
||||
|
||||
end = to_datetime("2024-01-01T13:00:00Z") # Include only first record
|
||||
|
||||
df = sequence.to_dataframe(end_datetime=end)
|
||||
|
||||
assert isinstance(df, pd.DataFrame)
|
||||
assert not df.empty
|
||||
assert len(df) == 1
|
||||
assert df.index[0] == pd.Timestamp("2024-01-01T12:00:00Z")
|
||||
|
||||
def test_to_dataframe_no_end_datetime(self, sequence):
|
||||
"""Test when only start_datetime is given (all future records should be included)."""
|
||||
record1 = self.create_test_record("2024-01-01T12:00:00Z", 10)
|
||||
record2 = self.create_test_record("2024-01-01T13:00:00Z", 20)
|
||||
record3 = self.create_test_record("2024-01-01T14:00:00Z", 30)
|
||||
sequence.append(record1)
|
||||
sequence.append(record2)
|
||||
sequence.append(record3)
|
||||
|
||||
start = to_datetime("2024-01-01T13:00:00Z") # Include last two records
|
||||
|
||||
df = sequence.to_dataframe(start_datetime=start)
|
||||
|
||||
assert isinstance(df, pd.DataFrame)
|
||||
assert not df.empty
|
||||
assert len(df) == 2
|
||||
assert df.index[0] == pd.Timestamp("2024-01-01T13:00:00Z")
|
||||
|
||||
|
||||
class TestDataProvider:
|
||||
# Fixtures and helper functions
|
||||
|
Reference in New Issue
Block a user