plot-light 0.1.2 → 0.2
raw patch · 5 files changed
+134/−96 lines, 5 filesdep ~basenew-component:exe:plot-light
Dependency ranges changed: base
Files
- app/timeseries/Main.hs +110/−0
- plot-light.cabal +19/−18
- src/Data/TimeSeries/Forex.hs +0/−13
- src/Graphics/Rendering/Plot/Light/IO/Text.hs +0/−65
- src/Graphics/Rendering/Plot/Light/PlotTypes.hs +5/−0
+ app/timeseries/Main.hs view
@@ -0,0 +1,110 @@+{-# language OverloadedStrings #-}+module Main where++-- import Control.Arrow ((***), (&&&))++import Graphics.Rendering.Plot.Light+import Graphics.Rendering.Plot.Light.PlotTypes+ +import qualified Data.Attoparsec.Text as A+import qualified Attoparsec.Time as AT+import qualified Data.Text as T +import qualified Data.Text.IO as T (readFile, writeFile)+import Data.Scientific (Scientific, toRealFloat)+import Text.Blaze.Svg.Renderer.String (renderSvg)+import qualified Data.Colour.Names as C++import Control.Applicative ((<|>))+import Data.Time (Day, TimeOfDay)+++++fname = "data/forex_small"++xPlot = 800+yPlot = 600+fnameOut = "data/forex_plot_3.svg"+++main = do+ d <- T.readFile fname+ let pd = A.parseOnly parseFxDataset d+ case pd of Left e -> error e+ Right d -> -- print $ tsAxis (toFloat . rateOpen) xPlot yPlot 3 C.blue (-45) d+ do+ let svg_t = svgHeader (mkFrameOrigin xPlot yPlot) $ tsAxis avgTs xPlot yPlot 3 C.black C.red (-45) d+ -- putStrLn $ renderSvg svg_t+ T.writeFile fnameOut $ T.pack $ renderSvg svg_t++toFloat :: Scientific -> Float+toFloat x = toRealFloat x :: Float+++avgTs :: FxRow Scientific -> Float+avgTs x = 0.5 * (h + l) where+ h = toFloat (rateHigh x)+ l = toFloat (rateLow x)++++++-- Forex time series parsers - related+++data FxRow a = FxRow {+ rateOpen :: a+ , rateHigh :: a+ , rateLow :: a+ , rateClose :: a+ } deriving (Eq, Show)+++space, comma :: A.Parser Char+space = A.char ' '+comma = A.char ','++-- | Parse a row of numbers, separated by `sep`+rowNums :: A.Parser s -> A.Parser [Scientific]+rowNums sep = A.sepBy A.scientific sep++rowNumSpace :: A.Parser [Scientific]+rowNumSpace = rowNums space++-- | parse a grid of numbers, separated by `sep`+gridNum :: A.Parser s -> A.Parser [[Scientific]]+gridNum sep = A.sepBy (rowNums sep) A.endOfLine++++++++++-- * Forex dataset++parseFxDataset :: A.Parser [TsPoint (FxRow Scientific)]+parseFxDataset = A.sepBy parseFxRow A.endOfLine++parseFxRow :: A.Parser (TsPoint (FxRow Scientific))+parseFxRow = do+ (d, t) <- parseDateTime+ _ <- comma+ open <- A.scientific+ _ <- comma+ hi <- A.scientific+ _ <- comma+ lo <- A.scientific+ _ <- comma+ close <- A.scientific+ pure $ Tsp (Tick d t) (FxRow open hi lo close)++parseDateTime :: A.Parser (Day, TimeOfDay)+parseDateTime = do+ d <- AT.dayInISO8601+ _ <- space+ t <- AT.timeOfDayInISO8601+ return (d, t)
plot-light.cabal view
@@ -1,5 +1,5 @@ name: plot-light-version: 0.1.2+version: 0.2 synopsis: A lightweight plotting library, exporting to SVG description: A lightweight plotting library, exporting to SVG homepage: https://github.com/ocramz/plot-light@@ -21,21 +21,20 @@ default-language: Haskell2010 ghc-options: -Wall hs-source-dirs: src- exposed-modules: Graphics.Rendering.Plot.Light + exposed-modules: Graphics.Rendering.Plot.Light+ Graphics.Rendering.Plot.Light.PlotTypes other-modules: Graphics.Rendering.Plot.Light.Internal- Graphics.Rendering.Plot.Light.IO.Text Graphics.Rendering.Plot.Light.PlotTypes.Heatmap Graphics.Rendering.Plot.Light.PlotTypes.Scatter Graphics.Rendering.Plot.Light.PlotTypes.TimeSeries Graphics.Rendering.Plot.Light.PlotTypes.TimeSeries.Candlestick Data.TimeSeries- Data.TimeSeries.Forex Graphics.Rendering.Plot.Light.Internal.Geometry build-depends: base >= 4.7 && < 5 , time- , attoparsec-time + -- , attoparsec-time -- , vector- , attoparsec+ -- , attoparsec , scientific , text , colour@@ -45,18 +44,20 @@ -- , QuickCheck --- executable plot-light--- default-language: Haskell2010--- ghc-options: -threaded -rtsopts -with-rtsopts=-N--- hs-source-dirs: app/timeseries--- main-is: Main.hs--- build-depends: base--- , plot-light--- -- , attoparsec--- -- , text--- -- , colour--- -- , blaze-svg--- -- , scientific+executable plot-light+ default-language: Haskell2010+ ghc-options: -threaded -rtsopts -with-rtsopts=-N+ hs-source-dirs: app/timeseries+ main-is: Main.hs+ build-depends: base+ , plot-light+ , attoparsec+ , attoparsec-time+ , time+ , text+ , colour+ , blaze-svg+ , scientific test-suite spec default-language: Haskell2010
− src/Data/TimeSeries/Forex.hs
@@ -1,13 +0,0 @@-module Data.TimeSeries.Forex where----data FxRow a = FxRow {- rateOpen :: a- , rateHigh :: a- , rateLow :: a- , rateClose :: a- } deriving (Eq, Show)---
− src/Graphics/Rendering/Plot/Light/IO/Text.hs
@@ -1,65 +0,0 @@-module Graphics.Rendering.Plot.Light.IO.Text where--import Data.Text-import qualified Data.Attoparsec.Text as A-import qualified Data.Attoparsec.Internal.Types as AP (Parser)-import Data.Scientific--import Control.Applicative ((<|>))-import Data.Time (Day, TimeOfDay)-import qualified Attoparsec.Time as AT--import Data.TimeSeries-import Data.TimeSeries.Forex----space, comma :: A.Parser Char-space = A.char ' '-comma = A.char ','---- | Parse a row of numbers, separated by `sep`-rowNums :: AP.Parser Text s -> AP.Parser Text [Scientific]-rowNums sep = A.sepBy A.scientific sep--rowNumSpace :: AP.Parser Text [Scientific]-rowNumSpace = rowNums space---- | parse a grid of numbers, separated by `sep`-gridNum :: AP.Parser Text s -> AP.Parser Text [[Scientific]]-gridNum sep = A.sepBy (rowNums sep) A.endOfLine------------ * Forex dataset--parseFxDataset :: AP.Parser Text [TsPoint (FxRow Scientific)]-parseFxDataset = A.sepBy parseFxRow A.endOfLine--parseFxRow :: AP.Parser Text (TsPoint (FxRow Scientific))-parseFxRow = do- (d, t) <- parseDateTime- _ <- comma- open <- A.scientific- _ <- comma- hi <- A.scientific- _ <- comma- lo <- A.scientific- _ <- comma- close <- A.scientific- pure $ Tsp (Tick d t) (FxRow open hi lo close)--parseDateTime :: AP.Parser Text (Day, TimeOfDay)-parseDateTime = do- d <- AT.dayInISO8601- _ <- space- t <- AT.timeOfDayInISO8601- return (d, t)--
+ src/Graphics/Rendering/Plot/Light/PlotTypes.hs view
@@ -0,0 +1,5 @@+module Graphics.Rendering.Plot.Light.PlotTypes (module X) where++import Graphics.Rendering.Plot.Light.PlotTypes.TimeSeries as X++import Data.TimeSeries as X