]> git.netwichtig.de Git - user/henk/code/haskell/diddohs.git/commitdiff
On branch master
authorHendrik Jaeger <henk@hnjs.ch>
Sun, 1 Dec 2013 13:49:44 +0000 (14:49 +0100)
committerHendrik Jaeger <henk@hnjs.ch>
Sun, 1 Dec 2013 13:49:44 +0000 (14:49 +0100)
Changes to be committed:

      modified:   diddohs.hs
        * CHANGED: a lot; basically the first usable version

diddohs.hs

index fdc1d0d73bd0244fb1e70c9b78ff885bb7d138bb..b96b491ff8815e8fbd2517bd92bfb45d210a74e3 100644 (file)
@@ -1,36 +1,54 @@
-import System.Environment
-import System.IO
-import Options.Applicative
-import Data.Time
-
-data Args = Args
-  { entry :: String
---  , time :: Time
---  , verbose :: Bool
---  , file :: String
-}
-
-runWithOptions :: Args -> IO ()
-runWithOptions opts =
-  putStrLn ( entry opts ++ " saved." )
-
-main :: IO ()
-main = execParser opts >>= runWithOptions
+import System.Environment( getArgs )
+import Data.Time.Git( approxidate )
+import Data.Time.LocalTime( utcToLocalTime, getTimeZone )
+import Data.Time.Clock.POSIX( posixSecondsToUTCTime )
+import Data.List.Split( splitOn )
+import Data.List( zip4, intersperse )
+import Data.Maybe( fromJust )
+import Control.Monad( forM_ )
+import Text.Printf
+
+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
-    parser = Args <$> argument str (metavar "ENTRY")
-    opts = info parser mempty
-
--- main = getArgs >>= parse
-
--- parse [] = getLine >>= saveActivity "actlog.txt"
--- parse ["add"] = getLine >>= saveActivity "actlog.txt"
--- parse ["new"] = getLine >>= saveActivity "actlog.txt"
--- parse ("add":entry) = saveActivity "actlog.txt" $ unwords entry
--- parse ("new":entry) = saveActivity "actlog.txt" $ unwords entry
--- parse ("-f":
-
--- saveActivity file act = do
---   zoneTime <- fmap show Data.Time.getZonedTime
---   appendFile "actlog.txt" (zoneTime ++ "\t" ++ act ++ "\n")
---   hPutStrLn stderr ("\"" ++ zoneTime ++ "\t" ++ act ++ "\"" ++ " saved.")
+    (mLeft, s) = seconds `divMod` 60
+    (h, m) = mLeft `divMod` 60
+
+getStartOfDay :: Num t => t -> t
+getStartOfDay time = 0
+
+--epochToTimestring :: Num t => t -> String
+--epochToTimestring epochtime = let getTZ = getTimeZone utctime in utcToLocalTime getTZ utctime
+--  where
+--    tz = getTimeZone utctime
+--    utctime = posixSecondsToUTCTime epochtime
+
+--getTZ time = do
+--  getTimeZone time