Skip to content

Commit

Permalink
Define main function and helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
0xpantera committed Feb 3, 2019
1 parent b0e81c8 commit f105983
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,26 @@ import Charts
import Params

main :: IO ()
main = print "Implement"
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 "

0 comments on commit f105983

Please sign in to comment.