frequenz_microgrid_component_graph/graph/
formulas.rs1use std::collections::BTreeSet;
7
8use crate::ComponentGraph;
9use crate::Edge;
10use crate::Error;
11use crate::Node;
12
13mod expr;
14mod fallback;
15mod formula;
16mod generators;
17mod traversal;
18
19use expr::Expr;
20pub use formula::{AggregationFormula, CoalesceFormula, Formula};
21
22impl<N, E> ComponentGraph<N, E>
24where
25 N: Node,
26 E: Edge,
27{
28 pub fn consumer_formula(&self) -> Result<AggregationFormula, Error> {
30 generators::consumer::ConsumerFormulaBuilder::try_new(self)?.build()
31 }
32
33 pub fn grid_formula(&self) -> Result<AggregationFormula, Error> {
35 generators::grid::GridFormulaBuilder::try_new(self)?.build()
36 }
37
38 pub fn producer_formula(&self) -> Result<AggregationFormula, Error> {
40 generators::producer::ProducerFormulaBuilder::try_new(self)?.build()
41 }
42
43 pub fn battery_formula(
48 &self,
49 battery_ids: Option<BTreeSet<u64>>,
50 ) -> Result<AggregationFormula, Error> {
51 generators::battery::BatteryFormulaBuilder::try_new(self, battery_ids)?.build()
52 }
53
54 pub fn chp_formula(&self, chp_ids: Option<BTreeSet<u64>>) -> Result<AggregationFormula, Error> {
56 generators::chp::CHPFormulaBuilder::try_new(self, chp_ids)?.build()
57 }
58
59 pub fn pv_formula(
61 &self,
62 pv_inverter_ids: Option<BTreeSet<u64>>,
63 ) -> Result<AggregationFormula, Error> {
64 generators::pv::PVFormulaBuilder::try_new(self, pv_inverter_ids)?.build()
65 }
66
67 pub fn ev_charger_formula(
69 &self,
70 ev_charger_ids: Option<BTreeSet<u64>>,
71 ) -> Result<AggregationFormula, Error> {
72 generators::ev_charger::EVChargerFormulaBuilder::try_new(self, ev_charger_ids)?.build()
73 }
74
75 pub fn component_formula(&self, component_id: u64) -> Result<AggregationFormula, Error> {
77 Ok(Expr::component(component_id).into())
78 }
79
80 pub fn grid_coalesce_formula(&self) -> Result<CoalesceFormula, Error> {
89 generators::grid_coalesce::GridCoalesceFormulaBuilder::try_new(self)?.build()
90 }
91
92 pub fn battery_ac_coalesce_formula(
103 &self,
104 battery_ids: Option<BTreeSet<u64>>,
105 ) -> Result<CoalesceFormula, Error> {
106 generators::battery_ac_coalesce::BatteryAcCoalesceFormulaBuilder::try_new(
107 self,
108 battery_ids,
109 )?
110 .build()
111 }
112
113 pub fn pv_ac_coalesce_formula(
124 &self,
125 pv_inverter_ids: Option<BTreeSet<u64>>,
126 ) -> Result<CoalesceFormula, Error> {
127 generators::pv_ac_coalesce::PVAcCoalesceFormulaBuilder::try_new(self, pv_inverter_ids)?
128 .build()
129 }
130
131 pub fn component_ac_coalesce_formula(
133 &self,
134 component_id: u64,
135 ) -> Result<CoalesceFormula, Error> {
136 Ok(Expr::component(component_id).into())
137 }
138}