Repository navigation
bidi charging: fix calculation of medium current #3196
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -4,7 +4,7 @@ | |||||||||||||||||
| def get_medium_charging_current(currents: List[float]) -> float: | ||||||||||||||||||
| """Ermittelt den mittleren Ladestrom der Phasen, auf denen geladen wird. | ||||||||||||||||||
|
||||||||||||||||||
| """Ermittelt den mittleren Ladestrom der Phasen, auf denen geladen wird. | |
| """Ermittelt den mittleren Strom der aktiven Phasen. | |
| Eine Phase gilt als aktiv, wenn der Betrag des Stroms mindestens 0,5 A beträgt | |
| (abs(I) >= 0.5). Es wird der arithmetische Mittelwert der Ströme aller aktiven | |
| Phasen zurückgegeben. Der zurückgegebene Mittelwert kann negativ sein, wenn | |
| überwiegend entladen wird (bidirektionaler Betrieb). Sind keine aktiven Phasen | |
| vorhanden, wird 0.0 zurückgegeben. |
Copilot
AI
Mar 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The list of “active” phase currents (|x| >= 0.5) is recomputed multiple times (any(), sum(), and len([...])). Consider filtering once into a local list and then using it for both sum/len to avoid duplication and keep the logic easier to maintain.
| if any(abs(x) >= 0.5 for x in currents): | |
| return sum(x for x in currents if abs(x) >= 0.5) / len([x for x in currents if abs(x) >= 0.5]) | |
| active_currents = [x for x in currents if abs(x) >= 0.5] | |
| if active_currents: | |
| return sum(active_currents) / len(active_currents) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are pytest-based tests for the algorithm package, but this behavioral change (including negative currents via abs()) isn’t covered by a unit test. Add a small test for get_medium_charging_current that includes negative currents (e.g., [-6, -6, 0] -> -6, and values below the 0.5A threshold) to prevent regressions for bidirectional charging.