]> git.netwichtig.de Git - user/henk/code/haskell/diddohs.git/blob - diddohs.hs
On branch master
[user/henk/code/haskell/diddohs.git] / diddohs.hs
1 import System.Environment( getArgs )
2 import Data.Time.Git( approxidate )
3 import Data.Time.LocalTime( utcToLocalTime, getTimeZone )
4 import Data.Time.Clock.POSIX( posixSecondsToUTCTime )
5 import Data.List.Split( splitOn )
6 import Data.List( zip4, intersperse )
7 import Data.Maybe( fromJust )
8 import Control.Monad( forM_ )
9 import Text.Printf
10
11 main = do
12   logfile_name : _ <- getArgs
13   logfile_content <- readFile logfile_name
14   let loglines                = lines logfile_content
15       loglines_split          = map (splitOn ";") loglines
16
17       entries                 = map (head . tail) loglines_split
18
19       timestrings_finish      = map head loglines_split
20       timestrings_start       = "" : init timestrings_finish
21
22       timestamps_finish       = map timestringToEpoch timestrings_finish
23       timestamps_start        = 0 : init timestamps_finish
24
25       timestamps_deltas       = zipWith (-) timestamps_finish timestamps_start
26       timestamps_deltas_HMMSS = map secondsToHMMSS timestamps_deltas
27
28       delta_entry_tuples      = zip timestamps_deltas_HMMSS entries
29       summaries               = zip4 (map show timestrings_start) (map show timestrings_finish) timestamps_deltas_HMMSS entries
30
31   forM_ summaries $ \(start, finish, delta, entry) ->
32     putStrLn $ concat $ intersperse ";" [start, finish, delta, entry]
33
34 timestringToEpoch :: String -> Integer
35 timestringToEpoch = fromJust . approxidate
36
37 secondsToHMMSS :: (Num seconds, Show seconds, Integral seconds, Text.Printf.PrintfArg seconds) => seconds -> String
38 secondsToHMMSS seconds = printf "%d:%02d:%02d" h m s
39   where
40     (mLeft, s) = seconds `divMod` 60
41     (h, m) = mLeft `divMod` 60
42
43 getStartOfDay :: Num t => t -> t
44 getStartOfDay time = 0
45
46 --epochToTimestring :: Num t => t -> String
47 --epochToTimestring epochtime = let getTZ = getTimeZone utctime in utcToLocalTime getTZ utctime
48 --  where
49 --    tz = getTimeZone utctime
50 --    utctime = posixSecondsToUTCTime epochtime
51
52 --getTZ time = do
53 --  getTimeZone time
54