From 1801082c7163e7bb301a9d89b2cdfc5f8af03870 Mon Sep 17 00:00:00 2001 From: Tissevert Date: Sat, 31 Aug 2019 23:41:48 +0200 Subject: [PATCH] Add support for a comment column in timelines --- ChangeLog.md | 4 ++++ pilu.cabal | 2 +- src/Event.hs | 6 ++++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 4185880..bd41a36 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,5 +1,9 @@ # Revision history for pilu +## 0.1.1.0 -- 2019-08-31 + +* Add support for a comment column in timelines + ## 0.1.0.0 -- YYYY-mm-dd * First version. Released on an unsuspecting world. diff --git a/pilu.cabal b/pilu.cabal index 187ce1d..a8b26cb 100644 --- a/pilu.cabal +++ b/pilu.cabal @@ -2,7 +2,7 @@ -- see http://haskell.org/cabal/users-guide/ name: pilu -version: 0.1.0.0 +version: 0.1.1.0 -- synopsis: -- description: license: BSD3 diff --git a/src/Event.hs b/src/Event.hs index c4ae2dc..b71f975 100644 --- a/src/Event.hs +++ b/src/Event.hs @@ -7,7 +7,7 @@ import CSV (Row(..)) import Control.Monad (foldM) import Data.List (isSuffixOf, takeWhile) import Data.Map (Map) -import qualified Data.Map as Map (delete, empty, insert, lookup, toList) +import qualified Data.Map as Map (difference, empty, fromList, insert, lookup, toList) import Data.Time (Day) import Medicine (MedicineName) import Text.ParserCombinators.Parsec.Error (Message(..)) @@ -23,7 +23,7 @@ data Event = Event { instance Row Event where fromRow assoc = do rowDate <- read <$> get "date" - (kind, ints) <- foldM addAmount (Nothing, Map.empty) . Map.toList $ Map.delete "date" assoc + (kind, ints) <- foldM addAmount (Nothing, Map.empty) $ Map.toList medicineNames maybe (Left $ Expect "A prescription or provisioning for a medicine") (Right . Event rowDate ints) @@ -31,6 +31,8 @@ instance Row Event where where get key = maybe (Left $ Expect key) Right $ Map.lookup key assoc unexpected = Left . UnExpect . show + ignoredKeys = Map.fromList [("date", ""), ("comment", "")] + medicineNames = Map.difference assoc ignoredKeys addAmount (evType, ints) (key, val) = do (newEvType, amount) <- readAmount val let newFloats = Map.insert key amount ints