Add support for a comment column in timelines

This commit is contained in:
Tissevert 2019-08-31 23:41:48 +02:00
parent 3ac6c2d40c
commit 1801082c71
3 changed files with 9 additions and 3 deletions

View file

@ -1,5 +1,9 @@
# Revision history for pilu # 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 ## 0.1.0.0 -- YYYY-mm-dd
* First version. Released on an unsuspecting world. * First version. Released on an unsuspecting world.

View file

@ -2,7 +2,7 @@
-- see http://haskell.org/cabal/users-guide/ -- see http://haskell.org/cabal/users-guide/
name: pilu name: pilu
version: 0.1.0.0 version: 0.1.1.0
-- synopsis: -- synopsis:
-- description: -- description:
license: BSD3 license: BSD3

View file

@ -7,7 +7,7 @@ import CSV (Row(..))
import Control.Monad (foldM) import Control.Monad (foldM)
import Data.List (isSuffixOf, takeWhile) import Data.List (isSuffixOf, takeWhile)
import Data.Map (Map) 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 Data.Time (Day)
import Medicine (MedicineName) import Medicine (MedicineName)
import Text.ParserCombinators.Parsec.Error (Message(..)) import Text.ParserCombinators.Parsec.Error (Message(..))
@ -23,7 +23,7 @@ data Event = Event {
instance Row Event where instance Row Event where
fromRow assoc = do fromRow assoc = do
rowDate <- read <$> get "date" 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 maybe
(Left $ Expect "A prescription or provisioning for a medicine") (Left $ Expect "A prescription or provisioning for a medicine")
(Right . Event rowDate ints) (Right . Event rowDate ints)
@ -31,6 +31,8 @@ instance Row Event where
where where
get key = maybe (Left $ Expect key) Right $ Map.lookup key assoc get key = maybe (Left $ Expect key) Right $ Map.lookup key assoc
unexpected = Left . UnExpect . show unexpected = Left . UnExpect . show
ignoredKeys = Map.fromList [("date", ""), ("comment", "")]
medicineNames = Map.difference assoc ignoredKeys
addAmount (evType, ints) (key, val) = do addAmount (evType, ints) (key, val) = do
(newEvType, amount) <- readAmount val (newEvType, amount) <- readAmount val
let newFloats = Map.insert key amount ints let newFloats = Map.insert key amount ints