Created
May 3, 2020 08:44
-
-
Save Szer/587672731825959d488423da18437751 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open FSharp.Data | |
open XPlot.Plotly | |
let url = sprintf "https://bank.gov.ua/markets/exchangerates?date=%s&period=daily" | |
type Currency = HtmlProvider<"https://bank.gov.ua/markets/exchangerates?date=03.05.2020&period=daily", Culture = "ru-RU"> | |
let dates = | |
[|1..30|] | |
|> Array.map (sprintf "%02d.04.2020") | |
let dataSets = | |
dates | |
|> Array.map (fun day -> async { | |
let url = url day | |
let! dataSet = Currency.AsyncLoad url | |
return day, dataSet | |
}) | |
|> fun asyncs -> Async.Parallel (asyncs, 8) | |
|> Async.RunSynchronously | |
let curPerDay = | |
dataSets | |
|> Array.collect (fun (day, dataSet) -> | |
dataSet.Tables.ExchangeRates.Rows | |
|> Array.map (fun rate -> | |
{| Day = day | |
Currency = rate.``Код літерний`` | |
Rate = rate.``Офіційний курс для відображення в бухгалтерському обліку, для операцій НБУ з ДКСУ та в інших випадках, визначених законодавством України, без зобов’язань Національного банку України купувати та продавати зазначені валюти за цими курсами`` |} | |
) | |
) | |
let charts = | |
curPerDay | |
|> Array.groupBy (fun x -> x.Currency) | |
|> Array.map (fun (currency, data) -> | |
let orderedData = | |
data | |
|> Array.sortBy (fun x -> x.Day) | |
Scatter( | |
x = (orderedData |> Array.map (fun x -> x.Day)), | |
y = (orderedData |> Array.map (fun x -> x.Rate)), | |
name = currency | |
) | |
) | |
charts | |
|> Chart.Plot | |
|> Chart.Show |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment