@@ -16,57 +16,117 @@ mod formula;
1616mod generators;
1717mod traversal;
1818
19- pub use formula:: Formula ;
19+ pub use formula:: { AggregationFormula , CoalesceFormula } ;
2020
2121/// Formulas for various microgrid metrics.
2222impl < N , E > ComponentGraph < N , E >
2323where
2424 N : Node ,
2525 E : Edge ,
2626{
27- /// Returns a string representing the consumer formula for the graph.
28- pub fn consumer_formula ( & self ) -> Result < Formula , Error > {
27+ /// Returns the consumer formula for the graph.
28+ pub fn consumer_formula ( & self ) -> Result < AggregationFormula , Error > {
2929 generators:: consumer:: ConsumerFormulaBuilder :: try_new ( self ) ?. build ( )
3030 }
3131
32- /// Returns a string representing the grid formula for the graph.
33- pub fn grid_formula ( & self ) -> Result < Formula , Error > {
32+ /// Returns the grid formula for the graph.
33+ pub fn grid_formula ( & self ) -> Result < AggregationFormula , Error > {
3434 generators:: grid:: GridFormulaBuilder :: try_new ( self ) ?. build ( )
3535 }
3636
37- /// Returns a string representing the producer formula for the graph.
38- pub fn producer_formula ( & self ) -> Result < Formula , Error > {
37+ /// Returns the producer formula for the graph.
38+ pub fn producer_formula ( & self ) -> Result < AggregationFormula , Error > {
3939 generators:: producer:: ProducerFormulaBuilder :: try_new ( self ) ?. build ( )
4040 }
4141
42- /// Returns a string representing the battery formula for the graph.
43- pub fn battery_formula ( & self , battery_ids : Option < BTreeSet < u64 > > ) -> Result < Formula , Error > {
42+ /// Returns the battery formula with the given battery IDs.
43+ ///
44+ /// If `battery_ids` is `None`, the formula will contain all batteries in
45+ /// the graph.
46+ pub fn battery_formula (
47+ & self ,
48+ battery_ids : Option < BTreeSet < u64 > > ,
49+ ) -> Result < AggregationFormula , Error > {
4450 generators:: battery:: BatteryFormulaBuilder :: try_new ( self , battery_ids) ?. build ( )
4551 }
4652
47- /// Returns a string representing the CHP formula for the graph.
48- pub fn chp_formula ( & self , chp_ids : Option < BTreeSet < u64 > > ) -> Result < Formula , Error > {
53+ /// Returns the CHP formula for the graph.
54+ pub fn chp_formula ( & self , chp_ids : Option < BTreeSet < u64 > > ) -> Result < AggregationFormula , Error > {
4955 generators:: chp:: CHPFormulaBuilder :: try_new ( self , chp_ids) ?. build ( )
5056 }
5157
52- /// Returns a string representing the PV formula for the graph.
53- pub fn pv_formula ( & self , pv_inverter_ids : Option < BTreeSet < u64 > > ) -> Result < Formula , Error > {
58+ /// Returns the PV formula for the graph.
59+ pub fn pv_formula (
60+ & self ,
61+ pv_inverter_ids : Option < BTreeSet < u64 > > ,
62+ ) -> Result < AggregationFormula , Error > {
5463 generators:: pv:: PVFormulaBuilder :: try_new ( self , pv_inverter_ids) ?. build ( )
5564 }
5665
57- /// Returns a string with the coalesce formula for the given component IDs.
66+ /// Returns the coalesce formula for the given component IDs.
5867 ///
5968 /// This formula uses the `COALESCE` function to return the first non-null
6069 /// value from the components with the provided IDs.
61- pub fn coalesce ( & self , component_ids : BTreeSet < u64 > ) -> Result < Formula , Error > {
70+ pub fn coalesce ( & self , component_ids : BTreeSet < u64 > ) -> Result < AggregationFormula , Error > {
6271 generators:: generic:: CoalesceFormulaBuilder :: try_new ( self , component_ids) ?. build ( )
6372 }
6473
6574 /// Returns a string representing the EV charger formula for the graph.
6675 pub fn ev_charger_formula (
6776 & self ,
6877 ev_charger_ids : Option < BTreeSet < u64 > > ,
69- ) -> Result < Formula , Error > {
78+ ) -> Result < AggregationFormula , Error > {
7079 generators:: ev_charger:: EVChargerFormulaBuilder :: try_new ( self , ev_charger_ids) ?. build ( )
7180 }
81+
82+ /// Returns the grid coalesce formula for the graph.
83+ ///
84+ /// This formula is used for non-aggregating metrics like AC voltage or
85+ /// frequency.
86+ ///
87+ /// The formula is a `COALESCE` expression that includes all meters,
88+ /// PV inverters, and battery inverters that are directly connected to the
89+ /// grid.
90+ pub fn grid_coalesce_formula ( & self ) -> Result < CoalesceFormula , Error > {
91+ generators:: grid_coalesce:: GridCoalesceFormulaBuilder :: try_new ( self ) ?. build ( )
92+ }
93+
94+ /// Returns the battery AC coalesce formula for the given components.
95+ ///
96+ /// This formula is used for non-aggregating metrics like AC voltage or
97+ /// frequency.
98+ ///
99+ /// The formula is a `COALESCE` expression that includes all the specified
100+ /// battery meters and corresponding inverters.
101+ ///
102+ /// When the `battery_ids` parameter is `None`, it will include all the
103+ /// battery meters and inverters in the graph.
104+ pub fn battery_ac_coalesce_formula (
105+ & self ,
106+ battery_ids : Option < BTreeSet < u64 > > ,
107+ ) -> Result < CoalesceFormula , Error > {
108+ generators:: battery_ac_coalesce:: BatteryAcCoalesceFormulaBuilder :: try_new (
109+ self ,
110+ battery_ids,
111+ ) ?
112+ . build ( )
113+ }
114+
115+ /// Returns the PV AC coalesce formula for the given components.
116+ ///
117+ /// This formula is used for non-aggregating metrics like AC voltage or
118+ /// frequency.
119+ ///
120+ /// The formula is a `COALESCE` expression that includes all the specified
121+ /// PV meters and corresponding inverters.
122+ ///
123+ /// When the `pv_inverter_ids` parameter is `None`, it will include all the
124+ /// PV meters and inverters in the graph.
125+ pub fn pv_ac_coalesce_formula (
126+ & self ,
127+ pv_inverter_ids : Option < BTreeSet < u64 > > ,
128+ ) -> Result < CoalesceFormula , Error > {
129+ generators:: pv_ac_coalesce:: PVAcCoalesceFormulaBuilder :: try_new ( self , pv_inverter_ids) ?
130+ . build ( )
131+ }
72132}
0 commit comments