-
Notifications
You must be signed in to change notification settings - Fork 2
Support coalesce/min/max on all formulas
#12
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
Conversation
Signed-off-by: Sahas Subramanian <[email protected]>
`AggregationFormula`s return 0.0 when there are matching components. For example, the battery `AggregationFormula` for a graph without batteries would be 0.0. This is not possible for `CoalesceFormula`s, so they were return an `Err` in such cases until now. This has been changed return `None`. This is done by changing the design to repeatedly calling `Expr::coalesce` for each item that needs to be added to a `coalesce` expression. Signed-off-by: Sahas Subramanian <[email protected]>
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.
Pull Request Overview
This PR enhances formula support by adding coalesce/min/max operations to all formula types and changes coalesce generators to return None instead of errors when no components are found.
- Introduces a
Formulatrait withcoalesce,min, andmaxmethods for all formula types - Refactors coalesce generators to use fold operations and return
Nonefor empty component sets - Updates expression handling to support fluent-style operations with proper operator precedence
Reviewed Changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/lib.rs | Exports the new Formula trait |
| src/graph/formulas/formula.rs | Adds Formula trait and implementations for formula types |
| src/graph/formulas/expr.rs | Refactors Expr methods to support binary operations and adds None variant |
| src/graph/formulas/generators/pv_ac_coalesce.rs | Updates to use fold-based coalescing and return None for empty sets |
| src/graph/formulas/generators/battery_ac_coalesce.rs | Similar fold-based refactoring for battery coalesce |
| src/graph/formulas/generators/grid_coalesce.rs | Applies fold pattern to grid coalesce generation |
| src/graph/formulas/generators/producer.rs | Updates to use new fluent-style min/max operations |
| src/graph/formulas/generators/consumer.rs | Refactors to use fluent-style max/coalesce operations |
| src/graph/formulas/fallback.rs | Updates coalesce calls to use binary operations |
| src/graph/formulas/generators/generic.rs | Removes generic coalesce module (entire file deleted) |
| src/graph/formulas.rs | Removes generic coalesce method and adds component-specific methods |
| src/error.rs | Removes unused MissingParameters error variant |
Signed-off-by: Sahas Subramanian <[email protected]>
Also change the MAX/MIN expressions to have the actual expression first, and then followed by the 0.0 to clamp to. Signed-off-by: Sahas Subramanian <[email protected]>
Now that some of them take a `self`, people could assume that the functions just mutate the values, which is not the case. So the hint is useful. Signed-off-by: Sahas Subramanian <[email protected]>
Signed-off-by: Sahas Subramanian <[email protected]>
Signed-off-by: Sahas Subramanian <[email protected]>
Signed-off-by: Sahas Subramanian <[email protected]>
Signed-off-by: Sahas Subramanian <[email protected]>
Signed-off-by: Sahas Subramanian <[email protected]>
niklas-timpe
left a comment
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.
lgtm
Also return
Nonewhen a coalesce formula can't be generated, instead of an error.