From 6a0c5087f716ed6c876a666db6573491bfd3e094 Mon Sep 17 00:00:00 2001 From: Joris Date: Sun, 12 Jun 2016 23:54:17 +0200 Subject: Design income form --- src/client/elm/Model/Income.elm | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'src/client/elm/Model/Income.elm') 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) = -- cgit v1.2.3