Created
January 3, 2015 03:31
-
-
Save adamchester/e5a65fc1ed7f1f256697 to your computer and use it in GitHub Desktop.
F# Community Twitter Clients (2014)
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
#I @"packages/" | |
#r @"FSharp.Data/lib/net40/FSharp.Data.dll" | |
#load @"FSPlot\FsPlotBootstrap.fsx" | |
#r @"Deedle\lib\net40\Deedle.dll" | |
do fsi.AddPrinter(fun (printer:Deedle.Internal.IFsiFormattable) -> "\n" + (printer.Format())) | |
open FSharp.Data | |
type Tweets = CsvProvider<"fsharp_2013-2014.csv"> | |
let tweets = Tweets.GetSample() | |
let extractNameFromAnchorTag (anchorTag: string) = | |
let indexOfDisplayText = anchorTag.IndexOf("\">") + 2 | |
let displayTextIncCloseTag = anchorTag.Substring(indexOfDisplayText, anchorTag.Length - indexOfDisplayText) | |
displayTextIncCloseTag.Remove(displayTextIncCloseTag.Length - 4, 4) // remove trailing "</a>" | |
let topTwitterClients = | |
tweets.Rows | |
|> Seq.filter (fun x -> x.CreatedDate.Year = 2014) | |
|> Seq.groupBy (fun x -> | |
match x.Source with | |
| "web" -> "web" | |
| _ when x.Source.StartsWith("<a href=") -> extractNameFromAnchorTag x.Source | |
| _ -> failwithf "unexpected source on %A" x | |
) | |
|> Seq.map (fun (group, items) -> | |
(group, Seq.length items)) | |
|> Seq.sortBy (fun (_, cnt) -> -cnt) | |
|> Seq.filter (fun (_, cnt) -> cnt > 15) // at least 15 usages | |
open FsPlot.Highcharts.Charting | |
topTwitterClients |> Chart.Pie |> Chart.WithTitle "F# Community Twitter Clients" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment