diff options
author | Hendrik Jaeger <henk@frustcomp> | 2013-12-24 00:14:12 +0100 |
---|---|---|
committer | Hendrik Jaeger <henk@frustcomp> | 2013-12-24 00:14:12 +0100 |
commit | d38cc424b83a0240b466f41ec1fe7521aba2d64e (patch) | |
tree | b62a014d8212359974a518e768b6ecf871e33595 | |
parent | aa7fd5c65535efa95dd0ea0a320aeac679c6dfa7 (diff) |
On branch master
modified: diddohs.hs
CHANGED: cleanup and simplification
-rw-r--r-- | diddohs.hs | 29 |
1 files changed, 20 insertions, 9 deletions
@@ -15,16 +15,27 @@ data DiddoOpts = DiddoOpts , inFile :: String } +calculateDeltas :: [DateTime] -> [Integer] +calculateDeltas dateTimes = zipWith diffSeconds dateTimes ((startOfDay $ head dateTimes) : init dateTimes) + +parseDateTimeFormat :: String -> String -> DateTime +parseDateTimeFormat format = fromMaybe (error "Input data broken.") . parseDateTime format + +startOfDay :: DateTime -> DateTime +startOfDay = fromJust . parseDateTime "%x" . formatDateTime "%x" + 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 +mainWithOpts opts = + do + [ timeStrings + , entries + ] <- transpose . map (splitOn ";") . lines <$> readFile (inFile opts) + + let + deltasHMS = map secondsToHMS $ calculateDeltas $ map (parseDateTimeFormat (inDateFmt opts)) timeStrings + diddos_summarized = zipWith4 DiddoEntry ("" : init timeStrings) timeStrings deltasHMS entries + + mapM_ print diddos_summarized main :: IO () main = execParser opts >>= mainWithOpts |