aboutsummaryrefslogtreecommitdiff
path: root/src/client/elm/LoggedIn/Stat/View.elm
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/elm/LoggedIn/Stat/View.elm')
-rw-r--r--src/client/elm/LoggedIn/Stat/View.elm34
1 files changed, 27 insertions, 7 deletions
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) =