library("DBI")
library("RSQLite")
con <- dbConnect(SQLite(), "/Users/reidab/code/calagator.org/production.sqlite3")
events_query <- dbSendQuery(con, "SELECT created_at, start_time FROM events WHERE duplicate_of_id IS NULL;")
events <- dbFetch(events_query)
events$month <- substring(events$created_at, 0, 7)
events$created_at <- as.POSIXct(events$created_at, tz = "GMT")
events$start_time <- as.POSIXct(events$start_time, tz = "GMT")
How many events are on Calagator?
nrow(events)
## [1] 13231
How many events are created each month?
hist(events$created_at, "months", freq = TRUE)

…maybe without those frantic first few months?
hist(events[events$created_at >= as.POSIXct('2008-06-01'),]$created_at, "months", freq = TRUE)

…or just last year?
start_date <- as.POSIXct('2015-01-01')
end_date <- as.POSIXct('2015-12-31')
events_created_last_year <- events[events$created_at >= start_date & events$created_at <= end_date,]
events_happened_last_year <- events[events$start_time >= start_date & events$start_time <= end_date,]
hist(events_created_last_year$created_at, "months", freq = TRUE)

How has the number of events per month changed over time?
hist(events$start_time, "months", freq = TRUE)

…just last year?
hist(events_happened_last_year$start_time, "months", freq = TRUE)

When do events take place?
barplot(table(factor(weekdays(events$start_time, abbreviate = TRUE),levels=c("Sun","Mon","Tue","Wed","Thu","Fri","Sat"))))

…by hour?
barplot(table(format(events$start_time, format="'%H", tz="America/Los_Angeles")))
