Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove unused function #123

Merged
merged 4 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions src/akkudoktoreos/class_ems.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
6 changes: 3 additions & 3 deletions tests/test_class_ems.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading