-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.hs
38 lines (31 loc) · 1.08 KB
/
Main.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
{-# LANGUAGE RecordWildCards #-}
module Main where
import Control.Monad (when)
import qualified Data.Text.IO as TIO
import qualified Data.ByteString.Lazy as BL (readFile)
import Data.Csv (decodeByName)
import QuoteData
import Statistics
import StatReport
import Charts
import Params
main :: IO ()
main = cmdLineParser >>= work
work :: Params -> IO ()
work params = do
csvData <- BL.readFile (fname params)
case decodeByName csvData of
Left err -> putStrLn err
Right (_, quotes) -> generateReports params quotes
generateReports :: (Functor t, Foldable t) => Params -> t QuoteData -> IO ()
generateReports Params {..} quotes = do
TIO.putStr $ statReport statInfo'
when prices $ plotChart title quotes [Open, Close, High, Low] fname_prices
when volumes $ plotChart title quotes [Volume] fname_volumes
where
statInfo' = statInfo quotes
withCompany pref = if company /= "" then pref ++ company else ""
img_suffix = withCompany "_" ++ ".svg"
fname_prices = "prices" ++ img_suffix
fname_volumes = "volumes" ++ img_suffix
title = "Historical Quotes" ++ withCompany " for "