arbtt 0.3.0 → 0.4
raw patch · 5 files changed
+50/−19 lines, 5 files
Files
- arbtt.cabal +1/−1
- categorize.cfg +19/−0
- src/Capture.hs +3/−3
- src/Stats.hs +23/−3
- src/stats-main.hs +4/−12
arbtt.cabal view
@@ -1,5 +1,5 @@ name: arbtt-version: 0.3.0+version: 0.4 license: GPL license-file: LICENSE category: Desktop
categorize.cfg view
@@ -24,7 +24,26 @@ -- project I'm currently working on current window $title =~ m!(?:~|home/jojo)/projekte/(?:programming/(?:haskell/)?)?([^/)]*)! ==> tag Project:$1,+current window $title =~ m!(?:~|home/jojo)/debian!+ ==> tag Project:Debian, +-- My diploma thesis is in a different directory+current window $title =~ m!(?:~|home/jojo)/dokumente/Uni/DA!+ ==> tag Project:DA,+current window $title =~ m!Diplomarbeit.pdf!+ ==> tag Project:DA,+ -- Out of curiosity: what percentage of my time am I actually coding Haskell? current window ($program == "gvim" && $title =~ /^[^ ]+\.hs \(/ ) ==> tag Editing-Haskell,++-- To be able to match on the time of day, I introduce tags for that as well+$time >= 2:00 && $time < 8:00 ==> tag time-of-day:night,+$time >= 8:00 && $time < 12:00 ==> tag time-of-day:morning,+$time >= 12:00 && $time < 14:00 ==> tag time-of-day:lunchtime,+$time >= 14:00 && $time < 18:00 ==> tag time-of-day:afternoon,+$time >= 18:00 && $time < 22:00 ==> tag time-of-day:evening,+$time >= 22:00 || $time < 2:00 ==> tag time-of-day:late-evening,++-- This tag always refers to the last 24h+$sampleage <= 24:00 ==> tag last-day,
src/Capture.hs view
@@ -35,12 +35,12 @@ getProgramName :: Display -> Window -> IO String getProgramName dpy w = fmap resName $ getClassHint dpy w --- | Follows the tree of windows up until the condition is met or the window is--- a direct child of the root.+-- | Follows the tree of windows up until the condition is met or the root+-- window is reached. followTreeUntil :: Display -> (Window -> Bool) -> Window -> IO Window followTreeUntil dpy cond = go where go w | cond w = return w | otherwise = do (r,p,_) <- queryTree dpy w- if r == p then return w+ if p == 0 then return w else go p
src/Stats.hs view
@@ -6,14 +6,16 @@ import Data.List import Data.Ord import Text.Tabular+import qualified Text.Tabular.AsciiArt as TA import Text.Printf import qualified Data.Map as M+import qualified Data.Set as S import Data import Categorize -data Report = GeneralInfos | TotalTime | Category String+data Report = GeneralInfos | TotalTime | Category String | EachCategory deriving Eq data Filter = Exclude Activity | Only Activity | AlsoInactive | GeneralCond String@@ -75,8 +77,22 @@ where go' act = M.insertWith (+) act (tlRate tl) -renderReport :: [ReportOption] -> Calculations -> Report -> (String, Table String String String)-renderReport opts (Calculations {..}) r = case r of+listCategories :: TimeLog (Ctx, ActivityData) -> [Category]+listCategories = S.toList . foldr go (S.empty) + where go tl m = foldr go' m (snd (tlData tl))+ where go' (Activity (Just cat) _) = S.insert cat+ go' _ = id++putReports :: [ReportOption] -> Calculations -> [Report] -> IO ()+putReports opts c = sequence_ . intersperse (putStrLn "") . map (putReport opts c) ++putReport :: [ReportOption] -> Calculations -> Report -> IO ()+putReport opts c EachCategory = putReports opts c (map Category (listCategories (tags c)))+putReport opts c r = let (h,t) = reportToTable opts c r+ in putStrLnUnderlined h >> putStr (TA.render id id id t)++reportToTable :: [ReportOption] -> Calculations -> Report -> (String, Table String String String)+reportToTable opts (Calculations {..}) r = case r of GeneralInfos -> ("General Information", empty ^..^ colH "Value" +.+ row "FirstRecord"@@ -161,3 +177,7 @@ go' True (a,u) = (True, printf "%02d%s" a u) go' False (a,u) | a > 0 = (True, printf "%2d%s" a u) | otherwise = (False, "")++putStrLnUnderlined str = do+ putStrLn str+ putStrLn $ map (const '=') str
src/stats-main.hs view
@@ -13,7 +13,6 @@ import Text.Printf import Data.Maybe import Data.Version (showVersion)-import qualified Text.Tabular.AsciiArt as TA import TimeLog import Data@@ -68,6 +67,9 @@ , Option ['c'] ["category"] (ReqArg (Report . Category) "CATEGORY") "show statistics about category CATEGORY"+ , Option [] ["each-category"]+ (NoArg (Report EachCategory))+ "show statistics about each category found" ] @@ -111,17 +113,7 @@ -- advantageous. let c = prepareCalculations allTags tags - sequence_ $ intersperse (putStrLn "")- $ map (\r -> let (h,t) = renderReport opts c r in do- putStrLnUnderlined h- putStr (TA.render id id id t)- )- $ reps--putStrLnUnderlined str = do- putStrLn str- putStrLn $ map (const '=') str-+ putReports opts c reps {- import Data.Accessor