aboutsummaryrefslogtreecommitdiff
path: root/src/client/elm/LoggedIn/Stat
diff options
context:
space:
mode:
authorJoris2016-06-04 11:02:43 +0200
committerJoris2016-06-04 11:02:43 +0200
commit38896af4281d2e191cbde15836a23e4c0274fff6 (patch)
tree0d7df152cc84beaa79cc9fa055db1e7992c4ac91 /src/client/elm/LoggedIn/Stat
parent9dfa7a7e2c6fac564a456b11623c04d0b26fbce5 (diff)
downloadbudget-38896af4281d2e191cbde15836a23e4c0274fff6.tar.gz
budget-38896af4281d2e191cbde15836a23e4c0274fff6.tar.bz2
budget-38896af4281d2e191cbde15836a23e4c0274fff6.zip
Add mean payment by month
Diffstat (limited to 'src/client/elm/LoggedIn/Stat')
-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) =