44//! A composable formula type, that can be subscribed to.
55
66use crate :: Error ;
7+ use crate :: logical_meter:: formula:: FormulaParams ;
78use crate :: logical_meter:: logical_meter_actor;
89use crate :: proto:: common:: v1:: microgrid:: components:: Component ;
910use crate :: proto:: common:: v1:: microgrid:: components:: ComponentConnection ;
@@ -14,13 +15,14 @@ use tokio::sync::mpsc;
1415use super :: { AggregationFormula , CoalesceFormula } ;
1516
1617macro_rules! graph_formula_provider {
17- ( $( ( $fnname: ident $( , $idsparam: ident) ?) ) ,+ $( , ) ?) => { $(
18+ ( $( ( $fnname: ident $( , ids : $idsparam: ident ) ? $ ( , id : $idparam : ident) ?) ) ,+ $( , ) ?) => { $(
1819
1920 fn $fnname<M : crate :: metric:: metric_trait:: AcMetric >(
2021 _graph: & ComponentGraph <Component , ComponentConnection >,
2122 _metric: M ,
2223 _instructions_tx: mpsc:: Sender <logical_meter_actor:: Instruction >,
2324 $( $idsparam: Option <BTreeSet <u64 >>, ) ?
25+ $( $idparam: u64 , ) ?
2426 ) -> Result <Self , Error > {
2527 return Err ( Error :: component_graph_error(
2628 format!(
@@ -45,29 +47,37 @@ pub trait GraphFormulaProvider: Sized {
4547 ( grid) ,
4648 ( consumer) ,
4749 ( producer) ,
48- ( battery, _battery_ids) ,
49- ( chp, _chp_ids) ,
50- ( pv, _pv_inverter_ids) ,
51- ( ev_charger, _ev_charger_ids) ,
50+ ( battery, ids: _battery_ids) ,
51+ ( chp, ids: _chp_ids) ,
52+ ( pv, ids: _pv_inverter_ids) ,
53+ ( ev_charger, ids: _ev_charger_ids) ,
54+ ( component, id: _component_id) ,
5255 ) ;
5356}
5457
5558macro_rules! impl_graph_formula_provider {
56- ( $( ( $fnname: ident, $graphfnname: ident$( , $idsparam: ident) ?) ) ,+ $( , ) ?) => { $(
59+ ( $( (
60+ $fnname: ident,
61+ $graphfnname: ident
62+ $( , ids: $idsparam: ident) ?
63+ $( , id: $idparam: ident) ?
64+ ) ) ,+ $( , ) ?) => { $(
5765
5866 fn $fnname<M : crate :: metric:: metric_trait:: AcMetric >(
5967 graph: & ComponentGraph <Component , ComponentConnection >,
6068 _metric: M ,
6169 instructions_tx: mpsc:: Sender <logical_meter_actor:: Instruction >,
6270 $( $idsparam: Option <BTreeSet <u64 >>, ) ?
71+ $( $idparam: u64 , ) ?
6372 ) -> Result <Self , Error > {
64- let formula = graph. $graphfnname( $( $idsparam) ?) . map_err( |e| {
73+ let formula = graph. $graphfnname( $( $idsparam) ?$ ( $idparam ) ? ) . map_err( |e| {
6574 Error :: component_graph_error(
6675 format!( "Could not get {} formula: {e}" , stringify!( $fnname) )
6776 )
6877 } ) ?;
69- Ok ( Self :: new( formula, M :: METRIC , instructions_tx) )
78+ Ok ( FormulaParams :: new( formula, M :: METRIC , instructions_tx) . into ( ) )
7079 }
80+
7181 ) +} ;
7282}
7383
@@ -76,17 +86,19 @@ impl GraphFormulaProvider for AggregationFormula {
7686 ( grid, grid_formula) ,
7787 ( consumer, consumer_formula) ,
7888 ( producer, producer_formula) ,
79- ( battery, battery_formula, battery_ids) ,
80- ( chp, chp_formula, chp_ids) ,
81- ( pv, pv_formula, pv_inverter_ids) ,
82- ( ev_charger, ev_charger_formula, ev_charger_ids) ,
89+ ( battery, battery_formula, ids: battery_ids) ,
90+ ( chp, chp_formula, ids: chp_ids) ,
91+ ( pv, pv_formula, ids: pv_inverter_ids) ,
92+ ( ev_charger, ev_charger_formula, ids: ev_charger_ids) ,
93+ ( component, component_formula, id: component_id) ,
8394 ) ;
8495}
8596
8697impl GraphFormulaProvider for CoalesceFormula {
8798 impl_graph_formula_provider ! (
8899 ( grid, grid_coalesce_formula) ,
89- ( battery, battery_ac_coalesce_formula, battery_ids) ,
90- ( pv, pv_ac_coalesce_formula, pv_inverter_ids) ,
100+ ( battery, battery_ac_coalesce_formula, ids: battery_ids) ,
101+ ( pv, pv_ac_coalesce_formula, ids: pv_inverter_ids) ,
102+ ( component, component_ac_coalesce_formula, id: component_id) ,
91103 ) ;
92104}
0 commit comments