From c3a2ece1e259ff3d0251fefe16cc7a422ddca0ad Mon Sep 17 00:00:00 2001 From: Guillermo Ramos Date: Fri, 14 Mar 2025 11:52:09 +0100 Subject: Minucias minucias --- front/.gitignore | 3 +-- front/src/Main.elm | 12 ++++-------- src/bin/web.rs | 1 - src/lib.rs | 27 ++++++++++++++++++--------- 4 files changed, 23 insertions(+), 20 deletions(-) diff --git a/front/.gitignore b/front/.gitignore index 3a587bf..02c2f93 100644 --- a/front/.gitignore +++ b/front/.gitignore @@ -1,5 +1,4 @@ elm-stuff -index.html +node_modules main.js main.css -node_modules diff --git a/front/src/Main.elm b/front/src/Main.elm index ad8862b..57a6f11 100644 --- a/front/src/Main.elm +++ b/front/src/Main.elm @@ -358,7 +358,7 @@ periodicUpdateDecoder = type alias SimUpdates = { periodically : List PeriodicUpdate - , byMonth : List ( Int, List SimUpdate ) + , byMonth : List ( Int, SimUpdate ) } @@ -380,11 +380,7 @@ simUpdatesEncode { periodically, byMonth } = [ ( "periodically", JE.list periodicUpdateEncode periodically ) , ( "by_month" , JE.object <| - List.map - (\( m, us ) -> - ( String.fromInt m, JE.list simUpdateEncode us ) - ) - byMonth + List.map (\( m, us ) -> ( String.fromInt m, simUpdateEncode us )) byMonth ) ] @@ -394,7 +390,7 @@ simUpdatesDecoder = JD.map2 SimUpdates (JD.field "periodically" (JD.list periodicUpdateDecoder)) (JD.field "by_month" - (JD.keyValuePairs (JD.list simUpdateDecoder) + (JD.keyValuePairs simUpdateDecoder |> JD.map (\l -> List.map (\( k, v ) -> ( Maybe.withDefault 0 (String.toInt k), v )) l @@ -1093,7 +1089,7 @@ quotaView m { updates } { month, payed, pending_principal } = , div [] (List.map (simUpdateView [ class "bg-lime-200" ] m << .upd) monthUpdates.periodically ++ (List.map (simUpdateView [ class "bg-lime-200" ] m) <| - List.concatMap Tuple.second monthUpdates.byMonth + List.map Tuple.second monthUpdates.byMonth ) ) ) 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) -> Json { 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) } diff --git a/src/lib.rs b/src/lib.rs index 597a360..6d95ff4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -225,7 +225,7 @@ pub struct PeriodicUpdate { #[derive(Debug, Default, Serialize, Deserialize)] pub struct SimUpdates { periodically: Vec, - by_month: HashMap>, + by_month: HashMap, } 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 } } -- cgit v1.2.3