diff --git a/Cargo.toml b/Cargo.toml index 07e2a22e..e6e525a1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -46,5 +46,5 @@ pyo3-log = "0.9.0" tracing = { version = "0.1", features = ["log"] } csv = "1.1" hdf5 = { git = "https://github.com/aldanor/hdf5-rust.git", package = "hdf5", features = ["static", "zlib"] } -pywr-v1-schema = { git = "https://github.com/pywr/pywr-schema/", tag = "v0.11.0", package = "pywr-schema" } -chrono = { version = "0.4.34" } \ No newline at end of file +pywr-v1-schema = { git = "https://github.com/pywr/pywr-schema/", tag = "v0.12.0", package = "pywr-schema" } +chrono = { version = "0.4.34" } diff --git a/pywr-schema/src/model.rs b/pywr-schema/src/model.rs index 374b2b99..524c33f1 100644 --- a/pywr-schema/src/model.rs +++ b/pywr-schema/src/model.rs @@ -74,6 +74,15 @@ pub enum DateType { DateTime(NaiveDateTime), } +impl From for DateType { + fn from(v1: pywr_v1_schema::model::DateType) -> Self { + match v1 { + pywr_v1_schema::model::DateType::Date(date) => Self::Date(date), + pywr_v1_schema::model::DateType::DateTime(date_time) => Self::DateTime(date_time), + } + } +} + #[derive(serde::Deserialize, serde::Serialize, Clone, Debug)] pub struct Timestepper { pub start: DateType, @@ -91,25 +100,13 @@ impl Default for Timestepper { } } -impl TryFrom for Timestepper { - type Error = ConversionError; - - fn try_from(v1: pywr_v1_schema::model::Timestepper) -> Result { - let start = DateType::Date( - NaiveDate::from_ymd_opt(v1.start.year(), v1.start.month() as u32, v1.start.day() as u32) - .ok_or(ConversionError::UnparseableDate(v1.start.to_string()))?, - ); - - let end = DateType::Date( - NaiveDate::from_ymd_opt(v1.end.year(), v1.end.month() as u32, v1.end.day() as u32) - .ok_or(ConversionError::UnparseableDate(v1.end.to_string()))?, - ); - - Ok(Self { - start, - end, +impl From for Timestepper { + fn from(v1: pywr_v1_schema::model::Timestepper) -> Self { + Self { + start: v1.start.into(), + end: v1.end.into(), timestep: v1.timestep.into(), - }) + } } } @@ -457,10 +454,7 @@ impl PywrModel { Metadata::default() }); - let timestepper = v1.timestepper.try_into().unwrap_or_else(|e| { - errors.push(e); - Timestepper::default() - }); + let timestepper = v1.timestepper.into(); // Extract nodes and any timeseries data from the v1 nodes let nodes_and_ts: Vec = v1 diff --git a/pywr-schema/src/nodes/annual_virtual_storage.rs b/pywr-schema/src/nodes/annual_virtual_storage.rs index 7b5ab111..fb04fddc 100644 --- a/pywr-schema/src/nodes/annual_virtual_storage.rs +++ b/pywr-schema/src/nodes/annual_virtual_storage.rs @@ -179,7 +179,7 @@ impl TryFrom for AnnualVirtualStorageNode { cost, initial_volume, reset: AnnualReset { - day: v1.reset_day, + day: v1.reset_day as u8, month, use_initial_volume: v1.reset_to_initial_volume, },