diff options
author | Joris | 2020-01-27 22:07:18 +0100 |
---|---|---|
committer | Joris | 2020-01-27 22:07:18 +0100 |
commit | 79e1d8b0099d61b580a499311f1714b1b7eb07b5 (patch) | |
tree | a4c35442914b3a59119ddfc1e6c2ce358ecd4758 /client/src/View | |
parent | 47c2a4d6b68c54eed5f7b45671b1ccaf8c0db200 (diff) |
Show total incom by month in statistics
Diffstat (limited to 'client/src/View')
-rw-r--r-- | client/src/View/Statistics/Statistics.hs | 54 |
1 files changed, 36 insertions, 18 deletions
diff --git a/client/src/View/Statistics/Statistics.hs b/client/src/View/Statistics/Statistics.hs index 71f93d4..d931b2b 100644 --- a/client/src/View/Statistics/Statistics.hs +++ b/client/src/View/Statistics/Statistics.hs @@ -16,7 +16,8 @@ import qualified Reflex.Dom as R import qualified Util.Ajax as AjaxUtil import qualified View.Statistics.Chart as Chart -import Common.Model (Category (..), Currency, PaymentStats) +import Common.Model (Category (..), Currency, Income, + MonthStats (..), Stats, User (..)) import qualified Common.Msg as Msg import qualified Common.View.Format as Format @@ -27,41 +28,58 @@ data In = In view :: forall t m. MonadWidget t m => In -> m () view input = do + users <- AjaxUtil.getNow "api/users" categories <- AjaxUtil.getNow "api/allCategories" statistics <- AjaxUtil.getNow "api/statistics" - let categoriesAndStatistics = (\c s -> (,) <$> c <*> s) <$> categories <*> statistics + + let loadable = (\u c s -> (,,) <$> u <*> c <*> s) <$> users <*> categories <*> statistics R.divClass "withMargin" $ R.divClass "titleButton" $ R.el "h1" $ R.text $ Msg.get Msg.Statistics_Title - void . R.dyn . R.ffor categoriesAndStatistics . Loadable.viewHideValueWhileLoading $ + void . R.dyn . R.ffor loadable . Loadable.viewHideValueWhileLoading $ stats (_in_currency input) -stats :: forall t m. MonadWidget t m => Currency -> ([Category], PaymentStats) -> m () -stats currency (categories, stats) = +stats :: forall t m. MonadWidget t m => Currency -> ([User], [Category], Stats) -> m () +stats currency (users, categories, stats) = Chart.view $ Chart.In - { Chart._in_title = Msg.get (Msg.Statistics_ByMonthsAndMean averageEachMonth) - , Chart._in_labels = map (Format.monthAndYear . fst) stats - , Chart._in_datasets = - Chart.Dataset - { Chart._dataset_label = Msg.get Msg.Statistics_Total - , Chart._dataset_data = totalSeries - , Chart._dataset_color = "#555555" - } : (map categoryDataset categories) + { Chart._in_title = Msg.get (Msg.Statistics_ByMonthsAndMean averagePayment averageIncome) + , Chart._in_labels = map (Format.monthAndYear . _monthStats_start) stats + , Chart._in_datasets = totalIncomeDataset : totalPaymentDataset : (map categoryDataset categories) } where - averageEachMonth = - Format.price currency $ sum totalSeries `div` length stats + averageIncome = + Format.price currency $ sum totalIncomes `div` length stats + + totalIncomeDataset = + Chart.Dataset + { Chart._dataset_label = Msg.get Msg.Statistics_TotalIncomes + , Chart._dataset_data = totalIncomes + , Chart._dataset_color = "#222222" + } + + totalIncomes = + map (sum . map snd . M.toList . _monthStats_incomeByUser) stats + + averagePayment = + Format.price currency $ sum totalPayments `div` length stats + + totalPaymentDataset = + Chart.Dataset + { Chart._dataset_label = Msg.get Msg.Statistics_TotalPayments + , Chart._dataset_data = totalPayments + , Chart._dataset_color = "#555555" + } - totalSeries = - map (sum . map snd . M.toList . snd) stats + totalPayments = + map (sum . map snd . M.toList . _monthStats_paymentsByCategory) stats categoryDataset category = Chart.Dataset { Chart._dataset_label = _category_name category - , Chart._dataset_data = map (M.findWithDefault 0 (_category_id category) . snd) stats + , Chart._dataset_data = map (M.findWithDefault 0 (_category_id category) . _monthStats_paymentsByCategory) stats , Chart._dataset_color = _category_color category } |