From 11052951b74b9ad4b6a9412ae490086235f9154b Mon Sep 17 00:00:00 2001 From: Joris Date: Sun, 3 Jan 2021 13:40:40 +0100 Subject: Rewrite in Rust --- client/src/View/Statistics/Statistics.hs | 85 -------------------------------- 1 file changed, 85 deletions(-) delete mode 100644 client/src/View/Statistics/Statistics.hs (limited to 'client/src/View/Statistics/Statistics.hs') 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 - } -- cgit v1.2.3