-
Notifications
You must be signed in to change notification settings - Fork 2
Formula generation support #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
9f95f81
Rename `graph::test_types` to `test_utils`
shsms 5d75997
Add the `ComponentGraphBuilder` type in the `test_utils` module
shsms 29a50c4
Add the `Expr` type for representing formula expressions
shsms cce38d5
Add methods for iterating over the siblings of components
shsms 4554c50
Support generating formulas with fallback expressions
shsms 5baa9ba
Support searching the graph for components that match a predicate
shsms b9be4c2
Add the `consumer` formula generator
shsms 3750ea0
Add the `grid` formula generator
shsms 786b42f
Add the `producer` formula generator
shsms 399cce7
Add the `battery` formula generator
shsms 13af131
Add the `chp` formula generator
shsms 6da0f7b
Add the `PV` formula generator
shsms 30e4572
Add the `EV charger` formula generator
shsms 8fd3b46
Use `gh-action-cargo-test` in CI
shsms 157e1c7
Update documentation
shsms a3bdb63
Remove `is_grid_meter` implementation
shsms b19af8f
Add additional per-component fallback to 0.0
shsms 6f43828
Remove `Node::is_supported` trait method
shsms 75d067e
Add a direction parameter to the `find_all` method
shsms File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| // License: MIT | ||
| // Copyright © 2024 Frequenz Energy-as-a-Service GmbH | ||
|
|
||
| //! Methods for building formulas for various microgrid metrics. | ||
|
|
||
| use std::collections::BTreeSet; | ||
|
|
||
| use crate::ComponentGraph; | ||
| use crate::Edge; | ||
| use crate::Error; | ||
| use crate::Node; | ||
|
|
||
| mod expr; | ||
| mod fallback; | ||
| mod generators; | ||
| mod traversal; | ||
|
|
||
| /// Formulas for various microgrid metrics. | ||
| impl<N, E> ComponentGraph<N, E> | ||
| where | ||
| N: Node, | ||
| E: Edge, | ||
| { | ||
| /// Returns a string representing the consumer formula for the graph. | ||
| pub fn consumer_formula(&self) -> Result<String, Error> { | ||
| generators::consumer::ConsumerFormulaBuilder::try_new(self)?.build() | ||
| } | ||
|
|
||
| /// Returns a string representing the grid formula for the graph. | ||
| pub fn grid_formula(&self) -> Result<String, Error> { | ||
| generators::grid::GridFormulaBuilder::try_new(self)?.build() | ||
| } | ||
|
|
||
| /// Returns a string representing the producer formula for the graph. | ||
| pub fn producer_formula(&self) -> Result<String, Error> { | ||
| generators::producer::ProducerFormulaBuilder::try_new(self)?.build() | ||
| } | ||
|
|
||
| /// Returns a string representing the battery formula for the graph. | ||
| pub fn battery_formula(&self, battery_ids: Option<BTreeSet<u64>>) -> Result<String, Error> { | ||
| generators::battery::BatteryFormulaBuilder::try_new(self, battery_ids)?.build() | ||
| } | ||
|
|
||
| /// Returns a string representing the CHP formula for the graph. | ||
| pub fn chp_formula(&self, chp_ids: Option<BTreeSet<u64>>) -> Result<String, Error> { | ||
| generators::chp::CHPFormulaBuilder::try_new(self, chp_ids)?.build() | ||
| } | ||
|
|
||
| /// Returns a string representing the PV formula for the graph. | ||
| pub fn pv_formula(&self, pv_inverter_ids: Option<BTreeSet<u64>>) -> Result<String, Error> { | ||
| generators::pv::PVFormulaBuilder::try_new(self, pv_inverter_ids)?.build() | ||
| } | ||
|
|
||
| /// Returns a string representing the EV charger formula for the graph. | ||
| pub fn ev_charger_formula( | ||
| &self, | ||
| ev_charger_ids: Option<BTreeSet<u64>>, | ||
| ) -> Result<String, Error> { | ||
| generators::ev_charger::EVChargerFormulaBuilder::try_new(self, ev_charger_ids)?.build() | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.