Last active
December 18, 2015 11:09
-
-
Save joshz/5774127 to your computer and use it in GitHub Desktop.
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
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) |
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
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