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
14 changes: 13 additions & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,16 @@

## Summary

This is the first release of the Frequenz Component Graph. In this version, it supports validating component graphs, provides formula generators for various metrics and methods for manual traversal of the graph, when necessary.
<!-- Here goes a general summary of what this release is about -->

## Upgrading

<!-- Here goes notes on how to upgrade from previous versions, including deprecations and what they should be replaced with -->

## New Features

<!-- Here goes the main new features and examples or instructions on how to use them -->

## Bug Fixes

- This fixes a bug in a rare case where the grid component could get picked as a fallback component.
39 changes: 35 additions & 4 deletions src/graph/formulas/fallback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,25 @@ where
)));
}

for sibling in siblings {
component_ids.remove(&sibling.component_id());
}

// Collect predecessor meter ids.
let predecessor_ids: BTreeSet<u64> = self
.graph
.predecessors(component_id)?
.filter(|x| x.is_meter())
.map(|x| x.component_id())
.collect();

if predecessor_ids.is_empty() {
return Ok(Some(Expr::coalesce(
Expr::component(component_id),
Expr::number(0.0),
)));
}

for sibling in siblings {
component_ids.remove(&sibling.component_id());
}

Ok(Some(self.generate(predecessor_ids)?))
}

Expand Down Expand Up @@ -301,4 +310,26 @@ mod tests {

Ok(())
}

/// Test fallback expression generation when there are no meters in the
/// graph, with only PV inverters directly connected to the grid.
#[test]
fn test_no_meters() {
let mut builder = ComponentGraphBuilder::new();
let grid = builder.grid();

let inverter = builder.solar_inverter();
builder.connect(grid, inverter);

let graph = builder.build(None).unwrap();
let expr = graph.pv_formula(None).unwrap().to_string();
assert_eq!(expr, "COALESCE(#1, 0.0)");

let inverter = builder.solar_inverter();
builder.connect(grid, inverter);

let graph = builder.build(None).unwrap();
let expr = graph.pv_formula(None).unwrap().to_string();
assert_eq!(expr, "COALESCE(#1, 0.0) + COALESCE(#2, 0.0)");
}
}