This commit is contained in:
Szymon Szczubkowski 2024-05-25 20:25:24 +02:00
commit 642bab0ba2
6 changed files with 31 additions and 2 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/dist-newstyle

View File

@ -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)
* aeson (JSON parsing)
* http-client
* http-client-tls
* http-conduit
* Chart
* Chart-diagrams

View File

@ -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

15
app/Plot.hs Normal file
View File

@ -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]

3
plot/weather.svg Normal file

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 103 KiB

View File

@ -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.