Skip to content

Instantly share code, notes, and snippets.

@joshz
Last active December 18, 2015 11:09
Show Gist options
  • Save joshz/5774127 to your computer and use it in GitHub Desktop.
Save joshz/5774127 to your computer and use it in GitHub Desktop.
import csv
import json
with open('metrics.json', 'r') as f:
data = json.load(f)
keys = data[0].keys()
writer = csv.DictWriter(open('metrics.csv', 'wb'), keys)
writer.writer.writerow(keys)
writer.writerows(data)
library(ggplot2)
library(scales)
dn <- read.csv('metrics.csv', sep=',')
dn$timestamp <- as.POSIXlt(dn$timestamp, origin='1970-01-01',tz='UTC',
format="%Y-%m-%d %H:%M:%S")
dn$value <- as.numeric(dn$value)
dnf <- dn[dn$network == 'SoundCloud' & dn$metric=='plays' & dn$network_id == '10531558' ,]
lm1 <- lm(as.numeric(dnf$timestamp) ~ dnf$value)
ggplot(dnf, aes(timestamp, lm1$residuals)) +
geom_point() +
facet_wrap(~network_id + network + metric) +
scale_x_datetime(breaks=date_breaks('6 hours')) +
theme(axis.text.x = element_text(angle = 90, hjust = 0)) +
ylab('residuals')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment