remove Maybe

This commit is contained in:
Alexander Bondarenko
2024-06-14 17:00:13 +03:00
parent a8337aee8f
commit f5c2e0f19a
3 changed files with 10 additions and 9 deletions
+2 -1
View File
@@ -52,6 +52,7 @@ import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as B
import qualified Data.ByteString.Lazy.Char8 as LB
import Data.Either (fromRight, partitionEithers)
import Data.Foldable (toList)
import Data.Functor (($>))
import Data.Int (Int64)
import Data.IntMap.Strict (IntMap)
@@ -369,7 +370,7 @@ smpServer started cfg@ServerConfig {transports, transportConfig = tCfg} = do
rates <- readTVarIO rates'
forM_ (listToMaybe rates) $ \cs -> do
ts <- getCurrentTime
let values = concatMap (concatMap $ pure . maybe "0" bshow) cs
let values = concatMap (map bshow . toList) cs
withFile statsFilePath AppendMode $ \h -> liftIO $ do
hSetBuffering h LineBuffering
B.hPut h $ B.intercalate "," (strEncode ts : values) <> "\n"
+1 -1
View File
@@ -137,7 +137,7 @@ data Env = Env
clientStats :: TVar (IntMap ClientStats), -- transitive session stats
statsClients :: TVar (IntMap ClientStatsId), -- reverse index from sockets
sendSignedClients :: TMap RecipientId (TVar ClientStatsId), -- reverse index from queues to their senders
serverRates :: TVar [ClientStatsC (Distribution (Maybe Int))], -- current (head) + historical distributions extracted from clientStats for logging and assessing ClientStatsData deviations
serverRates :: TVar [ClientStatsC (Distribution Int)], -- current (head) + historical distributions extracted from clientStats for logging and assessing ClientStatsData deviations
sockets :: SocketState,
clientSeq :: TVar ClientId,
clients :: TVar (IntMap Client),
+7 -7
View File
@@ -129,7 +129,7 @@ getServerStatsData s = do
_qDeletedSecured <- readTVar $ qDeletedSecured s
_qSub <- readTVar $ qSub s
_qSubAuth <- readTVar $ qSubAuth s
_qSubDuplicate <- readTVar $ qSubDuplicate s
_qSubDuplicate <- readTVar $ qSubDuplicate s
_qSubProhibited <- readTVar $ qSubProhibited s
_msgSent <- readTVar $ msgSent s
_msgSentAuth <- readTVar $ msgSentAuth s
@@ -159,7 +159,7 @@ setServerStats s d = do
writeTVar (qDeletedNew s) $! _qDeletedNew d
writeTVar (qDeletedSecured s) $! _qDeletedSecured d
writeTVar (qSub s) $! _qSub d
writeTVar (qSubAuth s) $! _qSubAuth d
writeTVar (qSubAuth s) $! _qSubAuth d
writeTVar (qSubDuplicate s) $! _qSubDuplicate d
writeTVar (qSubProhibited s) $! _qSubProhibited d
writeTVar (msgSent s) $! _msgSent d
@@ -417,21 +417,21 @@ histogram :: Foldable t => t Int -> Histogram
histogram = Histogram . IM.fromListWith (+) . map (,1) . toList
{-# INLINE histogram #-}
distribution :: Histogram -> Distribution (Maybe Int)
distribution :: Histogram -> Distribution Int
distribution h =
Distribution
{ minimal = fst <$> listToMaybe cdf',
{ minimal = maybe 0 fst $ listToMaybe cdf',
bottom50p = bot 0.5, -- std median
top50p = top 0.5,
top20p = top 0.2,
top10p = top 0.1,
top5p = top 0.05,
top1p = top 0.01,
maximal = fst <$> listToMaybe rcdf'
maximal = maybe 0 fst $ listToMaybe rcdf'
}
where
bot p = fst <$> find (\(_, p') -> p' >= p) cdf'
top p = fst <$> find (\(_, p') -> p' <= 1 - p) rcdf'
bot p = maybe 0 fst $ find (\(_, p') -> p' >= p) cdf'
top p = maybe 0 fst $ find (\(_, p') -> p' <= 1 - p) rcdf'
cdf' = cdf h
rcdf' = reverse cdf' -- allow find to work from the smaller end