Skip to content

Conversation

@shsms
Copy link
Collaborator

@shsms shsms commented Jul 28, 2025

Also return None when a coalesce formula can't be generated, instead of an error.

shsms added 2 commits July 24, 2025 17:36
`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]>
@shsms shsms added the cmd:skip-release-notes It is not necessary to update release notes for this PR label Jul 28, 2025
@shsms shsms requested review from Copilot and niklas-timpe July 28, 2025 09:30
Copy link

Copilot AI left a 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 Formula trait with coalesce, min, and max methods for all formula types
  • Refactors coalesce generators to use fold operations and return None for 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

niklas-timpe
niklas-timpe previously approved these changes Jul 28, 2025
shsms added 8 commits July 28, 2025 13:26
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]>
Copy link
Collaborator

@niklas-timpe niklas-timpe left a comment

Choose a reason for hiding this comment

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

lgtm

@shsms shsms added this pull request to the merge queue Jul 28, 2025
Merged via the queue into frequenz-floss:v0.x.x with commit b2fd616 Jul 28, 2025
3 checks passed
@shsms shsms deleted the none-formulas branch July 28, 2025 11:44
shsms added a commit to shsms/frequenz-microgrid-component-graph-rs that referenced this pull request Aug 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cmd:skip-release-notes It is not necessary to update release notes for this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants