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
|
import Control.Applicative( (<$>), (<*>), liftA, liftA2 )
import Data.DateTime( parseDateTime, startOfTime, diffSeconds, formatDateTime )
import Data.List( zip4, zipWith4, transpose )
import Data.List.Split( splitOn )
import Data.Maybe( fromJust, fromMaybe )
import Data.Monoid( mempty )
import Data.Time.Clock( secondsToDiffTime )
import Options.Applicative( execParser, info, strOption, long )
import System.Environment( getArgs )
import Text.Printf( printf )
data HMSTime = HMSTime { hours :: Integer, minutes :: Integer, seconds :: Integer }
instance Show HMSTime where
show (HMSTime h m s) = printf "%d:%02d:%02d" h m s
secondsToHMS :: Integer -> HMSTime
secondsToHMS seconds = HMSTime h m s where
(mLeft, s) = seconds `divMod` 60
(h, m) = mLeft `divMod` 60
data DiddoEntry = DiddoEntry { start :: String
, finish :: String
, delta :: HMSTime
, entry :: String
}
instance Show DiddoEntry where
show (DiddoEntry start finish delta entry) = printf "%s;%s;%s;%s" start finish (show delta) entry
data DiddoOpts = DiddoOpts
{ inDateFmt :: String
, inFile :: String
}
mainWithOpts :: DiddoOpts -> IO ()
mainWithOpts opts = do
[timestrings_finish
, entries
] <- transpose . map (splitOn ";") . lines <$> readFile (inFile opts)
let utcTimes_finish = map (fromMaybe (error "Input data broken.") . parseDateTime (inDateFmt opts)) timestrings_finish
entry_deltas_HMMSS = zipWith (\x y -> secondsToHMS $ diffSeconds x y) utcTimes_finish (startOfTime : init utcTimes_finish)
diddos_summarized = zipWith4 DiddoEntry ("" : init timestrings_finish) timestrings_finish entry_deltas_HMMSS entries
mapM_ print diddos_summarized
main :: IO ()
main = execParser opts >>= mainWithOpts
where
opts = info parser mempty
parser = DiddoOpts
<$> strOption ( long "indateform" )
<*> strOption ( long "infile" )
|