timeplot 0.2.11 → 0.2.12
raw patch · 2 files changed
+44/−32 lines, 2 files
Files
- Tools/TimePlot.hs +43/−31
- timeplot.cabal +1/−1
Tools/TimePlot.hs view
@@ -110,13 +110,14 @@ | KindCumSum | KindSum { binSize :: Delta t } | KindNone+ deriving (Show) data Conf = forall t . TimeAxis t => Conf { inFile :: FilePath, parseTime :: B.ByteString -> Maybe (t, B.ByteString),- chartKindF :: S.ByteString -> ChartKind t,+ chartKindF :: S.ByteString -> [ChartKind t], fromTime :: Maybe t, toTime :: Maybe t,@@ -126,6 +127,8 @@ outResolution :: (Int,Int) } +data KindChoiceOperator = Cut | Accumulate+ readConf :: [String] -> Conf readConf args = case (words $ single "time format" "-tf" ("date %Y-%m-%d %H:%M:%OS")) of ["num"] -> readConf' readDouble@@ -154,11 +157,14 @@ outRes = parseRes $ single "output resolution" "-or" "640x480" where parseRes s = case break (=='x') s of (h,_:v) -> (read h,read v)- chartKindF = kindByRegex [((matches regex), parseKind (words kind)) | [regex,kind] <- getArg "-k" 2 args]+ chartKindF = kindByRegex $ + [(Cut, matches regex, parseKind (words kind)) | [regex,kind] <- getArg "-k" 2 args] +++ [(Accumulate, matches regex, parseKind (words kind)) | [regex,kind] <- getArg "+k" 2 args] where- kindByRegex rks s = case [k | (p,k) <- rks, p s] of- k:_ -> k- _ -> defaultKind+ ifNull xs y = case xs of { [] -> [y] ; _ -> xs }+ kindByRegex rks s = (defaultKindsPlus ++ + [k | (Accumulate, p, k) <- rks, p s] +++ [case [k | (Cut, p, k) <- rks, p s] of { [] -> defaultKindMinus; k:_ -> k }]) matches regex = matchTest (makeRegexOpts defaultCompOpt (ExecOption {captureGroups = False}) regex) fromTime = fst `fmap` (parseTime . B.pack $ single "minimum time (inclusive)" "-fromTime" "")@@ -183,7 +189,8 @@ parseKind ["none" ] = KindNone parseKind ws = error ("Unknown diagram kind " ++ unwords ws) - defaultKind = parseKind $ words $ single "default kind" "-dk" "event"+ defaultKindMinus = parseKind $ words $ single "default kind" "-dk" "none"+ defaultKindsPlus = map (parseKind . words . head) $ getArg "+dk" 1 args parseStyle "stacked" = BarsStacked parseStyle "clustered" = BarsClustered@@ -227,7 +234,7 @@ _ -> Nothing makeChart :: forall t . TimeAxis t =>- (S.ByteString -> ChartKind t) -> [(t, S.ByteString, InEvent)] -> Renderable ()+ (S.ByteString -> [ChartKind t]) -> [(t, S.ByteString, InEvent)] -> Renderable () makeChart chartKindF [] = emptyRenderable makeChart chartKindF events0 = renderLayout1sStacked plots where@@ -235,15 +242,17 @@ track2events = reverse `fmap` foldl' insert M.empty [(s, (t, e)) | (t, s, e) <- events] where insert m (s, r) = M.alter (Just . maybe [r] (r:)) s m - plots = [ plotTrack k es | (k, es) <- M.toList track2events, - case (chartKindF k) of {KindNone -> False ; KindDuration _ _ -> False ; _ -> True} ] +++ plots = [ plotTrack k kind es | (k, es) <- M.toList track2events, + kind <- chartKindF k,+ case kind of {KindNone -> False ; KindDuration _ _ -> False ; _ -> True} ] ++ durationPlots durationPlots = [ plotWithKind name k es | (name, (k,es)) <- M.toList durationTracks ] where durationTracks = M.fromListWith (\(ka,as) (kb,bs) -> (ka,mergeOn fst as bs)) components- components = [ (mn k, (sk, edges2durations (edges es)))| (k, es) <- M.toList track2events, - Just (sk,mn) <- [case (chartKindF k) of - {KindDuration mn sk -> Just (sk,mn) ; _ -> Nothing}]]+ components = [ (mn k, (sk, edges2durations (edges es))) + | (k, es) <- M.toList track2events, + kind <- chartKindF k,+ Just (sk,mn) <- [case kind of {KindDuration mn sk -> Just (sk,mn) ; _ -> Nothing}]] mergeOn f [] ys = ys mergeOn f xs [] = xs mergeOn f (x:xs) (y:ys) @@ -254,7 +263,7 @@ times = sort $ [t | tes <- M.elems track2events, (t,_)<- tes] commonTimeAxis = autoAxis times - plotTrack name es = plotWithKind name (chartKindF name) es+ plotTrack name kind es = plotWithKind name kind es plotWithKind name k es = case k of KindCount bs -> withAnyOrdinate $ plotTrackCount name es bs@@ -487,24 +496,27 @@ showHelp = mapM_ putStrLn [ "", "tplot - a tool for drawing timing diagrams. See http://www.haskell.org/haskellwiki/Timeplot", "Usage: tplot [-o OFILE] [-of {png|pdf|ps|svg|x}] [-or 640x480] -if IFILE [-tf TF] ",- " [-k Pat1 Kind1 -k Pat2 Kind2 ...] [-dk KindN] [-fromTime TIME] [-toTime TIME]",- " -o OFILE - output file (required if -of is not x)",- " -of - output format (x means draw result in a window, default: extension of -o)",- " x is only available if you installed timeplot with --flags=gtk",- " -or - output resolution (default 640x480)",- " -if IFILE - input file; '-' means 'read from stdin'",- " -tf TF - time format: 'num' means that times are floating-point numbers",- " (for instance, seconds elapsed since an event); 'date PATTERN' means that times are dates",- " in the format specified by PATTERN - see http://linux.die.net/man/3/strptime,",- " for example, [%Y-%m-%d %H:%M:%S] parses dates like [2009-10-20 16:52:43]. ",- " We also support %OS for fractional seconds (i.e. %OS will parse 12.4039 or 12,4039).",- " Default: 'date %Y-%m-%d %H:%M:%OS'",- " -k P K - set diagram kind for tracks matching regex P (in the format of regex-tdfa, which",- " is at least POSIX-compliant and supports some GNU extensions) to K ",- " (-k clauses are matched till first success)",- " -dk - set default diagram kind",- " -fromTime - filter records whose time is >= this time (formatted according to -tf)",- " -toTime - filter records whose time is < this time (formatted according to -tf)",+ " [{+|-}k Pat1 Kind1 {+|-}k Pat2 Kind2 ...] [{+|-}dk KindN] [-fromTime TIME] [-toTime TIME]",+ " -o OFILE - output file (required if -of is not x)",+ " -of - output format (x means draw result in a window, default: extension of -o)",+ " x is only available if you installed timeplot with --flags=gtk",+ " -or - output resolution (default 640x480)",+ " -if IFILE - input file; '-' means 'read from stdin'",+ " -tf TF - time format: 'num' means that times are floating-point numbers",+ " (for instance, seconds elapsed since an event); 'date PATTERN' means that times are dates",+ " in the format specified by PATTERN - see http://linux.die.net/man/3/strptime,",+ " for example, [%Y-%m-%d %H:%M:%S] parses dates like [2009-10-20 16:52:43]. ",+ " We also support %OS for fractional seconds (i.e. %OS will parse 12.4039 or 12,4039).",+ " Default: 'date %Y-%m-%d %H:%M:%OS'",+ " {+|-}dk - set default diagram kind",+ " {+|-}k P K - set diagram kind for tracks matching regex P (in the format of regex-tdfa, which",+ " is at least POSIX-compliant and supports some GNU extensions) to K ",+ " EXPLANATION:",+ " -k clauses are matched till first success, +k are all matched:",+ " a track is drawn acc. to all matching +k, to +dk AND ALSO to the",+ " first matching -k, or -dk if none of -k match",+ " -fromTime - filter records whose time is >= this time (formatted according to -tf)",+ " -toTime - filter records whose time is < this time (formatted according to -tf)", "", "Input format: lines of the following form:", "1234 >A - at time 1234, activity A has begun",
timeplot.cabal view
@@ -1,5 +1,5 @@ Name: timeplot-Version: 0.2.11+Version: 0.2.12 License: BSD3 License-file: LICENSE Copyright: Eugene Kirpichov, 2009