aboutsummaryrefslogtreecommitdiff
path: root/front/src
diff options
context:
space:
mode:
authorGuillermo Ramos2025-03-08 11:50:04 +0100
committerGuillermo Ramos2025-03-08 12:04:12 +0100
commit12879e066a55ef0d7567d9474f8b6ae815cfb08c (patch)
tree789025afa124d18ddaef68030528bdf6ca25b0eb /front/src
parent1471379224cee42026f53a79fc5574069664998c (diff)
downloadhiccup-12879e066a55ef0d7567d9474f8b6ae815cfb08c.tar.gz
Refactor variable names
Diffstat (limited to 'front/src')
-rw-r--r--front/src/Main.elm72
1 files changed, 36 insertions, 36 deletions
diff --git a/front/src/Main.elm b/front/src/Main.elm
index 88a5ee7..c6f63f6 100644
--- a/front/src/Main.elm
+++ b/front/src/Main.elm
@@ -113,9 +113,9 @@ simDecoder =
type alias RawSpecs =
{ title : String
- , totalValue : String
+ , total : String
, initial : String
- , financedRate : String
+ , rate : String
, i1 : String
, years : String
}
@@ -124,9 +124,9 @@ type alias RawSpecs =
defaultRawSpecs : RawSpecs
defaultRawSpecs =
{ title = ""
- , totalValue = "200000"
+ , total = "200000"
, initial = "40000"
- , financedRate = "80"
+ , rate = "80"
, i1 = "1.621"
, years = "30"
}
@@ -136,20 +136,20 @@ rawSpecsParser : UQ.Parser RawSpecs
rawSpecsParser =
UQ.map6 RawSpecs
(UQ.map (Maybe.withDefault defaultRawSpecs.title) <| UQ.string "title")
- (UQ.map (Maybe.withDefault defaultRawSpecs.totalValue) <| UQ.string "totalValue")
+ (UQ.map (Maybe.withDefault defaultRawSpecs.total) <| UQ.string "total")
(UQ.map (Maybe.withDefault defaultRawSpecs.initial) <| UQ.string "initial")
- (UQ.map (Maybe.withDefault defaultRawSpecs.financedRate) <| UQ.string "financedRate")
+ (UQ.map (Maybe.withDefault defaultRawSpecs.rate) <| UQ.string "rate")
(UQ.map (Maybe.withDefault defaultRawSpecs.i1) <| UQ.string "i1")
(UQ.map (Maybe.withDefault defaultRawSpecs.years) <| UQ.string "years")
rawSpecsToURL : RawSpecs -> String
-rawSpecsToURL { title, totalValue, initial, financedRate, i1, years } =
+rawSpecsToURL { title, total, initial, rate, i1, years } =
UB.toQuery <|
[ UB.string "title" title
- , UB.string "totalValue" totalValue
+ , UB.string "total" total
, UB.string "initial" initial
- , UB.string "financedRate" financedRate
+ , UB.string "rate" rate
, UB.string "i1" i1
, UB.string "years" years
]
@@ -163,14 +163,14 @@ type alias MortgageSpecs =
parseMortgageSpecs : RawSpecs -> Maybe MortgageSpecs
-parseMortgageSpecs { totalValue, financedRate, i1, years } =
+parseMortgageSpecs { total, rate, i1, years } =
case
- ( List.map String.toFloat [ totalValue, i1 ]
- , List.map String.toInt [ financedRate, years ]
+ ( List.map String.toFloat [ total, i1 ]
+ , List.map String.toInt [ rate, years ]
)
of
- ( [ Just totalValueF, Just i1F ], [ Just rate, Just yearsI ] ) ->
- Just { principal = totalValueF * toFloat rate / 100, i1 = i1F, years = yearsI }
+ ( [ Just totalValueF, Just i1F ], [ Just rateI, Just yearsI ] ) ->
+ Just { principal = totalValueF * toFloat rateI / 100, i1 = i1F, years = yearsI }
_ ->
Nothing
@@ -233,7 +233,7 @@ init : () -> Url -> Nav.Key -> ( Model, Cmd Msg )
init () url navKey =
( { navKey = navKey
, error = ""
- , rawSpecs = routeQuery (toRoute url)
+ , rawSpecs = Debug.log "set rawSpecs" <| routeQuery (toRoute url)
, expandedYears = Set.empty
, simulation = Nothing
}
@@ -256,8 +256,8 @@ rateToInitial rate principal =
convertInitialRate : (Float -> Int -> Float) -> String -> String -> Maybe String
-convertInitialRate convert val totalValue =
- case ( String.toFloat val, String.toInt totalValue ) of
+convertInitialRate convert val total =
+ case ( String.toFloat val, String.toInt total ) of
( Just x, Just totalValueF ) ->
Just <| String.fromFloat <| convert x totalValueF
@@ -292,7 +292,7 @@ errorToString error =
type SpecField
= Title
- | Principal
+ | TotalValue
| Rate
| Initial
| I1
@@ -353,28 +353,28 @@ update msg m =
Title ->
{ rawSpecs | title = val }
- Principal ->
+ TotalValue ->
{ rawSpecs
- | totalValue = val
+ | total = val
, initial =
Maybe.withDefault rawSpecs.initial <|
- convertInitialRate rateToInitial rawSpecs.financedRate val
+ convertInitialRate rateToInitial rawSpecs.rate val
}
Rate ->
{ rawSpecs
- | financedRate = val
+ | rate = val
, initial =
Maybe.withDefault rawSpecs.initial <|
- convertInitialRate rateToInitial val rawSpecs.totalValue
+ convertInitialRate rateToInitial val rawSpecs.total
}
Initial ->
{ rawSpecs
| initial = val
- , financedRate =
- Maybe.withDefault rawSpecs.financedRate <|
- convertInitialRate initialToRate val rawSpecs.totalValue
+ , rate =
+ Maybe.withDefault rawSpecs.rate <|
+ convertInitialRate initialToRate val rawSpecs.total
}
I1 ->
@@ -435,7 +435,7 @@ slider attributes onInputMsg valueTxt =
specsView : RawSpecs -> Html Msg
specsView rawSpecs =
let
- { title, totalValue, financedRate, initial, i1, years } =
+ { title, total, rate, initial, i1, years } =
rawSpecs
simButAttrs =
@@ -458,17 +458,17 @@ specsView rawSpecs =
]
, div [ class "flex my-1" ]
[ text "Property price: "
- , slider [ Html.Attributes.min "0", Html.Attributes.max "1000000", step "5000" ]
- (UpdateSpecs Principal)
- totalValue
- , txtInput [ class "w-[100px]", Html.Attributes.min "0", Html.Attributes.max "1000000" ]
- (UpdateSpecs Principal)
- totalValue
+ , slider [ Html.Attributes.min "50000", Html.Attributes.max "800000", step "5000" ]
+ (UpdateSpecs TotalValue)
+ total
+ , txtInput [ class "w-[100px]", Html.Attributes.min "0" ]
+ (UpdateSpecs TotalValue)
+ total
]
, div [ class "flex my-1" ]
[ div [ class "" ]
[ text "Initial contribution: "
- , txtInput [ class "w-[100px]", Html.Attributes.min "0", Html.Attributes.max totalValue ]
+ , txtInput [ class "w-[100px]", Html.Attributes.min "0", Html.Attributes.max total ]
(UpdateSpecs Initial)
initial
]
@@ -476,7 +476,7 @@ specsView rawSpecs =
[ text " ("
, txtInput [ class "w-[55px]", Html.Attributes.min "10", Html.Attributes.max "100" ]
(UpdateSpecs Rate)
- financedRate
+ rate
, text "%)"
]
]
@@ -489,7 +489,7 @@ specsView rawSpecs =
]
, div [ class "flex my-1 mb-2" ]
[ text "Years: "
- , slider [ Html.Attributes.min "1", Html.Attributes.max "50", step "1" ]
+ , slider [ Html.Attributes.min "1", Html.Attributes.max "40", step "1" ]
(UpdateSpecs Years)
years
, text years