|
| 1 | +// License: MIT |
| 2 | +// Copyright © 2024 Frequenz Energy-as-a-Service GmbH |
| 3 | + |
| 4 | +//! Methods for building formulas for various microgrid metrics. |
| 5 | +
|
| 6 | +use std::collections::BTreeSet; |
| 7 | + |
| 8 | +use crate::ComponentGraph; |
| 9 | +use crate::Edge; |
| 10 | +use crate::Error; |
| 11 | +use crate::Node; |
| 12 | + |
| 13 | +mod expr; |
| 14 | +mod fallback; |
| 15 | +mod generators; |
| 16 | +mod traversal; |
| 17 | + |
| 18 | +/// Formulas for various microgrid metrics. |
| 19 | +impl<N, E> ComponentGraph<N, E> |
| 20 | +where |
| 21 | + N: Node, |
| 22 | + E: Edge, |
| 23 | +{ |
| 24 | + /// Returns a string representing the consumer formula for the graph. |
| 25 | + pub fn consumer_formula(&self) -> Result<String, Error> { |
| 26 | + generators::consumer::ConsumerFormulaBuilder::try_new(self)?.build() |
| 27 | + } |
| 28 | + |
| 29 | + /// Returns a string representing the grid formula for the graph. |
| 30 | + pub fn grid_formula(&self) -> Result<String, Error> { |
| 31 | + generators::grid::GridFormulaBuilder::try_new(self)?.build() |
| 32 | + } |
| 33 | + |
| 34 | + /// Returns a string representing the producer formula for the graph. |
| 35 | + pub fn producer_formula(&self) -> Result<String, Error> { |
| 36 | + generators::producer::ProducerFormulaBuilder::try_new(self)?.build() |
| 37 | + } |
| 38 | + |
| 39 | + /// Returns a string representing the battery formula for the graph. |
| 40 | + pub fn battery_formula(&self, battery_ids: Option<BTreeSet<u64>>) -> Result<String, Error> { |
| 41 | + generators::battery::BatteryFormulaBuilder::try_new(self, battery_ids)?.build() |
| 42 | + } |
| 43 | + |
| 44 | + /// Returns a string representing the CHP formula for the graph. |
| 45 | + pub fn chp_formula(&self, chp_ids: Option<BTreeSet<u64>>) -> Result<String, Error> { |
| 46 | + generators::chp::CHPFormulaBuilder::try_new(self, chp_ids)?.build() |
| 47 | + } |
| 48 | + |
| 49 | + /// Returns a string representing the PV formula for the graph. |
| 50 | + pub fn pv_formula(&self, pv_inverter_ids: Option<BTreeSet<u64>>) -> Result<String, Error> { |
| 51 | + generators::pv::PVFormulaBuilder::try_new(self, pv_inverter_ids)?.build() |
| 52 | + } |
| 53 | + |
| 54 | + /// Returns a string representing the EV charger formula for the graph. |
| 55 | + pub fn ev_charger_formula( |
| 56 | + &self, |
| 57 | + ev_charger_ids: Option<BTreeSet<u64>>, |
| 58 | + ) -> Result<String, Error> { |
| 59 | + generators::ev_charger::EVChargerFormulaBuilder::try_new(self, ev_charger_ids)?.build() |
| 60 | + } |
| 61 | +} |
0 commit comments