R/timeseries.R

#' Plot time series of the names variable
#'
#' \code{\link{timeSeries}} is the base plotting function that is called by the
#' wrapper for each KPI.
#'
#' @param variable Variable to plot as the time series
#' @return Returns standard fast-analysis structured list
#' @name timeSeries
#' @family skeletonPlots
timeSeries <- function(variable) {

    plot <- sprintf("
plt <- ggplot(df, aes(x = device_time,
                        y = %s,
                        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)", variable)

    return(plot)

}

#' @rdname timeSeries
#' @export
downloadTimeSeries <- function() {
    save <- 'download_time_series'
    data <- pullTestSummary()
    plot <- paste("\n#### Download Time Series\n",
                  "df <- data[data$test_type_id == 20, ]",
                  timeSeries("dsd_effective_download_test_speed"),
                  saveLine(save),
                  sep = "")
    output <- list(data = data,
                   plot = plot,
                   save = save)
    return(output)
}

#' @rdname timeSeries
#' @export
uploadTimeSeries <- function() {
    save <- 'upload_time_series'
    data <- pullTestSummary()
    plot <- paste("\n#### Upload Time Series\n",
                  "df <- data[data$test_type_id == 19, ]",
                  timeSeries("dsu_effective_upload_test_speed"),
                  saveLine(save),
                  sep = "")
    output <- list(data = data,
                   plot = plot,
                   save = save)
    return(output)
}


#' @rdname timeSeries
#' @export
batteryTimeSeries <- function() {
    save <- 'battery_time_series'
    data <- pullPollEvent()
    plot <- paste("\n#### Battery Level Time Series\n",
                  "df <- poll[!is.na(poll$batt_level) & !is.na(poll$batt_temp),]",
                  timeSeries("batt_level"),
                  saveLine(save),
                  sep = "")
    output <- list(data = data,
                   plot = plot,
                   save = save)
    return(output)
}

#' @rdname timeSeries
#' @export
temperatureTimeSeries <- function() {
    save <- 'temperature_time_series'
    data <- pullPollEvent()
    plot <- paste("\n#### Temperature Time Series\n",
                  "df <- poll[!is.na(poll$batt_level) & !is.na(poll$batt_temp),]",
                  timeSeries("batt_temp"),
                  saveLine(save),
                  sep = "")
    output <- list(data = data,
                   plot = plot,
                   save = save)
    return(output)
}

#' @rdname timeSeries
#' @export
ltePowerTimeSeries <- function() {
    save <- 'lte_rsrp_time_series'
    data <- pullTestSummary()
    plot <- paste("\n#### LTE RSRP Time Series\n",
                  "df <- data[!is.na(data$avg_lte_rsrp) & !is.na(data$avg_lte_rssnr),]",
                  timeSeries("avg_lte_rsrp"),
                  saveLine(save),
                  sep = "")
    output <- list(data = data,
                   plot = plot,
                   save = save)
    return(output)
}

#' @rdname timeSeries
#' @export
lteNoiseTimeSeries <- function() {
    save <- 'lte_rssnr_time_series'
    data <- pullTestSummary()
    plot <- paste("\n#### LTE RSSNR Time Series\n",
                  "df <- data[!is.na(data$avg_lte_rsrp) & !is.na(data$avg_lte_rssnr),]",
                  timeSeries("avg_lte_rssnr"),
                  saveLine(save),
                  sep = "")
    output <- list(data = data,
                   plot = plot,
                   save = save)
    return(output)
}
mlhutchins/fast-analytics documentation built on May 23, 2019, 2:10 a.m.