summaryrefslogtreecommitdiff
path: root/diddohs.hs
blob: 60beb319e6279dc9003c4a6bfe070ac59a6f24d2 (plain)
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
import Control.Applicative( (<$>), (<*>) )
import Data.DateTime( DateTime(..), parseDateTime, formatDateTime, startOfTime, diffSeconds )
import Data.List.Split( splitOn )
import Data.List( zipWith4, transpose )
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 HMSTime( HMSTime(..), secondsToHMS )
import Diddo.Entry( DiddoEntry(..) )

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" )