#### Fast Analytics Skeleton Script
#####################################################
#### Setup ##########################################
#####################################################
library(utilities)
csid <- 2588
con1 <- connectRootDB(con1, username = 'michael.hutchins', password = '')
con2 <- connectRootDB(con2, username = 'michael.hutchins', password = '', db = 'ndp')
dataDir <- 'data/'
figureDir <- 'figures/'
saveTag <- paste(csid, sep = '', collapse = '_')
reprocess <- FALSE
#####################################################
#### Load Data ######################################
#####################################################
data <- do.call('rbind', lapply(csid, function(x) {
loadCache(sprintf('%stest_summary_with_meta_%g.RData', dataDir, x),
fetchTestSummaryWithMeta, con1, x, rm = reprocess)
}))
callStats <- do.call('rbind', lapply(csid, function(x) {
loadCache(sprintf('%scall_stats_%s.Rdata', dataDir, x),
fetchCallStats, con1, csid, 30000, rm = reprocess)
}))
#####################################################
#### Data Processing ################################
#####################################################
baseMap <- ggGoogle(data$lon, data$lat, source = 'stamen', maptype = 'toner')
## Create call stats friendly call status
callStats$call_type <- NA
callStats$call_type[callStats$is_drop & !is.na(callStats$is_drop)] <- 'Drop'
callStats$call_type[callStats$is_block & !is.na(callStats$is_block)] <- 'Block'
callStats$call_type[!callStats$is_block & !is.na(callStats$is_block) & !callStats$is_drop & !is.na(callStats$is_drop)] <- 'Success'
callStats <- callStats[callStats$call_type %in% c('Success', 'Drop', 'Block'), ]
## Set Order
callStats$call_type <- factor(callStats$call_type, levels = c('Success', 'Block', 'Drop'))
callStats <- callStats[order(callStats$call_type), ]
#####################################################
#### Plotting #######################################
#####################################################
#### Download Time Series
df <- data[data$test_type_id == 20, ]
plt <- ggplot(df, aes(x = device_time,
y = dsd_effective_download_test_speed,
color = carrier,
fill = as.factor(device_id))) +
geom_line(alpha = 0.7) +
scale_fill_grey(start = 0, end = 0, guide = FALSE) +
scale_color_root() +
facet_wrap(~ carrier) +
theme_root() +
xlab('Device Time')
print(plt)
plotSave(sprintf('download_time_series_%s', saveTag), figureDir)
#### Upload Time Series
df <- data[data$test_type_id == 19, ]
plt <- ggplot(df, aes(x = device_time,
y = dsu_effective_upload_test_speed,
color = carrier,
fill = as.factor(device_id))) +
geom_line(alpha = 0.7) +
scale_fill_grey(start = 0, end = 0, guide = FALSE) +
scale_color_root() +
facet_wrap(~ carrier) +
theme_root() +
xlab('Device Time')
print(plt)
plotSave(sprintf('upload_time_series_%s', saveTag), figureDir)
#### Download Box Plot
plt <- ggplot(data, aes(x = carrier,
y = dsd_effective_download_test_speed,
fill = carrier)) +
geom_boxplot(notch = TRUE) +
scale_fill_root() +
theme_root() +
xlab('')
print(plt)
plotSave(sprintf('download_boxplot_%s', saveTag), figureDir)
#### Upload Box Plot
plt <- ggplot(data, aes(x = carrier,
y = dsu_effective_upload_test_speed,
fill = carrier)) +
geom_boxplot(notch = TRUE) +
scale_fill_root() +
theme_root() +
xlab('')
print(plt)
plotSave(sprintf('upload_boxplot_%s', saveTag), figureDir)
#### twilio Failure Map
df <- callStats[callStats$test_type_id %in% 16, ]
plotMap <- function(carrier) {
plt <- baseMap +
geom_point(data = df[df$carrier == carrier,],
aes(x = lon,
y = lat,
fill = call_type,
shape = call_type,
size = call_type),
alpha = 0.8) +
scale_fill_manual(values = c('Success' = '#55BB55', 'Drop' = '#BB5555', 'Block' = '#BBBB55')) +
scale_shape_manual(values = c('Success' = 21, 'Drop' = 23, 'Block' = 24)) +
scale_size_manual(values = c('Success' = 3, 'Drop' = 8, 'Block' = 8)) +
theme_root() +
xlab('') +
ylab('') +
ggtitle(carrier)
return(plt)
}
plt <- lapply(unique(callStats$carrier), plotMap)
## Combine into 1 plot
do.call('grid.arrange', plt)
## Save
plotSave(sprintf('twilio_failure_map_%s', saveTag), figureDir)
## Print Sequentially
# lapply(plt, print)
#### m2m Failure Map
df <- callStats[callStats$test_type_id %in% 23, ]
plotMap <- function(carrier) {
plt <- baseMap +
geom_point(data = df[df$carrier == carrier,],
aes(x = lon,
y = lat,
fill = call_type,
shape = call_type,
size = call_type),
alpha = 0.8) +
scale_fill_manual(values = c('Success' = '#55BB55', 'Drop' = '#BB5555', 'Block' = '#BBBB55')) +
scale_shape_manual(values = c('Success' = 21, 'Drop' = 23, 'Block' = 24)) +
scale_size_manual(values = c('Success' = 3, 'Drop' = 8, 'Block' = 8)) +
theme_root() +
xlab('') +
ylab('') +
ggtitle(carrier)
return(plt)
}
plt <- lapply(unique(callStats$carrier), plotMap)
## Combine into 1 plot
do.call('grid.arrange', plt)
## Save
plotSave(sprintf('m2m_failure_map_%s', saveTag), figureDir)
## Print Sequentially
# lapply(plt, print)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.