diff options
Diffstat (limited to 'diddohs.hs')
-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 |