aboutsummaryrefslogtreecommitdiff
path: root/client/src/View/Statistics/Statistics.hs
diff options
context:
space:
mode:
authorJoris2021-01-03 13:40:40 +0100
committerJoris2021-01-03 13:54:20 +0100
commit11052951b74b9ad4b6a9412ae490086235f9154b (patch)
tree64526ac926c1bf470ea113f6cac8a33158684e8d /client/src/View/Statistics/Statistics.hs
parent371449b0e312a03162b78797b83dee9d81706669 (diff)
downloadbudget-11052951b74b9ad4b6a9412ae490086235f9154b.tar.gz
budget-11052951b74b9ad4b6a9412ae490086235f9154b.tar.bz2
budget-11052951b74b9ad4b6a9412ae490086235f9154b.zip
Rewrite in Rust
Diffstat (limited to 'client/src/View/Statistics/Statistics.hs')
-rw-r--r--client/src/View/Statistics/Statistics.hs85
1 files changed, 0 insertions, 85 deletions
diff --git a/client/src/View/Statistics/Statistics.hs b/client/src/View/Statistics/Statistics.hs
deleted file mode 100644
index d931b2b..0000000
--- a/client/src/View/Statistics/Statistics.hs
+++ /dev/null
@@ -1,85 +0,0 @@
-module View.Statistics.Statistics
- ( view
- , In(..)
- ) where
-
-import Control.Monad (void)
-import Data.Map (Map)
-import qualified Data.Map as M
-import qualified Data.Text as T
-import Data.Time.Calendar (Day)
-import qualified Data.Time.Calendar as Calendar
-import Loadable (Loadable)
-import qualified Loadable
-import Reflex.Dom (Dynamic, MonadWidget)
-import qualified Reflex.Dom as R
-import qualified Util.Ajax as AjaxUtil
-import qualified View.Statistics.Chart as Chart
-
-import Common.Model (Category (..), Currency, Income,
- MonthStats (..), Stats, User (..))
-import qualified Common.Msg as Msg
-import qualified Common.View.Format as Format
-
-data In = In
- { _in_currency :: Currency
- }
-
-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 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 loadable . Loadable.viewHideValueWhileLoading $
- stats (_in_currency input)
-
-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 averagePayment averageIncome)
- , Chart._in_labels = map (Format.monthAndYear . _monthStats_start) stats
- , Chart._in_datasets = totalIncomeDataset : totalPaymentDataset : (map categoryDataset categories)
- }
-
- where
- 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"
- }
-
- 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) . _monthStats_paymentsByCategory) stats
- , Chart._dataset_color = _category_color category
- }