diff --git a/src/Eventlog/Args.hs b/src/Eventlog/Args.hs index d17e628..dbb4dfc 100644 --- a/src/Eventlog/Args.hs +++ b/src/Eventlog/Args.hs @@ -21,7 +21,7 @@ data Option = ShowVersion | Run Args -data Sort = Size | StdDev | Name | Gradient +data Sort = Size | StdDev | Name | Gradient | Number data Args = Args { @@ -47,7 +47,7 @@ argParser :: Parser Option argParser = Run <$> (Args <$> option parseSort ( long "sort" - <> help "How to sort the bands. One of: size (default), stddev, name, gradient." + <> help "How to sort the bands. One of: size (default), stddev, name, number, gradient." <> value Size <> metavar "FIELD" ) <*> switch @@ -118,8 +118,9 @@ parseSort = eitherReader $ \s -> case s of "size" -> Right Size "stddev" -> Right StdDev "name" -> Right Name + "number" -> Right Number "gradient" -> Right Gradient - _ -> Left "expected one of: size, stddev, name" + _ -> Left "expected one of: size, stddev, name, number" args :: IO Option args = execParser argsInfo diff --git a/src/Eventlog/Prune.hs b/src/Eventlog/Prune.hs index 76564f2..0f155e6 100644 --- a/src/Eventlog/Prune.hs +++ b/src/Eventlog/Prune.hs @@ -1,5 +1,6 @@ {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ViewPatterns #-} +{-# LANGUAGE TypeApplications #-} module Eventlog.Prune ( pruneBands, pruneDetailed ) where @@ -11,6 +12,8 @@ import Data.Map (Map, fromList, (!), toList) import Eventlog.Args (Args(..), Sort(..)) import Data.Maybe +import Text.Read (readMaybe) +import qualified Data.Text as T type Compare a = a -> a -> Ordering @@ -21,15 +24,20 @@ getComparison Args { sorting = StdDev, reversing = False } = cmpStdDevDescendin getComparison Args { sorting = StdDev, reversing = True } = cmpStdDevAscending getComparison Args { sorting = Name, reversing = True } = cmpNameDescending getComparison Args { sorting = Name, reversing = False } = cmpNameAscending +getComparison Args { sorting = Number, reversing = True } = cmpNumberDescending +getComparison Args { sorting = Number, reversing = False } = cmpNumberAscending getComparison Args { sorting = Gradient, reversing = True } = cmpGradientAscending getComparison Args { sorting = Gradient, reversing = False } = cmpGradientDescending cmpNameAscending, cmpNameDescending, + cmpNumberAscending, cmpNumberDescending, cmpStdDevAscending, cmpStdDevDescending, cmpSizeAscending, cmpSizeDescending, cmpGradientAscending, cmpGradientDescending :: Compare (Bucket, BucketInfo) cmpNameAscending = comparing fst cmpNameDescending = flip cmpNameAscending +cmpNumberAscending (Bucket a, _) (Bucket b, _) = comparing (readMaybe @Int . T.unpack) a b <> compare a b +cmpNumberDescending = flip cmpNumberAscending cmpStdDevAscending = comparing (bucketStddev . snd) cmpStdDevDescending = flip cmpStdDevAscending cmpSizeAscending = comparing (bucketTotal . snd)