source: adblock2privoxy/adblock2privoxy/src/Statistics.hs @ e2b555c

Last change on this file since e2b555c was e2b555c, checked in by Alexey Zubritskiy <a.zubritskiy@…>, 4 years ago

Adapted to GHC 7.10, introduced stack build

  • Property mode set to 100644
File size: 1.5 KB
Line 
1module Statistics (
2        collectStat
3)where
4import qualified Data.Map as Map
5import InputParser
6import Data.Maybe
7import Control.Applicative
8import Control.Monad.State
9
10type Stat = Map.Map String Int
11
12collectStat :: [Line] -> [String]
13collectStat = liftA resultLine . Map.toAscList . foldr getStat Map.empty
14        where
15        resultLine (name, value) = concat [name, ": ", show value]
16
17increment :: String -> Stat-> Stat
18increment key = Map.insertWith (+) key 1
19
20isJustFilled :: Maybe [a] -> Bool
21isJustFilled Nothing = False
22isJustFilled (Just list) = not.null $ list
23
24
25getStat :: Line -> Stat-> Stat
26getStat  (Line _ Comment {} ) = increment "Comments"
27getStat  (Line _ Error {}) = increment "Errors"
28getStat  (Line _ ElementHide {}) = increment "Elements hiding rules"
29getStat  (Line _ (RequestBlock policy _ (RequestOptions _ thirdParty domains _ _ _ _ _))) = execState stateState
30    where
31    incrementState = modify . increment
32    stateState = do
33        incrementState "Request block rules total"
34        when (policy == InputParser.Unblock) $ incrementState "Request block rules for exception"
35        when (isJust thirdParty) $ incrementState "Rules with third party option"
36        when ((not.null._negative $ domains) || (isJustFilled . _positive $ domains)) $ incrementState "Request block rules with domain option"
37        when ((not.null._negative $ domains) || (isJustFilled . _positive $ domains)) $ incrementState "Request block rules with request type options"
Note: See TracBrowser for help on using the repository browser.