Commits

Stefan Saasen committed a501daa

Reorganize the functions in the GitOpsAnalyser

  • Participants
  • Parent commits a018e4e

Comments (0)

Files changed (1)

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

     ,cacheHits                  :: [Int]
 }
 
--- | Parse and aggregate the log file input into a list of GitOperationStats
+-- | Parse and aggregate the log file input into a list of hourly GitOperationStats
 analyseGitOperations :: Input -> [GitOperationStats]
 analyseGitOperations rawLines =
     let formatLogDate date = printf "%04d-%02d-%02d %02d" (getYear date) (getMonth date)
 emptyStats = GitOperationStats "" zero zero
         where zero = replicate 5 0
 
+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 (GitOperationStats date misses hits) logLine =
+                                let ops         = [isClone, isFetch, isShallowClone, isPush, isRefAdvertisement]
+                                    inc op      = if op logLine then (+1) else (+0)
+                                    missOps     = map (inc . uncachedOperation) ops
+                                    hitOps      = map (inc . cachedOperation) ops
+                                    !date'      = if null date then formatLogDate $ getDate logLine else date
+                                    !misses'    = zipWith id missOps misses
+                                    !hits'      = zipWith id hitOps hits
+                                in GitOperationStats date' misses' hits'
+
+-- =================================================================================
+--                                Predicates
+-- =================================================================================
+
 -- As of 1.1.2 of the clone cache plugin, refs are explicitly listed in the
 -- labels field, most of the data we have does _not_ have that information though
 isRefAdvertisement :: LogLine -> Bool
 
 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]
-                                inc op      = if op logLine then (+1) else (+0)
-                                missOps     = map (inc . uncachedOperation) ops
-                                hitOps      = map (inc . cachedOperation) ops
-                                !date'      = if null date then formatLogDate $ getDate logLine else date
-                                !misses'    = zipWith id missOps misses
-                                !hits'      = zipWith id hitOps hits
-                            in GitOperationStats date' misses' hits'
-