Skip to content

Commit

Permalink
Add the freq determining offset to get the exact stats
Browse files Browse the repository at this point in the history
  • Loading branch information
adithyaov committed Nov 13, 2023
1 parent c36862a commit a29af8d
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions stat-collector-src/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -231,20 +231,23 @@ printTable rows = do
fillRow r = zipWith (\n x -> fill n x) maxLengths r

statsToTable
:: [(EventId, Int)]
:: Int
-> [(EventId, Int)]
-> Counter
-> [(EventId, Int)]
-> Map EventId StatResult
-> [[String]]
statsToTable winSizeList counter keyTracker mp =
statsToTable freqMeasurementWindow winSizeList counter keyTracker mp =
["Tag", "Mean", "Min", "Max", "Count", "Window"]
: map
(\(evId@(EventId _ t _), (me, rg)) ->
[ t
, showFFloat (Just 2) me ""
, showMaybe (fmap fst rg)
, showMaybe (fmap snd rg)
, show $ fromJust $ lookup evId keyTracker
, show
$ (+freqMeasurementWindow)
$ fromJust $ lookup evId keyTracker
, show $ fromJust $ lookup evId winSizeList
])
(sortBy sorterFunc
Expand All @@ -262,19 +265,25 @@ statsToTable winSizeList counter keyTracker mp =
_ -> error "Key not found"

printSlidingStats
:: [(EventId, Int)]
:: Int
-> [(EventId, Int)]
-> Counter
-> Int
-> Stream IO ([(EventId, Int)], Map EventId StatResult)
-> IO ()
printSlidingStats winSizeList counter rowsOnPage strm =
printSlidingStats freqMeasurementWindow winSizeList counter rowsOnPage strm =
Stream.fold
(Fold.drainMapM
(\(order, mp) -> do
ANSI.setCursorPosition 0 0
printTable
(take rowsOnPage
(statsToTable winSizeList counter order mp))
(statsToTable
freqMeasurementWindow
winSizeList
counter
order
mp))
hFlush stdout
))
strm
Expand Down Expand Up @@ -313,4 +322,4 @@ main = do
<$> Fold.latest)))
scanStats winSizeList rest
& Stream.sampleIntervalEnd 2
& printSlidingStats winSizeList counter rowsOnPage
& printSlidingStats freqMeasurementWindow winSizeList counter rowsOnPage

0 comments on commit a29af8d

Please sign in to comment.