-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTypes.hs
116 lines (73 loc) · 3.04 KB
/
Types.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
{-# LANGUAGE OverloadedStrings, BangPatterns#-}
module Types where
import Data.Time
import System.Locale
import Prelude hiding (FilePath)
import Safe
import qualified Data.ByteString as B
import qualified Data.ByteString.Char8 as BC
import Data.Csv
import Data.Text
import System.Directory
import Filesystem
import Filesystem.Path
data OnpingTagHistory = OnpingTagHistory {
time :: Maybe UTCTime,
pid:: Maybe Int,
val :: Maybe Double
} deriving (Read, Show, Eq,Ord)
instance ToNamedRecord OnpingTagHistory where
toNamedRecord (OnpingTagHistory time pid val) = namedRecord [ "time" .= (encodeArchiveTime time),"pid" .= pid , "val" .= val]
instance ToRecord OnpingTagHistory where
toRecord (OnpingTagHistory t p v) = record [toField (encodeArchiveTime t), toField v]
data NameAndLine = NameAndLine { nlName::Text, nlLine::Text}
data BuildableObject = B_OTH !OnpingTagHistory
deriving (Read,Show,Eq,Ord)
type Buildable a = NameAndLine -> Either String (a,Text)
newtype FileFilter = FileFilter { getFileFilter :: (ParamFile -> Maybe ParamFile)}
newtype StartTime a = StartTime { getStartTime :: a}
deriving (Eq,Read,Show)
newtype EndTime a = EndTime { getEndTime :: a }
deriving (Eq,Read,Show)
-- | Simple Parsers for Time and Value
parseFileDate :: String -> Maybe UTCTime
parseFileDate = (parseTime defaultTimeLocale "%F.txt")
parseArchiveTime::Text -> Maybe UTCTime
parseArchiveTime = (parseTime defaultTimeLocale "%F %X").unpack.fst.(breakOn ",")
parseArchiveTime':: String -> Maybe UTCTime
parseArchiveTime' = (parseTime defaultTimeLocale "%F %X")
encodeArchiveTime :: Maybe UTCTime => String
encodeArchiveTime (Just t) = (formatTime defaultTimeLocale "%F %X") t
encodeArchiveTime Nothing = ""
parseArchiveValue :: Text -> Maybe Double
parseArchiveValue = readMay.unpack.strip.snd.(breakOnEnd ",")
parseArchiveValue' :: String -> Maybe Double
parseArchiveValue' = readMay
parsePidValue :: Text -> Maybe Int
parsePidValue = readMay.unpack
-- | Helper Type to pull the date out to the front for sorting against
-- the File Touch Time
data DatedFile = DatedFile { touchDate :: UTCTime,
touchFile :: FilePath
}
deriving (Eq,Show,Ord)
-- | Newtypes for Location and PID folders
newtype LocationPath = LocationPath {getLocationPath :: DatedFile}
deriving (Eq,Show,Ord)
newtype ParamPath = ParamPath {getParamPath :: DatedFile}
deriving (Eq,Show,Ord)
newtype ParamFile = ParamFile {getParamFile :: DatedFile}
deriving (Eq,Show,Ord)
-- | Mongo Config options
data MongoConfig = MongoConfig {
mongoHost :: String
,mongoDB :: Text
,mongoCollection :: Text
} deriving (Eq,Read,Show)
data ConfigOptions = Test | Help | Run RunConfig |Fail
data OS = Windows | Linux
data RunConfig = RunConfig {
startDate :: Maybe UTCTime
,endDate :: Maybe UTCTime
,archivePath :: FilePath}
deriving (Show)