aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillermo Ramos2025-03-14 11:52:09 +0100
committerGuillermo Ramos2025-03-15 20:05:59 +0100
commitc3a2ece1e259ff3d0251fefe16cc7a422ddca0ad (patch)
treee16fb9aed22a44b55cec170bbd322991a5fbec97
parent1a552ee15578c028fe05cef08e3e590f10a6f07d (diff)
downloadhiccup-c3a2ece1e259ff3d0251fefe16cc7a422ddca0ad.tar.gz
Minucias minucias
-rw-r--r--front/.gitignore3
-rw-r--r--front/src/Main.elm12
-rw-r--r--src/bin/web.rs1
-rw-r--r--src/lib.rs27
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<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)
}
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<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
}
}