Skip to content

Commit f296103

Browse files
committed
Add methods to check if a component is part of a category chain
Signed-off-by: Sahas Subramanian <[email protected]>
1 parent 6dafd03 commit f296103

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

src/graph/meter_roles.rs

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,76 @@ where
101101
|| self.is_chp_meter(component_id)?
102102
|| self.is_wind_turbine_meter(component_id)?)
103103
}
104+
105+
/// Returns true if the node is part of a battery chain.
106+
///
107+
/// A component is part of a battery chain if it is one of the following:
108+
/// - a battery meter,
109+
/// - a battery inverter,
110+
/// - a battery.
111+
pub fn is_battery_chain(&self, component_id: u64) -> Result<bool, Error> {
112+
Ok(self.is_battery_meter(component_id)? || {
113+
let component = self.component(component_id)?;
114+
component.is_battery() || component.is_battery_inverter(&self.config)
115+
})
116+
}
117+
118+
/// Returns true if the node is part of a PV chain.
119+
///
120+
/// A component is part of a PV chain if it is one of the following:
121+
/// - a PV meter,
122+
/// - a PV inverter.
123+
pub fn is_pv_chain(&self, component_id: u64) -> Result<bool, Error> {
124+
Ok(self.is_pv_meter(component_id)? || self.component(component_id)?.is_pv_inverter())
125+
}
126+
127+
/// Returns true if the node is part of a CHP chain.
128+
///
129+
/// A component is part of a CHP chain if it is one of the following:
130+
/// - a CHP meter,
131+
/// - a CHP.
132+
pub fn is_chp_chain(&self, component_id: u64) -> Result<bool, Error> {
133+
Ok(self.is_chp_meter(component_id)? || self.component(component_id)?.is_chp())
134+
}
135+
136+
/// Returns true if the node is part of an EV charger chain.
137+
///
138+
/// A component is part of an EV charger chain if it is one of the following:
139+
/// - an EV charger meter,
140+
/// - an EV charger.
141+
pub fn is_ev_charger_chain(&self, component_id: u64) -> Result<bool, Error> {
142+
Ok(
143+
self.is_ev_charger_meter(component_id)?
144+
|| self.component(component_id)?.is_ev_charger(),
145+
)
146+
}
147+
148+
/// Returns true if the node is part of a Wind Turbine chain.
149+
///
150+
/// A component is part of a Wind Turbine chain if it is one of the following:
151+
/// - a Wind Turbine meter,
152+
/// - a Wind Turbine.
153+
pub fn is_wind_turbine_chain(&self, component_id: u64) -> Result<bool, Error> {
154+
Ok(self.is_wind_turbine_meter(component_id)?
155+
|| self.component(component_id)?.is_wind_turbine())
156+
}
157+
158+
/// Returns true if the node is part of a component chain.
159+
///
160+
/// A component is part of a component chain if it is part of one of the
161+
/// following:
162+
/// - a battery chain,
163+
/// - a PV chain,
164+
/// - an EV charger chain,
165+
/// - a CHP chain,
166+
/// - a Wind Turbine chain.
167+
pub fn is_component_chain(&self, component_id: u64) -> Result<bool, Error> {
168+
Ok(self.is_battery_chain(component_id)?
169+
|| self.is_pv_chain(component_id)?
170+
|| self.is_ev_charger_chain(component_id)?
171+
|| self.is_chp_chain(component_id)?
172+
|| self.is_wind_turbine_chain(component_id)?)
173+
}
104174
}
105175

106176
#[cfg(test)]

0 commit comments

Comments
 (0)