-
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
Conversation
Also move the code for the module from `graph.rs` to `graph/test_utils`. This is to make room for a component graph builder for tests, that will be added in the next commit. Signed-off-by: Sahas Subramanian <[email protected]>
llucax
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I gave this a quick look and looks really nice, with all the automatic fallaback/COALESCE. As a no-rust, it feels a bit the docs are not very verbose though. Can we maybe generate the docs as GitHub pages? Or will they be automatically generated and published when uploading to crates.io?
It looks to me that maybe more in depth docs about how do the formula builders work (what kind of components are considered, which are used as fallback of which, etc.) might be helpful for users to know.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I survived until commit: Support generating formulas with fallback expressions :)
Will check rest later today or tomorrow.
src/graph/formulas/fallback.rs
Outdated
| if self | ||
| .graph | ||
| .successors(component_id)? | ||
| .all(|x| x.is_supported()) | ||
| { | ||
| let mut exprs = vec![ | ||
| Expr::components( | ||
| self.graph | ||
| .successors(component_id)? | ||
| .map(|x| x.component_id()), | ||
| ) | ||
| .into_iter() | ||
| .reduce(|a, b| a + b) | ||
| .ok_or(Error::internal( | ||
| "Can't find successors of components with successors.", | ||
| ))?, | ||
| Expr::component(component_id), | ||
| ]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either I don't understand this fragment or it is over complicated.
Would something like this work? It is just an idea
let successors = self.graph.successors(component_id)?;
if successors.len() == 0 || successors.all(|x| x.is_supported()) == false:
return Ok(Some(Expr::component(component_id)));
let fallback_expr = successors.map(|node| Expr::component(node.component_id)).reduce(|a, b| a + b))?
exprs = match self.prefer_meters:
true => vec![Expr::component(component_id), fallback_expr]
false => vec![ fallback_expr, Expr::component(component_id)]
return Ok(Some(Expr::coalesce(exprs)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, it was possibly too nested. I've simplified this as suggested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more comment to this below.
Signed-off-by: Sahas Subramanian <[email protected]>
d23964c to
c0c3d59
Compare
Signed-off-by: Sahas Subramanian <[email protected]>
They will be generated from our inline doc comments and become available at docs.rs when we publish to crates.io.
More documentation is necessary, especially definitions of formula components, instructions for using the formulas, and explanations for the algorithms. But I'll get to those after the formulas and algorithms have stabilized; otherwise, I'll spend all my time rewriting the docs. |
ela-kotulska-frequenz
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checked until Add the consumer formula generator
| /// the matching components. | ||
| pub(crate) fn find_all( | ||
| &self, | ||
| from: u64, | ||
| mut pred: impl FnMut(&N) -> bool, | ||
| follow_after_match: bool, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: I don't understand why it is called find_all?
Because It doesn't finds all nodes. It finds only nodes in direction outgoing. :)
Maybe find_with_pred would be more descriptive?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initially, it also had a direction parameter, but I realized we didn't need it. I will think of an option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added a direction parameter as a filter instead.
Signed-off-by: Sahas Subramanian <[email protected]>
Fallback expressions may be used when the primary expressions are missing values. Signed-off-by: Sahas Subramanian <[email protected]>
Signed-off-by: Sahas Subramanian <[email protected]>
Signed-off-by: Sahas Subramanian <[email protected]>
Signed-off-by: Sahas Subramanian <[email protected]>
Signed-off-by: Sahas Subramanian <[email protected]>
Signed-off-by: Sahas Subramanian <[email protected]>
Signed-off-by: Sahas Subramanian <[email protected]>
Signed-off-by: Sahas Subramanian <[email protected]>
Signed-off-by: Sahas Subramanian <[email protected]>
Signed-off-by: Sahas Subramanian <[email protected]>
Signed-off-by: Sahas Subramanian <[email protected]>
With the new consumer power formula, it is no longer necessary to identify meters as grid meters. So this method can go away. If the SDK's traversal algorithms need it, they can use their own temporary implementation, until they can migrate to the new formulas. Signed-off-by: Sahas Subramanian <[email protected]>
Signed-off-by: Sahas Subramanian <[email protected]>
All components now have a fallback to 0.0, so this check is no longer necessary. Signed-off-by: Sahas Subramanian <[email protected]>
Earlier the direction was hard coded, which made it unclear that the method was only finding outgoing nodes. Signed-off-by: Sahas Subramanian <[email protected]>
This PR adds formula generators for various microgrid metrics that traverse the graph to produce and return string formulas.