-
Couldn't load subscription status.
- Fork 20
More updates for n:m support - battery pool's power formula #730
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 | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -12,6 +12,7 @@ | |||||||||||||
| from ._formula_generator import ( | ||||||||||||||
| NON_EXISTING_COMPONENT_ID, | ||||||||||||||
| ComponentNotFound, | ||||||||||||||
| FormulaGenerationError, | ||||||||||||||
| FormulaGenerator, | ||||||||||||||
| ) | ||||||||||||||
|
|
||||||||||||||
|
|
@@ -40,6 +41,8 @@ def generate( | |||||||||||||
| they don't have an inverter as a predecessor. | ||||||||||||||
| FormulaGenerationError: If a battery has a non-inverter predecessor | ||||||||||||||
| in the component graph. | ||||||||||||||
| FormulaGenerationError: If not all batteries behind a set of inverters | ||||||||||||||
| have been requested. | ||||||||||||||
| """ | ||||||||||||||
| builder = self._get_builder( | ||||||||||||||
| "battery-power", ComponentMetricId.ACTIVE_POWER, Power.from_watts | ||||||||||||||
|
|
@@ -61,16 +64,39 @@ def generate( | |||||||||||||
|
|
||||||||||||||
| component_graph = connection_manager.get().component_graph | ||||||||||||||
|
|
||||||||||||||
| battery_inverters = list( | ||||||||||||||
| next(iter(component_graph.predecessors(bat_id))) for bat_id in component_ids | ||||||||||||||
| battery_inverters = frozenset( | ||||||||||||||
| frozenset( | ||||||||||||||
| filter( | ||||||||||||||
| component_graph.is_battery_inverter, | ||||||||||||||
| component_graph.predecessors(bat_id), | ||||||||||||||
| ) | ||||||||||||||
| ) | ||||||||||||||
| for bat_id in component_ids | ||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in a setup with 1 inverter and 2 batteries, there will be 2 frozensets with the same inverter. that would lead to 2x power reporting, no? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch. Added a test to catch this and fixed it, too |
||||||||||||||
| ) | ||||||||||||||
|
|
||||||||||||||
| if len(component_ids) != len(battery_inverters): | ||||||||||||||
| if not all(battery_inverters): | ||||||||||||||
| raise ComponentNotFound( | ||||||||||||||
| "Can't find inverters for all batteries from the component graph." | ||||||||||||||
| "All batteries must have at least one inverter as a predecessor." | ||||||||||||||
| ) | ||||||||||||||
|
|
||||||||||||||
| all_connected_batteries = set() | ||||||||||||||
| for inverters in battery_inverters: | ||||||||||||||
| for inverter in inverters: | ||||||||||||||
| all_connected_batteries.update( | ||||||||||||||
| component_graph.successors(inverter.component_id) | ||||||||||||||
| ) | ||||||||||||||
|
|
||||||||||||||
| if len(all_connected_batteries) != len(component_ids): | ||||||||||||||
| raise FormulaGenerationError( | ||||||||||||||
| "All batteries behind a set of inverters must be requested." | ||||||||||||||
| ) | ||||||||||||||
|
|
||||||||||||||
| for idx, comp in enumerate(battery_inverters): | ||||||||||||||
| builder.push_oper("(") | ||||||||||||||
| builder.push_oper("(") | ||||||||||||||
| # Iterate over the flattened list of inverters | ||||||||||||||
| for idx, comp in enumerate( | ||||||||||||||
| inverter for inverters in battery_inverters for inverter in inverters | ||||||||||||||
| ): | ||||||||||||||
|
Comment on lines
+97
to
+99
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe the inverter ids can be collected into a set before enumerating, to deduplicate?
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I made |
||||||||||||||
| if idx > 0: | ||||||||||||||
| builder.push_oper("+") | ||||||||||||||
| builder.push_component_metric(comp.component_id, nones_are_zeros=True) | ||||||||||||||
|
|
||||||||||||||
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.
was this supposed to go into a different commit?
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.
fixed >:|