Commits

Stefan Saasen committed a018e4e

Rename plotGitOperations -> analyseGitOperations

  • Participants
  • Parent commits e89dd6c

Comments (0)

Files changed (2)

File logparser/src/Main.hs

 
 summarizeGitOperations = defCmd {
                 cmdName = "gitOperations",
-                cmdHandler = commandHandler $ generatePlotDataGitOps plotGitOperations,
+                cmdHandler = commandHandler $ generatePlotDataGitOps analyseGitOperations,
                 cmdCategory = "Logfile analysis",
                 cmdShortDesc = "Aggregate git operations per hour. Show counts for fetch, clone, push, pull and ref advertisement"
         }

File logparser/src/Stash/Log/GitOpsAnalyser.hs

 
 module Stash.Log.GitOpsAnalyser
 ( GitOperationStats(..)
-, plotGitOperations
+, analyseGitOperations
 ) where
 
 import qualified Data.ByteString.Char8 as S
     ,cacheHits                  :: [Int]
 }
 
+-- | Parse and aggregate the log file input into a list of GitOperationStats
+analyseGitOperations :: Input -> [GitOperationStats]
+analyseGitOperations rawLines =
+    let formatLogDate date = printf "%04d-%02d-%02d %02d" (getYear date) (getMonth date)
+                            (getDay date) (getHour date)
+    in analyseGitOperations' logDateEqHour formatLogDate rawLines
+
+-- =================================================================================
+
 emptyStats :: GitOperationStats
 emptyStats = GitOperationStats "" zero zero
         where zero = replicate 5 0
 inLabel :: LogLine -> String -> Bool
 inLabel logLine name =  let labels = getLabels logLine
                         in name `elem` labels
--- Example Output
--- (Date, clone, fetch, shallow clone, push)
-plotGitOperations :: Input -> [GitOperationStats]
-plotGitOperations rawLines =
-    let formatLogDate date = printf "%04d-%02d-%02d %02d" (getYear date) (getMonth date)
-                            (getDay date) (getHour date)
-    in plotGitOperations' logDateEqHour formatLogDate rawLines
-
-plotGitOperations' :: (LogDate -> LogDate -> Bool) -> (LogDate -> String) -> Input -> [GitOperationStats]
-plotGitOperations' comp formatLogDate rawLines =
-    let groups = groupBy (comp `on` getDate) $ parseLogLines rawLines
-    in map (summarizeGitOperations formatLogDate) groups
-
 
 cachedOperation :: (LogLine -> Bool) -> LogLine -> Bool
 cachedOperation op logLine = op logLine && isCacheHit logLine
 uncachedOperation :: (LogLine -> Bool) -> LogLine -> Bool
 uncachedOperation op logLine = op logLine && isCacheMiss logLine
 
+analyseGitOperations' :: (LogDate -> LogDate -> Bool) -> (LogDate -> String) -> Input -> [GitOperationStats]
+analyseGitOperations' comp formatLogDate rawLines =
+    let groups = groupBy (comp `on` getDate) $ parseLogLines rawLines
+    in map (summarizeGitOperations formatLogDate) groups
+
+
+summarizeGitOperations :: (LogDate -> String) -> [LogLine] -> GitOperationStats
+summarizeGitOperations formatLogDate = foldl' aggregate emptyStats . filter isOutgoingLogLine
+                        where aggregate = updateStats formatLogDate
+
 updateStats :: (LogDate -> String) -> GitOperationStats -> LogLine -> GitOperationStats
 updateStats formatLogDate (GitOperationStats date misses hits) logLine =
                             let ops         = [isClone, isFetch, isShallowClone, isPush, isRefAdvertisement]
                                 !hits'      = zipWith id hitOps hits
                             in GitOperationStats date' misses' hits'
 
-summarizeGitOperations :: (LogDate -> String) -> [LogLine] -> GitOperationStats
-summarizeGitOperations formatLogDate = foldl' aggregate emptyStats . filter isOutgoingLogLine
-                        where aggregate = updateStats formatLogDate