-
Notifications
You must be signed in to change notification settings - Fork 4
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
feat: add returned_metric attribute to threshold parameter #331
Conversation
This optional attribute contains metrics to be returned by the parameter. It is equivalent to the values attribute of the v1 threshold parameters and enables conversions of v1 parameters that specify this attribute.
pywr-schema/src/parameters/mod.rs
Outdated
@@ -191,7 +191,18 @@ impl Parameter { | |||
Self::Min(p) => pywr_core::parameters::ParameterType::Parameter(p.add_to_model(network, args)?), | |||
Self::Negative(p) => pywr_core::parameters::ParameterType::Parameter(p.add_to_model(network, args)?), | |||
Self::Polynomial1D(p) => pywr_core::parameters::ParameterType::Parameter(p.add_to_model(network, args)?), | |||
Self::Threshold(p) => pywr_core::parameters::ParameterType::Index(p.add_to_model(network, args)?), | |||
Self::Threshold(p) => match p.add_to_model(network, args)? { |
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.
p.add_to_model
already returns a ParameterType
?
@@ -54,13 +55,37 @@ impl From<Predicate> for pywr_core::parameters::Predicate { | |||
} | |||
} | |||
|
|||
/// A parameter that compares a metric against a threshold metric | |||
/// | |||
/// The metrics are compared using the given predicate and the result is returned as an index. If the comparison |
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.
This needs to say that the returned metrics are used instead if given.
/// is set as the index parameter of a [`pywr_core::parameters::IndexedArrayParameter`] containing the `returned_metrics` | ||
/// values. | ||
/// | ||
/// An equivalent representation could be achieved by defining the two parameters in the schema directly: |
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.
Expand this to compare the approach with one parameter and two.
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 minor comment and a request to make the IndexMetric
change in a different PR. Otherwise LGTM.
@@ -472,7 +472,7 @@ impl EdgeReference { | |||
/// This struct is the integer equivalent of [`Metric`] and is used in places where an integer | |||
/// value is required. See [`Metric`] for more information. | |||
#[derive(serde::Deserialize, serde::Serialize, Debug, Clone, JsonSchema, Display, PartialEq)] | |||
#[serde(untagged)] | |||
#[serde(tag = "type")] |
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.
Can we do this in a separate PR?
pywr-schema/src/parameters/mod.rs
Outdated
let _ = serde_json::from_value::<Vec<Parameter>>(value) | ||
.unwrap_or_else(|_| panic!("Failed to deserialize: {:?}", p)); | ||
} | ||
_ => panic!("Expected JSON object: {:?}", p), |
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.
"... JSON object or array."
This optional attribute contains metrics to be returned by the parameter. It is equivalent to the values attribute of the v1 threshold parameters and enables conversions of v1 parameters that specify this attribute.