aboutsummaryrefslogtreecommitdiff
path: root/src/client/LoggedIn/Stat
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/LoggedIn/Stat')
-rw-r--r--src/client/LoggedIn/Stat/Model.elm34
-rw-r--r--src/client/LoggedIn/Stat/Msg.elm7
-rw-r--r--src/client/LoggedIn/Stat/Update.elm24
-rw-r--r--src/client/LoggedIn/Stat/View.elm77
4 files changed, 0 insertions, 142 deletions
diff --git a/src/client/LoggedIn/Stat/Model.elm b/src/client/LoggedIn/Stat/Model.elm
deleted file mode 100644
index bfc66f2..0000000
--- a/src/client/LoggedIn/Stat/Model.elm
+++ /dev/null
@@ -1,34 +0,0 @@
-module LoggedIn.Stat.Model exposing
- ( Model
- , init
- , getPaymentsByMonthByCategory
- )
-
-import Date exposing (Month)
-import List.Extra as List
-import Time exposing (Time)
-
-import Model.Category exposing (CategoryId)
-import Model.Conf exposing (Conf)
-import Model.Payment as Payment exposing (Payments)
-import Model.PaymentCategory as PaymentCategory exposing (PaymentCategories)
-
-type alias Model =
- { paymentsByMonthByCategory : List ((Month, Int), List (CategoryId, Int))
- }
-
-init : Time -> PaymentCategories -> Payments -> Model
-init currentTime paymentCategories payments =
- { paymentsByMonthByCategory = getPaymentsByMonthByCategory currentTime paymentCategories payments
- }
-
-getPaymentsByMonthByCategory : Time -> PaymentCategories -> Payments -> List ((Month, Int), List (CategoryId, Int))
-getPaymentsByMonthByCategory currentTime paymentCategories payments =
- Payment.punctual payments
- |> Payment.groupAndSortByMonth
- |> List.map (\(m, payments) ->
- ( m
- , PaymentCategory.groupPaymentsByCategory paymentCategories payments
- |> List.map (Tuple.mapSecond (List.sum << List.map .cost))
- )
- )
diff --git a/src/client/LoggedIn/Stat/Msg.elm b/src/client/LoggedIn/Stat/Msg.elm
deleted file mode 100644
index d517544..0000000
--- a/src/client/LoggedIn/Stat/Msg.elm
+++ /dev/null
@@ -1,7 +0,0 @@
-module LoggedIn.Stat.Msg exposing
- ( Msg(..)
- )
-
-type Msg =
- NoOp
- | UpdateChart
diff --git a/src/client/LoggedIn/Stat/Update.elm b/src/client/LoggedIn/Stat/Update.elm
deleted file mode 100644
index 2415733..0000000
--- a/src/client/LoggedIn/Stat/Update.elm
+++ /dev/null
@@ -1,24 +0,0 @@
-module LoggedIn.Stat.Update exposing
- ( update
- )
-
-import LoggedData exposing (LoggedData)
-import LoggedIn.Stat.Model as Stat
-import LoggedIn.Stat.Msg as Stat
-
-update : LoggedData -> Stat.Msg -> Stat.Model -> (Stat.Model, Cmd Stat.Msg)
-update loggedData msg model =
- case msg of
-
- Stat.NoOp ->
- ( model
- , Cmd.none
- )
-
- Stat.UpdateChart ->
- let { currentTime, paymentCategories, payments } = loggedData
- in ( { model
- | paymentsByMonthByCategory = Stat.getPaymentsByMonthByCategory currentTime paymentCategories payments
- }
- , Cmd.none
- )
diff --git a/src/client/LoggedIn/Stat/View.elm b/src/client/LoggedIn/Stat/View.elm
deleted file mode 100644
index e389c67..0000000
--- a/src/client/LoggedIn/Stat/View.elm
+++ /dev/null
@@ -1,77 +0,0 @@
-module LoggedIn.Stat.View exposing
- ( view
- )
-
-import Date exposing (Month)
-import Dict
-import Html exposing (..)
-import Html.Attributes exposing (..)
-import List.Extra as List
-import Time exposing (Time)
-
-import Chart.Api as Chart
-import LoggedData exposing (LoggedData)
-import LoggedIn.Stat.Model as Stat
-import LoggedIn.View.Format as Format
-import Model.Category exposing (CategoryId, Categories)
-import Model.Conf exposing (Conf)
-import Model.Payment as Payment exposing (Payments)
-import Model.PaymentCategory as PaymentCategory exposing (PaymentCategories)
-import Model.Translations exposing (Translations, getMessage, getParamMessage)
-import Msg exposing (Msg)
-import Utils.List as List
-import View.Date as Date
-import View.Plural exposing (plural)
-
-view : LoggedData -> Stat.Model -> Html Msg
-view loggedData { paymentsByMonthByCategory } =
- div
- [ class "stat withMargin" ]
- [ renderChart loggedData paymentsByMonthByCategory ]
-
-renderChart : LoggedData -> List ((Month, Int), List (CategoryId, Int)) -> Html msg
-renderChart { currentTime, paymentCategories, categories, conf, translations } paymentsByMonthByCategory =
- let monthPaymentMean = getMonthPaymentMean currentTime paymentsByMonthByCategory
- title = getParamMessage [ Format.price conf monthPaymentMean ] translations "ByMonthsAndMean"
- keys =
- paymentsByMonthByCategory
- |> List.map (\((month, year), _) -> Date.shortMonthAndYear month year translations)
- series =
- categories
- |> Dict.toList
- |> List.map (\(categoryId, category) ->
- { values =
- List.map
- (\(_, paymentsByCategory) ->
- paymentsByCategory
- |> List.find (\(c, _) -> c == categoryId)
- |> Maybe.map (toFloat << Tuple.second)
- |> Maybe.withDefault 0
- )
- paymentsByMonthByCategory
- , color = category.color
- , label = category.name
- }
- )
- totalSerie =
- { values =
- List.transpose (List.map .values series)
- |> List.map List.sum
- , color = "black"
- , label = getMessage translations "Total"
- }
- in Chart.from keys (series ++ [totalSerie])
- |> Chart.withSize { x = 2000, y = 900 }
- |> Chart.withTitle title
- |> Chart.withOrdinate 10 (Format.price conf << truncate)
- |> Chart.toHtml
-
-getMonthPaymentMean : Time -> List ((Month, Int), List (CategoryId, Int)) -> Int
-getMonthPaymentMean currentTime paymentsByMonthByCategory =
- paymentsByMonthByCategory
- |> List.filter (\((month, year), _) ->
- let currentDate = Date.fromTime currentTime
- in not (Date.month currentDate == month && Date.year currentDate == year)
- )
- |> List.map (List.sum << List.map Tuple.second << Tuple.second)
- |> List.mean