diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index e464950..e3b27c1 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -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. + + +## Upgrading + + + +## New Features + + + +## Bug Fixes + +- This fixes a bug in a rare case where the grid component could get picked as a fallback component. diff --git a/src/graph/formulas/fallback.rs b/src/graph/formulas/fallback.rs index 4db70e9..666137d 100644 --- a/src/graph/formulas/fallback.rs +++ b/src/graph/formulas/fallback.rs @@ -150,16 +150,25 @@ where ))); } - for sibling in siblings { - component_ids.remove(&sibling.component_id()); - } - + // Collect predecessor meter ids. let predecessor_ids: BTreeSet = 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)?)) } @@ -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)"); + } }