Skip to content
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
19 changes: 14 additions & 5 deletions packages/modules/common/utils/peak_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,18 @@ def check_imported_exported(
exported: Optional[float] = None,
) -> tuple[Optional[float], Optional[float]]:
if max_power > 0:
# maximal mögliche Energiemenge in 50 Jahren:
# max. Leistung × 24 h/Tag × 365 Tage/Jahr × 50 Jahre
max_energy = max_power * 24 * 365 * 50
# Die erlaubte Abweichung ist doppelt so groß wie die mögliche
# Energiemenge pro Intervall bei maximaler Leistung
control_interval = data.data.general_data.data.control_interval
allowed_deviation = 2 * (control_interval / 3600) * max_power

imp = self.check_total_energy(imported, self.imported, allowed_deviation)
imp = self.check_total_energy(imported, self.imported, allowed_deviation, max_energy)
self.imported = imported

exp = self.check_total_energy(exported, self.exported, allowed_deviation)
exp = self.check_total_energy(exported, self.exported, allowed_deviation, max_energy)
self.exported = exported
Comment on lines +64 to 68
return imp, exp
return imported, exported
Expand All @@ -70,15 +73,21 @@ def check_total_energy(
self,
total_energy: Optional[float],
previous_total_energy: Optional[float],
allowed_deviation: float
allowed_deviation: float,
max_energy: float
) -> Optional[float]:
if total_energy is not None:
if previous_total_energy is None:
if total_energy > max_energy:
log.debug(f"PeakFilter: Unplausibler Zählerwert: {total_energy / 1000}kWh. "
f"Maximal mögliche Energiemenge in 50 Jahren: {max_energy / 1000}kWh.")
elif previous_total_energy is None:
if allowed_deviation > 0:
self.fault_state.warning("PeakFilter: Vorheriger Wert None (Startup), "
f"aktueller Zählerwert: {total_energy / 1000 }kWh. "
"Warte einen Regelintervall.")
elif allowed_deviation > 0 and (total_energy - previous_total_energy) > allowed_deviation:
elif (allowed_deviation > 0 and
((total_energy - previous_total_energy) > allowed_deviation or
(total_energy - previous_total_energy) < 0)):
Comment on lines +88 to +90

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Negativwerte werden in der setdata zusätzlich verworfen. Es geht darum kleinere Peaks nach großen Peaks zu filtern (wären negativ und würden durchgehen).
Es sollen nur steigende oder gleichbleibende Werte valide sein.

Ist keine aktuelle Leistung zum Vergleich hinterlegt soll kein Filter angewendet werden.

log.debug(f"PeakFilter: Unplausibler Zählerwert: {total_energy / 1000}kWh. "
f"Differenz zum vorherigen Wert: {total_energy - previous_total_energy}Wh. "
f"erlaubte Differenz: {round(allowed_deviation, 2)}Wh.")
Expand Down
6 changes: 6 additions & 0 deletions packages/modules/common/utils/test_peak_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ class Params:
Params("Imp/ Exp Speicher - Werte invalide", ComponentType.BAT, 1000, 500, 400, 1300, 800, None, None),
Params("Imp/ Exp Speicher - Import invalide", ComponentType.BAT, 1000, 500, 400, 1300, 505, None, 505),
Params("Imp/ Exp Speicher - Export invalide", ComponentType.BAT, 1000, 500, 400, 1005, 800, 1005, None),
Params("Imp/ Exp Speicher - Import > 50Y", ComponentType.BAT, 500000000, 500, 400, 500000000, 505, None, 505),
Params("Imp/ Exp Speicher - Export > 50Y", ComponentType.BAT, 1000, 500000000, 400, 1005, 500000000, 1005, None),
Params("Imp/ Exp Speicher - Export ~ 45Y", ComponentType.BAT,
1000, 400000000, 400, 1005, 400000000, 1005, 400000000),
Params("Imp/ Exp Speicher - Import ~ 45Y", ComponentType.BAT,
400000000, 500, 400, 400000000, 505, 400000000, 505)
Comment on lines +76 to +81
]


Expand Down
Loading