timeplot 0.1.6 → 0.1.7
raw patch · 2 files changed
+24/−8 lines, 2 filesdep ~strptime
Dependency ranges changed: strptime
Files
- Tools/TimePlot.hs +22/−6
- timeplot.cabal +2/−2
Tools/TimePlot.hs view
@@ -77,13 +77,16 @@ parseTime :: B.ByteString -> Maybe (t, B.ByteString), chartKindF :: S.ByteString -> ChartKind t, + fromTime :: Maybe t,+ toTime :: Maybe t,+ outFile :: FilePath, outFormat :: OutFormat, outResolution :: (Int,Int) } readConf :: [String] -> Conf-readConf args = case (words $ single "time format" "-tf" ("date %Y-%m-%d %H:%M:%S")) of+readConf args = case (words $ single "time format" "-tf" ("date %Y-%m-%d %H:%M:%OS")) of ["num"] -> readConf' (fmap (int2double *** id) . B.readInt) "date":f -> readConf' (strptime (B.pack $ unwords f)) _ -> error "Unrecognized time format (-tf)"@@ -95,7 +98,7 @@ _ -> error $ "Single argument expected for: "++desc++" ("++name++")" readConf' parseTime = Conf {inFile=inFile, outFile=outFile, outFormat=outFormat, outResolution=outRes,- chartKindF=chartKindF, parseTime=parseTime}+ chartKindF=chartKindF, parseTime=parseTime, fromTime=fromTime, toTime=toTime} where inFile = single "input file" "-if" (error "No input file (-if) specified") outFile = single "output file" "-o" (error "No output file (-of) specified")@@ -112,6 +115,9 @@ k:_ -> k _ -> defaultKind + fromTime = fst `fmap` (parseTime . B.pack $ single "minimum time (inclusive)" "-fromTime" "")+ toTime = fst `fmap` (parseTime . B.pack $ single "maximum time (exclusive)" "-toTime" "")+ parseKind ["hist", n ] = KindHistogram {binSize=read n} parseKind ["freq", n ] = KindFreq {binSize=read n,style=BarsClustered} parseKind ["freq", n,s] = KindFreq {binSize=read n,style=parseStyle s}@@ -369,10 +375,16 @@ n = length xs toFreq = if n==0 then const 0 else (\k -> fromIntegral k/fromIntegral n) +zoom :: (TimeAxis t) => [(t, S.ByteString, InEvent)] -> Maybe t -> Maybe t -> [(t, S.ByteString, InEvent)]+zoom events fromTime toTime = filter p events+ where + p (t, _, _) = (maybe True (\ft -> t >= ft) fromTime) &&+ (maybe True (\tt -> t < tt) toTime)+ 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]",+ " [-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)", " -or - output resolution (default 640x480)",@@ -381,10 +393,13 @@ " (for instance, line numbers); '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]. ",- " Default: 'date %Y-%m-%d %H:%M:%S'",+ " We also support %OS for fractional seconds (i.e. %OS will parse 12.4039).",+ " Default: 'date %Y-%m-%d %H:%M:%OS'", " -k P K - set diagram kind for tracks matching pattern P 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)", "", "Input format: lines of the following form:", "1234 >A - at time 1234, during event A has begun",@@ -429,8 +444,9 @@ Window -> \c w h f -> renderableToWindow c w h } case conf of- Conf{parseTime=parseTime, inFile=inFile, chartKindF=chartKindF, outFile=outFile, outResolution=outResolution} -> do+ Conf{parseTime=parseTime, inFile=inFile, chartKindF=chartKindF, outFile=outFile, outResolution=outResolution, fromTime=fromTime, toTime=toTime} -> do source <- readSource parseTime inFile- let chart = makeChart chartKindF source+ let source' = zoom source fromTime toTime+ let chart = makeChart chartKindF source' let (w,h) = outResolution render chart w h outFile
timeplot.cabal view
@@ -1,5 +1,5 @@ Name: timeplot-Version: 0.1.6+Version: 0.1.7 License: BSD3 License-file: LICENSE Copyright: Eugene Kirpichov, 2009@@ -27,7 +27,7 @@ else Build-Depends: base < 3 - Build-Depends: Chart >= 0.12, cairo, bytestring, bytestring-lexing, strptime >= 0.1.4, time, + Build-Depends: Chart >= 0.12, cairo, bytestring, bytestring-lexing, strptime >= 0.1.5, time, containers, colour, data-accessor == 0.2.*, data-accessor-template >= 0.2.1.1 && < 0.3, haskell98, regex-pcre Main-Is: Tools/TimePlot.hs