diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..82fdd79 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/dist-newstyle \ No newline at end of file diff --git a/README.md b/README.md index f6b19e2..6d7bd74 100644 --- a/README.md +++ b/README.md @@ -10,4 +10,9 @@ This project makes use of the following dependencies (specified in `profun.cabal * http-client (for API requests) * http-client-tls (for API requests) * http-conduit (for API requests) -* aeson (JSON parsing) \ No newline at end of file +* aeson (JSON parsing) +* http-client +* http-client-tls +* http-conduit +* Chart +* Chart-diagrams diff --git a/app/Main.hs b/app/Main.hs index 4a68e3c..40dfa63 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -1,12 +1,15 @@ {-# LANGUAGE OverloadedStrings #-} --needed for ByteString arguments import Network.HTTP.Simple import System.Environment (lookupEnv) +import Plot + main :: IO () main = do apiKey <- getWeatherKey let todayRequest = apiRequestBuilder apiKey "today" response <- httpJSON todayRequest :: IO (Response ()) + generatePlot 20 30 25 --example putStrLn $ show todayRequest putStrLn $ show $ getResponseStatusCode response --apiResponse <- httpJSON "http://httpbin.org/get" :: IO (Response ()) -- specifying type as httpJSON return value is ambigious diff --git a/app/Plot.hs b/app/Plot.hs new file mode 100644 index 0000000..f3304a8 --- /dev/null +++ b/app/Plot.hs @@ -0,0 +1,15 @@ +module Plot where +import Graphics.Rendering.Chart.Easy +import Graphics.Rendering.Chart.Backend.Diagrams + + +formatData :: Double -> Double -> Double -> [(Int, Double)] +formatData yday tday tmrw = [(0, yday), (1, tday), (2, tmrw)] + + +generatePlot :: Double -> Double -> Double -> IO () +generatePlot yday tday tmrw = toFile def "plot/weather.svg" $ do + layout_title .= "Yesterday, Today, and Tomorrow's Temperatures" + layout_margin .= 30 + layout_x_axis . laxis_generate .= autoIndexAxis ["Yesterday", "Today", "Tomorrow"] + plot $ line "Degrees Celsius" [formatData yday tday tmrw] \ No newline at end of file diff --git a/plot/weather.svg b/plot/weather.svg new file mode 100644 index 0000000..b526933 --- /dev/null +++ b/plot/weather.svg @@ -0,0 +1,3 @@ + + \ No newline at end of file diff --git a/profun.cabal b/profun.cabal index 551f973..aff905f 100644 --- a/profun.cabal +++ b/profun.cabal @@ -58,7 +58,7 @@ executable profun main-is: Main.hs -- Modules included in this executable, other than Main. - -- other-modules: + other-modules: Plot -- LANGUAGE extensions used by modules in this package. -- other-extensions: @@ -68,6 +68,8 @@ executable profun http-client ^>=0.7.17, http-client-tls ^>=0.3.6.3, http-conduit ^>=2.3.8.3, + Chart ^>=1.9.5, + Chart-diagrams ^>=1.9.5, aeson ^>=2.2.2.0 -- Directories containing source files.