summaryrefslogtreecommitdiff
path: root/diddohs.hs
diff options
context:
space:
mode:
Diffstat (limited to 'diddohs.hs')
-rw-r--r--diddohs.hs84
1 files changed, 35 insertions, 49 deletions
diff --git a/diddohs.hs b/diddohs.hs
index b96b491..7ee35cd 100644
--- a/diddohs.hs
+++ b/diddohs.hs
@@ -1,54 +1,40 @@
-import System.Environment( getArgs )
-import Data.Time.Git( approxidate )
-import Data.Time.LocalTime( utcToLocalTime, getTimeZone )
-import Data.Time.Clock.POSIX( posixSecondsToUTCTime )
+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.List( zip4, intersperse )
-import Data.Maybe( fromJust )
-import Control.Monad( forM_ )
-import Text.Printf
-
+import Data.Maybe( fromJust, fromMaybe )
+import Data.Time.Clock( secondsToDiffTime )
+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
+
+main :: IO ()
main = do
- logfile_name : _ <- getArgs
- logfile_content <- readFile logfile_name
- let loglines = lines logfile_content
- loglines_split = map (splitOn ";") loglines
-
- entries = map (head . tail) loglines_split
-
- timestrings_finish = map head loglines_split
- timestrings_start = "" : init timestrings_finish
-
- timestamps_finish = map timestringToEpoch timestrings_finish
- timestamps_start = 0 : init timestamps_finish
-
- timestamps_deltas = zipWith (-) timestamps_finish timestamps_start
- timestamps_deltas_HMMSS = map secondsToHMMSS timestamps_deltas
-
- delta_entry_tuples = zip timestamps_deltas_HMMSS entries
- summaries = zip4 (map show timestrings_start) (map show timestrings_finish) timestamps_deltas_HMMSS entries
-
- forM_ summaries $ \(start, finish, delta, entry) ->
- putStrLn $ concat $ intersperse ";" [start, finish, delta, entry]
-
-timestringToEpoch :: String -> Integer
-timestringToEpoch = fromJust . approxidate
-
-secondsToHMMSS :: (Num seconds, Show seconds, Integral seconds, Text.Printf.PrintfArg seconds) => seconds -> String
-secondsToHMMSS seconds = printf "%d:%02d:%02d" h m s
- where
- (mLeft, s) = seconds `divMod` 60
- (h, m) = mLeft `divMod` 60
-
-getStartOfDay :: Num t => t -> t
-getStartOfDay time = 0
+ logfile_name : timestring_format : _ <- getArgs
+ logfile_lines_split <- map (splitOn ";") . lines <$> readFile logfile_name
---epochToTimestring :: Num t => t -> String
---epochToTimestring epochtime = let getTZ = getTimeZone utctime in utcToLocalTime getTZ utctime
--- where
--- tz = getTimeZone utctime
--- utctime = posixSecondsToUTCTime epochtime
+ let [timestrings_finish
+ , entries
+ ] = transpose logfile_lines_split
+ utcTimes_finish = map (fromMaybe (error "Input data broken.") . parseDateTime timestring_format) 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
---getTZ time = do
--- getTimeZone time
+ mapM_ print diddos_summarized