diff --git a/src/akkudoktoreos/class_ems.py b/src/akkudoktoreos/class_ems.py index 6dd75f1..f20443a 100644 --- a/src/akkudoktoreos/class_ems.py +++ b/src/akkudoktoreos/class_ems.py @@ -4,24 +4,6 @@ import numpy as np -def replace_nan_with_none( - data: Union[np.ndarray, dict, list, float], -) -> Union[List, dict, float, None]: - if data is None: - return None - if isinstance(data, np.ndarray): - # Use numpy vectorized approach - return np.where(np.isnan(data), None, data).tolist() - elif isinstance(data, dict): - return {key: replace_nan_with_none(value) for key, value in data.items()} - elif isinstance(data, list): - return [replace_nan_with_none(element) for element in data] - elif isinstance(data, (float, np.floating)) and np.isnan(data): - return None - else: - return data - - class EnergieManagementSystem: def __init__( self, @@ -156,4 +138,22 @@ def simuliere(self, start_stunde: int) -> dict: "Haushaltsgeraet_wh_pro_stunde": haushaltsgeraet_wh_pro_stunde, } - return replace_nan_with_none(out) + # List output keys where the first element needs to be changed to None + keys_to_modify = [ + "Last_Wh_pro_Stunde", + "Netzeinspeisung_Wh_pro_Stunde", + "Netzbezug_Wh_pro_Stunde", + ] + + # Loop through each key in the list + for key in keys_to_modify: + # Convert the NumPy array to a list + element_list = out[key].tolist() + + # Change the first value to None + element_list[0] = None + + # Assign the modified list back to the dictionary + out[key] = element_list + + return out diff --git a/tests/test_class_ems.py b/tests/test_class_ems.py index b7979e5..ed24f09 100644 --- a/tests/test_class_ems.py +++ b/tests/test_class_ems.py @@ -279,15 +279,15 @@ def test_simulation(create_ems_instance): # Verify that the value at index 0 is 'None' assert ( - result["Last_Wh_pro_Stunde"][0] == 0.0 + result["Last_Wh_pro_Stunde"][0] is None ), "The value at index 0 of 'Last_Wh_pro_Stunde' should be None." # Check that 'Netzeinspeisung_Wh_pro_Stunde' and 'Netzbezug_Wh_pro_Stunde' are consistent assert ( - result["Netzeinspeisung_Wh_pro_Stunde"][0] == 0.0 + result["Netzeinspeisung_Wh_pro_Stunde"][0] is None ), "The value at index 0 of 'Netzeinspeisung_Wh_pro_Stunde' should be None." assert ( - result["Netzbezug_Wh_pro_Stunde"][0] == 0.0 + result["Netzbezug_Wh_pro_Stunde"][0] is None ), "The value at index 0 of 'Netzbezug_Wh_pro_Stunde' should be None." assert ( result["Netzbezug_Wh_pro_Stunde"][1] == 21679.13