Permalink
Browse files

Moving Averages: command-line Options parsing

  • Loading branch information...
1 parent 13cad64 commit 910709a7100de682f763cb336eee2487ac5d59ff @alang9 committed Oct 20, 2011
Showing with 20 additions and 3 deletions.
  1. +20 −3 tools/zoom-cache-gnuplot.hs
@@ -14,6 +14,7 @@ import Data.ZoomCache.Gnuplot
import Data.ZoomCache.Read (getTrackType, getCacheFile)
import qualified Graphics.Gnuplot.Advanced as Plot
import Graphics.Gnuplot.Simple
+import qualified Graphics.Gnuplot.Terminal.PNG as PNG
import qualified Graphics.Gnuplot.Terminal.X11 as X11
import Graphics.Gnuplot.Value.Tuple (C(..))
import qualified Graphics.Gnuplot.Plot.TwoDimensional as Plot
@@ -40,12 +41,14 @@ data Options = Options
{ gnuplotOpts :: [Attribute]
, candleSticks :: [(FilePath, TrackNo, Int)]
, avgs :: [(FilePath, TrackNo, Int)]
+ , mavgs :: [(FilePath, TrackNo, Int)]
}
defaultOptions = Options
{ gnuplotOpts = []
, candleSticks = []
, avgs = []
+ , mavgs = []
}
parseCustom :: String -> Attribute
@@ -63,10 +66,24 @@ options =
, Option ['c'] ["candlesticks"]
(OptArg ((\ f opts ->
opts { candleSticks = either (error "bad command line syntax")
- (: candleSticks opts) $ parseTrack f }) .
+ (: candleSticks opts) $ parseTrack f }) .
fromMaybe "candlesticks")
"FILE:TRACKNO:SUMMARYLVL")
- "candelsticks FILE:TRACKNO:SUMMARYLVL"
+ "candlesticks FILE:TRACKNO:SUMMARYLVL"
+ , Option ['a'] ["avg"]
+ (OptArg ((\ f opts ->
+ opts { avgs = either (error "bad command line syntax")
+ (: candleSticks opts) $ parseTrack f }) .
+ fromMaybe "avg")
+ "FILE:TRACKNO:SUMMARYLVL")
+ "avg FILE:TRACKNO:SUMMARYLVL"
+ , Option ['m'] ["mavg"]
+ (OptArg ((\ f opts ->
+ opts { mavgs = either (error "bad command line syntax")
+ (: candleSticks opts) $ parseTrack f }) .
+ fromMaybe "mavg")
+ "FILE:TRACKNO:SUMMARYLVL")
+ "mavg FILE:TRACKNO:SUMMARYLVL"
]
parseOpts :: [String] -> IO (Options, [String])
@@ -85,7 +102,7 @@ main = do
cPlots <- fmap (mconcat . catMaybes) . mapM candleProcess $ candleSticks opts
aPlots <- fmap (mconcat . catMaybes) . mapM avgProcess $ avgs opts
let plots = cPlots `mappend` aPlots
- exitWith =<< Plot.plot X11.cons plots
+ exitWith =<< Plot.plot (PNG.cons "test.png") plots
@alang9
alang9 Oct 20, 2011 Owner

Also changed output to PNG, to a constant file

where
candleProcess :: (FilePath, TrackNo, Int) -> IO (Maybe (Plot.T TimeStamp Double))
candleProcess (fp, tn, lvl) = do

0 comments on commit 910709a

Please sign in to comment.