Created
January 8, 2015 13:41
-
-
Save evelinag/d636af7e9df6ec2304f9 to your computer and use it in GitHub Desktop.
Number of unique people tweeting about F# per day over 2013 and 2014
This file contains hidden or 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 @"packages/FSharp.Data.2.0.14/lib/net40/FSharp.Data.dll" | |
#load @"packages/Deedle.1.0.6/Deedle.fsx" | |
#load @"packages/FSharp.Charting.0.90.9/FSharp.Charting.fsx" | |
open FSharp.Data | |
open Deedle | |
open FSharp.Charting | |
type Tweets = CsvProvider<"fsharp_2013-2014.csv"> | |
let tweets' = Tweets.Load("fsharp_2013-2014.csv") | |
// Get a list of people that tweeted each day | |
let tweetersByDate = | |
tweets'.Rows | |
|> Seq.map (fun tweet -> tweet.CreatedDate, tweet.FromUserScreenName) | |
|> Seq.groupBy (fun (date, author) -> | |
System.DateTime(date.Year, date.Month, date.Day)) | |
|> Seq.sortBy fst | |
|> Seq.map (fun (dt, ts) -> | |
let tweeters = ts |> Seq.map (fun (d, author) -> author) | |
dt, tweeters) | |
// Count number of unique people that tweeted each day | |
let countsByDay = | |
tweetersByDate | |
|> Seq.map (fun (dt, tweeters) -> dt, tweeters |> set |> Set.count |> float) | |
|> Series.ofObservations | |
// Moving average for a smoothed estimate | |
let movingAverage k = Stats.movingMean k countsByDay | |
// Plots | |
[ Chart.Point(countsByDay |> Series.observations); | |
Chart.Line(movingAverage 30 |> Series.observations) |> Chart.WithStyling(BorderWidth=5)] | |
|> Chart.Combine | |
|> Chart.WithYAxis(Title="Number of people tweeting about F# per day") | |
// How did the average number of people tweeting about F# change between years? | |
let avgByYear = | |
countsByDay | |
|> Series.groupBy (fun key _ -> key.Year) | |
|> Series.map (fun year xs -> Stats.mean xs) | |
printfn "%A" avgByYear |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment