Skip to content

Instantly share code, notes, and snippets.

@mjul
Created March 1, 2016 10:23
Show Gist options
  • Save mjul/64c29ecb44e001e1d523 to your computer and use it in GitHub Desktop.
Save mjul/64c29ecb44e001e1d523 to your computer and use it in GitHub Desktop.
World Bank TypeProvider example to get data on the major Nordic countries
// World Bank data example
// Look up some indicators for the Nordic markets
#r @"..\packages\FSharp.Data.2.2.5\lib\net40\FSharp.Data.dll"
open FSharp.Data
let wb= WorldBankData.GetDataContext()
let countries = [
wb.Countries.Denmark
wb.Countries.Sweden
wb.Countries.Finland
wb.Countries.Norway
]
let getLatest (indicator:Runtime.WorldBank.Indicator) =
let year = Seq.max (indicator.Years)
indicator.Item(year)
type Market = {Country:string; Population:int; Gdp:decimal; GdpPerCapita:decimal;}
let markets = [for c in countries do
yield {
Country=c.Name
Population=int (getLatest c.Indicators.``Population, total``)
Gdp=decimal (getLatest c.Indicators.``GDP at market prices (current US$)``)
GdpPerCapita=decimal (getLatest c.Indicators.``GDP per capita (current US$)``)
}
]
let dkGDP = getLatest wb.Countries.Denmark.Indicators.``GDP at market prices (current US$)``
let dkMarket = markets |> Seq.find (fun x -> x.Country = "Denmark")
let dkTurnover = float 100 // million
let relativeMarketSize (m:Market) =
let x = dkMarket.Population
(float m.Population)/(float x)
for m in markets do
printfn "%s\t%10d\t%10.0f\t%20.0f\t%4.0f" m.Country m.Population m.GdpPerCapita m.Gdp (dkTurnover*(relativeMarketSize m))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment