diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/bin/web.rs | 1 | ||||
-rw-r--r-- | src/lib.rs | 27 |
2 files changed, 18 insertions, 10 deletions
diff --git a/src/bin/web.rs b/src/bin/web.rs index 0384d7f..71b060b 100644 --- a/src/bin/web.rs +++ b/src/bin/web.rs @@ -50,7 +50,6 @@ struct SimSpecs { async fn api_simulate_post(Json(specs): Json<SimSpecs>) -> Json<hiccup::Simulation> { let mut sim = Simulation::new(specs.principal, specs.i1, specs.years); let updates: SimUpdates = specs.updates; - // let updates: SimUpdates = SimUpdates::default(); sim.run(updates); Json(sim) } @@ -225,7 +225,7 @@ pub struct PeriodicUpdate { #[derive(Debug, Default, Serialize, Deserialize)] pub struct SimUpdates { periodically: Vec<PeriodicUpdate>, - by_month: HashMap<u32, Vec<SimUpdate>>, + by_month: HashMap<u32, SimUpdate>, } impl SimUpdates { @@ -236,16 +236,20 @@ impl SimUpdates { } = self; let mut ret = vec![]; - for PeriodicUpdate{period, from, to, update} in periodically.iter() { + for PeriodicUpdate { + period, + from, + to, + update, + } in periodically.iter() + { let base = from.unwrap_or(0); - if month % period == base && base <= month && to.unwrap_or(month+1) > month { + if month % period == base && base <= month && to.unwrap_or(month + 1) > month { ret.push(*update); } } - if let Some(updates) = by_month.get(&month) { - for update in updates.iter() { - ret.push(*update); - } + if let Some(update) = by_month.get(&month) { + ret.push(*update); } // println!(" {self:?}.get({month}) -> {ret:?}"); ret @@ -285,13 +289,18 @@ impl fmt::Display for SimUpdate { impl SimUpdate { pub fn every(&self, months: u32) -> SimUpdates { let mut updates = SimUpdates::default(); - updates.periodically.push(PeriodicUpdate{period: months, from: None, to: None, update: *self}); + updates.periodically.push(PeriodicUpdate { + period: months, + from: None, + to: None, + update: *self, + }); updates } pub fn at(&self, month: u32) -> SimUpdates { let mut updates = SimUpdates::default(); - updates.by_month.insert(month, vec![*self]); + updates.by_month.insert(month, *self); updates } } |