Created
June 2, 2013 20:43
-
-
Save davidgrenier/5694901 to your computer and use it in GitHub Desktop.
Readers of Sergey Tihon's Blog vs Country population using FSharp.Data WorldBank type provider.
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
#r @"C:\Bib\Projects\FSharp.Data\src\bin\Release\FSharp.Data.dll" | |
open FSharp.Data | |
let data = WorldBankData.GetDataContext() | |
let ``Sergey's data`` = | |
[ | |
"United States", 11823 | |
"United Kingdom", 4256 | |
"Germany", 2121 | |
"Russian Federation", 1674 | |
"Belarus", 1579 | |
"Canada", 1552 | |
"India", 1454 | |
"Sweden", 1161 | |
"Australia", 1144 | |
"France", 1108 | |
"Japan", 885 | |
"Netherlands", 828 | |
"Switzerland", 747 | |
"Ukraine", 663 | |
"Denmark", 660 | |
"Spain", 601 | |
"Poland", 462 | |
"Brazil", 443 | |
"Greece", 357 | |
"Austria", 357 | |
"Hungary", 350 | |
] | |
let maxLength = | |
``Sergey's data`` | |
|> Seq.map fst | |
|> Seq.map (fun x -> x.Length) | |
|> Seq.max | |
query { | |
for (countryName, readers) in ``Sergey's data`` do | |
join c in data.Countries on (countryName = c.Name) | |
let population = | |
query { | |
for pop in c.Indicators.``Population, total``.Values do | |
last | |
} | |
let ratio = float readers / population * 1e2 | |
sortByDescending ratio | |
select (sprintf "|%*s|%6i|%11.0g|%.4f%%|" (maxLength + 1) c.Name readers population ratio) | |
} |> Seq.iter (printfn "%s") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment