aboutsummaryrefslogtreecommitdiff
path: root/src/client/elm/Model/Income.elm
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/elm/Model/Income.elm')
-rw-r--r--src/client/elm/Model/Income.elm24
1 files changed, 12 insertions, 12 deletions
diff --git a/src/client/elm/Model/Income.elm b/src/client/elm/Model/Income.elm
index c0039e9..7eaa77f 100644
--- a/src/client/elm/Model/Income.elm
+++ b/src/client/elm/Model/Income.elm
@@ -25,7 +25,7 @@ type alias IncomeId = Int
type alias Income =
{ userId : UserId
- , creation : Time
+ , time : Float
, amount : Int
}
@@ -45,15 +45,15 @@ incomeDecoder : Json.Decoder Income
incomeDecoder =
Json.object3 Income
("userId" := userIdDecoder)
- ("creation" := timeDecoder)
+ ("day" := timeDecoder)
("amount" := Json.int)
incomeDefinedForAll : List UserId -> Incomes -> Maybe Time
incomeDefinedForAll userIds incomes =
let userIncomes = List.map (\userId -> List.filter ((==) userId << .userId) << Dict.values <| incomes) userIds
- firstIncomes = map (head << sortBy .creation) userIncomes
+ firstIncomes = map (head << sortBy .time) userIncomes
in if all isJust firstIncomes
- then head << reverse << List.sort << map .creation << catMaybes <| firstIncomes
+ then head << reverse << List.sort << map .time << catMaybes <| firstIncomes
else Nothing
userCumulativeIncomeSince : Time -> Time -> Incomes -> UserId -> Int
@@ -70,26 +70,26 @@ cumulativeIncomesSince currentTime since incomes =
getOrderedIncomesSince : Time -> List Income -> List Income
getOrderedIncomesSince time incomes =
let mbStarterIncome = getIncomeAt time incomes
- orderedIncomesSince = filter (\income -> income.creation >= time) incomes
+ orderedIncomesSince = filter (\income -> income.time >= time) incomes
in (maybeToList mbStarterIncome) ++ orderedIncomesSince
getIncomeAt : Time -> List Income -> Maybe Income
getIncomeAt time incomes =
case incomes of
[x] ->
- if x.creation < time
- then Just { userId = x.userId, creation = time, amount = x.amount }
+ if x.time < time
+ then Just { userId = x.userId, time = time, amount = x.amount }
else Nothing
x1 :: x2 :: xs ->
- if x1.creation < time && x2.creation > time
- then Just { userId = x2.userId, creation = time, amount = x2.amount }
+ if x1.time < time && x2.time > time
+ then Just { userId = x2.userId, time = time, amount = x2.amount }
else getIncomeAt time (x2 :: xs)
[] ->
Nothing
cumulativeIncome : Time -> List Income -> Int
cumulativeIncome currentTime incomes =
- getIncomesWithDuration currentTime (List.sortBy .creation incomes)
+ getIncomesWithDuration currentTime (List.sortBy .time incomes)
|> map durationIncome
|> sum
@@ -99,9 +99,9 @@ getIncomesWithDuration currentTime incomes =
[] ->
[]
[income] ->
- [(currentTime - income.creation, income.amount)]
+ [(currentTime - income.time, income.amount)]
(income1 :: income2 :: xs) ->
- (income2.creation - income1.creation, income1.amount) :: (getIncomesWithDuration currentTime (income2 :: xs))
+ (income2.time - income1.time, income1.amount) :: (getIncomesWithDuration currentTime (income2 :: xs))
durationIncome : (Float, Int) -> Int
durationIncome (duration, income) =