aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillermo Ramos2025-03-14 11:52:09 +0100
committerGuillermo Ramos2025-03-15 13:33:30 +0100
commita05b9066900a017ac75e77e687f5414ad6f8d25a (patch)
treec85eb5a1519a4c8b50fb6fc9c6d5e9dfe19b3c12
parent8dff02998db9eac1efacf555ccbdec198d7fe213 (diff)
downloadhiccup-a05b9066900a017ac75e77e687f5414ad6f8d25a.tar.gz
New update: change interest rate
-rw-r--r--front/src/Main.elm26
-rw-r--r--src/bin/cli.rs3
-rw-r--r--src/lib.rs11
3 files changed, 34 insertions, 6 deletions
diff --git a/front/src/Main.elm b/front/src/Main.elm
index bc3f763..ad8862b 100644
--- a/front/src/Main.elm
+++ b/front/src/Main.elm
@@ -271,6 +271,7 @@ modelToUrl { settings, rawSpecs } =
type SimUpdate
= Amortize Float
+ | SetI1 Float
simUpdateEncode : SimUpdate -> JE.Value
@@ -279,28 +280,35 @@ simUpdateEncode mupdate =
Amortize f ->
JE.object [ ( "Amortize", JE.float f ) ]
+ SetI1 f ->
+ JE.object [ ( "SetI1", JE.float f ) ]
+
simUpdateDecoder : JD.Decoder SimUpdate
simUpdateDecoder =
JD.oneOf
[ JD.field "Amortize" <| JD.map Amortize JD.float
+ , JD.field "SetI1" <| JD.map SetI1 JD.float
]
simUpdateFlatten : List SimUpdate -> List SimUpdate
simUpdateFlatten us =
let
- { amortized } =
+ { amortized, other } =
List.foldr
(\upd acc ->
case upd of
Amortize f ->
{ acc | amortized = acc.amortized + f }
+
+ SetI1 f ->
+ { acc | other = upd :: acc.other }
)
- { amortized = 0 }
+ { amortized = 0, other = [] }
us
in
- [ Amortize amortized ]
+ Amortize amortized :: other
type alias PeriodicUpdate =
@@ -1046,7 +1054,10 @@ simUpdateView : List (Attribute Msg) -> Model -> SimUpdate -> Html Msg
simUpdateView attrs m upd =
case upd of
Amortize f ->
- span attrs [ text "+", amountView m.settings.currency f ]
+ p attrs [ text "+", amountView m.settings.currency f ]
+
+ SetI1 f ->
+ p attrs [ text <| String.fromFloat f, text "%" ]
quotaView : Model -> MortgageSim -> Quota -> Html Msg
@@ -1079,7 +1090,12 @@ quotaView m { updates } { month, payed, pending_principal } =
else
( text ""
- , div [] (List.map (simUpdateView [ class "bg-lime-200" ] m << .upd) <| monthUpdates.periodically)
+ , 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
+ )
+ )
)
in
if modBy 12 (month - 1) == 0 || monthInExpandedYear then
diff --git a/src/bin/cli.rs b/src/bin/cli.rs
index 5ca388b..2dae8ec 100644
--- a/src/bin/cli.rs
+++ b/src/bin/cli.rs
@@ -2,7 +2,8 @@ use hiccup::{SimUpdate::*, SimUpdates, Simulation};
fn main() {
let mut sim = Simulation::new(390_000., 0.028, 30);
- let updates: SimUpdates = Amortize(12_000.).every(12).and(Amortize(30_000.).at(1));
+ let updates: SimUpdates = Amortize(12_000.).every(12).and(Amortize(30_000.).at(1))
+ .and(SetI1(0.01).at(10));
// let mut sim = Simulation::new(200_000., 0.01621, 30);
// let updates: SimUpdates = SimUpdates::default();
diff --git a/src/lib.rs b/src/lib.rs
index 1f4a977..597a360 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -90,6 +90,10 @@ impl Simulation {
self.payed.principal += principal;
self.payed_amortized += principal;
}
+ SimUpdate::SetI1(i1) => {
+ st.i12 = i1 / 12.0;
+ st.calculate_monthly();
+ }
}
}
}
@@ -261,6 +265,7 @@ impl SimUpdates {
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
pub enum SimUpdate {
Amortize(f64),
+ SetI1(f64),
}
impl fmt::Display for SimUpdate {
@@ -270,6 +275,9 @@ impl fmt::Display for SimUpdate {
Self::Amortize(principal) => {
write!(f, "{principal:.2} amortized to reduce pending quotas]")
}
+ Self::SetI1(i1) => {
+ write!(f, "I1 set to {i1:.2}]")
+ }
}
}
}
@@ -296,6 +304,9 @@ fn flatten_amortizations(updates: Vec<SimUpdate>) -> Vec<SimUpdate> {
SimUpdate::Amortize(n) => {
amortized += n;
}
+ SimUpdate::SetI1(_) => {
+ result.push(update);
+ }
}
}
if amortized > 0. {