Skip to content

Commit

Permalink
Implemented NegativeMaxParameter and NegativeMinParameter (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
s-simoncelli authored Dec 19, 2023
1 parent be50d68 commit 67dbd67
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
28 changes: 28 additions & 0 deletions pywr_schema/src/parameters/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,34 @@ impl MinParameter {
}
}

#[derive(serde::Deserialize, serde::Serialize, Debug, Clone, PywrParameter)]
pub struct NegativeMinParameter {
#[serde(flatten)]
pub meta: Option<ParameterMeta>,
pub parameter: ParameterValue,
pub threshold: Option<f64>,
}

impl NegativeMinParameter {
pub fn node_references(&self) -> HashMap<&str, &str> {
HashMap::new()
}
}

#[derive(serde::Deserialize, serde::Serialize, Debug, Clone, PywrParameter)]
pub struct NegativeMaxParameter {
#[serde(flatten)]
pub meta: Option<ParameterMeta>,
pub parameter: ParameterValue,
pub threshold: Option<f64>,
}

impl NegativeMaxParameter {
pub fn node_references(&self) -> HashMap<&str, &str> {
HashMap::new()
}
}

#[derive(serde::Deserialize, serde::Serialize, Debug, Clone, PywrParameter)]
pub struct DivisionParameter {
#[serde(flatten)]
Expand Down
29 changes: 28 additions & 1 deletion pywr_schema/src/parameters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ pub use crate::parameters::control_curves::{
ControlCurvePiecewiseInterpolatedParameter,
};
pub use crate::parameters::core::{
ConstantParameter, DivisionParameter, MaxParameter, MinParameter, NegativeParameter,
ConstantParameter, DivisionParameter, MaxParameter, MinParameter, NegativeMaxParameter,
NegativeMinParameter, NegativeParameter,
};
pub use crate::parameters::deficit::DeficitParameter;
pub use crate::parameters::discount_factor::DiscountFactorParameter;
Expand Down Expand Up @@ -164,6 +165,18 @@ pub enum CoreParameter {
Max(MaxParameter),
#[serde(alias = "min", alias = "minparameter", alias = "MinParameter")]
Min(MinParameter),
#[serde(
alias = "negativemin",
alias = "negativeminparameter",
alias = "NegativeMinParameter"
)]
NegativeMin(NegativeMinParameter),
#[serde(
alias = "negativemax",
alias = "negativemaxparameter",
alias = "NegativeMaxParameter"
)]
NegativeMax(NegativeMaxParameter),
#[serde(
alias = "division",
alias = "divisionparameter",
Expand Down Expand Up @@ -278,6 +291,8 @@ impl CoreParameter {
Self::UniformDrawdownProfile(p) => p.meta.as_ref().and_then(|m| m.name.as_deref()),
Self::Max(p) => p.meta.as_ref().and_then(|m| m.name.as_deref()),
Self::Min(p) => p.meta.as_ref().and_then(|m| m.name.as_deref()),
Self::NegativeMin(p) => p.meta.as_ref().and_then(|m| m.name.as_deref()),
Self::NegativeMax(p) => p.meta.as_ref().and_then(|m| m.name.as_deref()),
Self::Division(p) => p.meta.as_ref().and_then(|m| m.name.as_deref()),
Self::Negative(p) => p.meta.as_ref().and_then(|m| m.name.as_deref()),
Self::Polynomial1D(p) => p.meta.as_ref().and_then(|m| m.name.as_deref()),
Expand Down Expand Up @@ -313,6 +328,8 @@ impl CoreParameter {
Self::WeeklyProfile(p) => p.node_references(),
Self::UniformDrawdownProfile(p) => p.node_references(),
Self::Max(p) => p.node_references(),
Self::NegativeMin(p) => p.node_references(),
Self::NegativeMax(p) => p.node_references(),
Self::Min(p) => p.node_references(),
Self::Division(p) => p.node_references(),
Self::Negative(p) => p.node_references(),
Expand Down Expand Up @@ -348,6 +365,8 @@ impl CoreParameter {
Self::MonthlyProfile(p) => p.parameters(),
Self::WeeklyProfile(p) => p.parameters(),
Self::UniformDrawdownProfile(p) => p.parameters(),
Self::NegativeMin(p) => p.parameters(),
Self::NegativeMax(p) => p.parameters(),
Self::Min(p) => p.parameters(),
Self::Max(p) => p.parameters(),
Self::Division(p) => p.parameters(),
Expand Down Expand Up @@ -384,6 +403,8 @@ impl CoreParameter {
Self::MonthlyProfile(p) => p.parameters_mut(),
Self::WeeklyProfile(p) => p.parameters_mut(),
Self::UniformDrawdownProfile(p) => p.parameters_mut(),
Self::NegativeMax(p) => p.parameters_mut(),
Self::NegativeMin(p) => p.parameters_mut(),
Self::Min(p) => p.parameters_mut(),
Self::Max(p) => p.parameters_mut(),
Self::Division(p) => p.parameters_mut(),
Expand Down Expand Up @@ -423,6 +444,8 @@ impl CoreParameter {
Self::Max(_) => "Max",
Self::Min(_) => "Min",
Self::Division(_) => "Division",
Self::NegativeMin(_) => "NegativeMin",
Self::NegativeMax(_) => "NegativeMax",
Self::Negative(_) => "Negative",
Self::Polynomial1D(_) => "Polynomial1D",
Self::ParameterThreshold(_) => "ParameterThreshold",
Expand Down Expand Up @@ -461,6 +484,8 @@ impl CoreParameter {
CoreParameter::Min(p) => p.resource_paths(),
CoreParameter::Division(p) => p.resource_paths(),
CoreParameter::Negative(p) => p.resource_paths(),
CoreParameter::NegativeMin(p) => p.resource_paths(),
CoreParameter::NegativeMax(p) => p.resource_paths(),
CoreParameter::Polynomial1D(p) => p.resource_paths(),
CoreParameter::ParameterThreshold(p) => p.resource_paths(),
CoreParameter::TablesArray(p) => p.resource_paths(),
Expand Down Expand Up @@ -517,6 +542,8 @@ impl CoreParameter {
CoreParameter::Min(p) => p.update_resource_paths(new_paths),
CoreParameter::Division(p) => p.update_resource_paths(new_paths),
CoreParameter::Negative(p) => p.update_resource_paths(new_paths),
CoreParameter::NegativeMin(p) => p.update_resource_paths(new_paths),
CoreParameter::NegativeMax(p) => p.update_resource_paths(new_paths),
CoreParameter::Polynomial1D(p) => p.update_resource_paths(new_paths),
CoreParameter::ParameterThreshold(p) => p.update_resource_paths(new_paths),
CoreParameter::TablesArray(p) => p.update_resource_paths(new_paths),
Expand Down

0 comments on commit 67dbd67

Please sign in to comment.