From 38896af4281d2e191cbde15836a23e4c0274fff6 Mon Sep 17 00:00:00 2001 From: Joris Date: Sat, 4 Jun 2016 11:02:43 +0200 Subject: Add mean payment by month --- src/client/elm/LoggedIn/Stat/View.elm | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) (limited to 'src/client/elm/LoggedIn/Stat') diff --git a/src/client/elm/LoggedIn/Stat/View.elm b/src/client/elm/LoggedIn/Stat/View.elm index 77a32a0..bb1ec84 100644 --- a/src/client/elm/LoggedIn/Stat/View.elm +++ b/src/client/elm/LoggedIn/Stat/View.elm @@ -15,7 +15,7 @@ import Msg exposing (Msg) import Model.Payment as Payment exposing (Payments) import Model.Conf exposing (Conf) -import Model.Translations exposing (getMessage) +import Model.Translations exposing (getMessage, getParamMessage) import LoggedIn.View.Format as Format import LoggedIn.View.Date as Date @@ -24,6 +24,7 @@ import View.Plural exposing (plural) import LoggedIn.View.Format as Format import Utils.Tuple as Tuple +import Utils.List as List view : LoggedData -> Html Msg view loggedData = @@ -74,12 +75,31 @@ totalPayments loggedData = monthsDetail : LoggedData -> Html Msg monthsDetail loggedData = - ul - [] - ( Payment.punctual loggedData.payments - |> Payment.groupAndSortByMonth - |> List.map (monthDetail loggedData) - ) + let paymentsByMonth = + loggedData.payments + |> Payment.punctual + |> Payment.groupAndSortByMonth + monthPaymentMean = + paymentsByMonth + |> List.filter (\((month, year), _) -> + let currentDate = Date.fromTime loggedData.currentTime + in not (Date.month currentDate == month && Date.year currentDate == year) + ) + |> List.map (List.sum << List.map .cost << snd) + |> List.mean + in div + [] + [ div + [ class "mean" ] + [ text (getParamMessage [ Format.price loggedData.conf monthPaymentMean ] "Mean" loggedData.translations) + ] + , ul + [] + ( Payment.punctual loggedData.payments + |> Payment.groupAndSortByMonth + |> List.map (monthDetail loggedData) + ) + ] monthDetail : LoggedData -> ((Month, Int), Payments) -> Html Msg monthDetail loggedData ((month, year), payments) = -- cgit v1.2.3