Skip to content

Commit

Permalink
feat: Add RbfProfileParameter. (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
jetuk authored Oct 26, 2023
1 parent dff428b commit 1575d33
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pywr_schema/src/parameters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub use crate::parameters::hydropower::HydropowerTargetParameter;
pub use crate::parameters::indexed_array::IndexedArrayParameter;
pub use crate::parameters::interpolated::{InterpolatedFlowParameter, InterpolatedVolumeParameter};
pub use crate::parameters::polynomial::Polynomial1DParameter;
use crate::parameters::profiles::RbfProfileParameter;
pub use crate::parameters::profiles::{
DailyProfileParameter, MonthInterpDay, MonthlyProfileParameter, UniformDrawdownProfileParameter,
};
Expand Down Expand Up @@ -243,6 +244,12 @@ pub enum CoreParameter {
ScenarioWrapper(ScenarioWrapperParameter),
#[serde(alias = "flow", alias = "flowparameter", alias = "FlowParameter")]
Flow(FlowParameter),
#[serde(
alias = "rbfprofile",
alias = "rbfprofileparameter",
alias = "RbfProfileParameter"
)]
RbfProfile(RbfProfileParameter),
}

impl CoreParameter {
Expand Down Expand Up @@ -279,6 +286,7 @@ impl CoreParameter {
Self::RollingMeanFlowNode(p) => p.meta.as_ref().and_then(|m| m.name.as_deref()),
Self::ScenarioWrapper(p) => p.meta.as_ref().and_then(|m| m.name.as_deref()),
Self::Flow(p) => p.meta.as_ref().and_then(|m| m.name.as_deref()),
Self::RbfProfile(p) => p.meta.as_ref().and_then(|m| m.name.as_deref()),
}
}

Expand Down Expand Up @@ -313,6 +321,7 @@ impl CoreParameter {
Self::RollingMeanFlowNode(p) => p.node_references(),
Self::ScenarioWrapper(p) => p.node_references(),
Self::Flow(p) => p.node_references(),
Self::RbfProfile(p) => p.node_references(),
}
}

Expand Down Expand Up @@ -347,6 +356,7 @@ impl CoreParameter {
Self::RollingMeanFlowNode(p) => p.parameters(),
Self::ScenarioWrapper(p) => p.parameters(),
Self::Flow(p) => p.parameters(),
Self::RbfProfile(p) => p.parameters(),
}
}

Expand Down Expand Up @@ -381,6 +391,7 @@ impl CoreParameter {
Self::RollingMeanFlowNode(p) => p.parameters_mut(),
Self::ScenarioWrapper(p) => p.parameters_mut(),
Self::Flow(p) => p.parameters_mut(),
Self::RbfProfile(p) => p.parameters_mut(),
}
}

Expand Down Expand Up @@ -415,6 +426,7 @@ impl CoreParameter {
Self::RollingMeanFlowNode(_) => "RollingMeanFlowNode",
Self::ScenarioWrapper(_) => "ScenarioWrapper",
Self::Flow(_) => "Flow",
Self::RbfProfile(_) => "RbfProfile",
}
}

Expand Down Expand Up @@ -450,6 +462,7 @@ impl CoreParameter {
CoreParameter::RollingMeanFlowNode(p) => p.resource_paths(),
CoreParameter::ScenarioWrapper(p) => p.resource_paths(),
CoreParameter::Flow(p) => p.resource_paths(),
CoreParameter::RbfProfile(p) => p.resource_paths(),
}
}

Expand Down Expand Up @@ -504,6 +517,7 @@ impl CoreParameter {
CoreParameter::RollingMeanFlowNode(p) => p.update_resource_paths(new_paths),
CoreParameter::ScenarioWrapper(p) => p.update_resource_paths(new_paths),
CoreParameter::Flow(p) => p.update_resource_paths(new_paths),
CoreParameter::RbfProfile(p) => p.update_resource_paths(new_paths),
}
}

Expand Down
20 changes: 20 additions & 0 deletions pywr_schema/src/parameters/profiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,23 @@ impl UniformDrawdownProfileParameter {
HashMap::new()
}
}

#[derive(serde::Deserialize, serde::Serialize, Debug, Clone, PywrParameter)]
pub struct RbfProfileParameter {
#[serde(flatten)]
pub meta: Option<ParameterMeta>,
pub days_of_year: Vec<u32>,
pub values: Vec<f64>,
pub lower_bounds: Option<f64>,
pub upper_bounds: Option<f64>,
pub variable_days_of_year_range: Option<u32>,
pub min_value: Option<f64>,
pub max_value: Option<f64>,
pub rbf_kwargs: HashMap<String, serde_json::Value>,
}

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

0 comments on commit 1575d33

Please sign in to comment.