commit 3d5bc767edcae80fd5759c5a349c16d207d68e7a Author: Karsten Loesing karsten.loesing@gmx.net Date: Wed Aug 29 12:30:59 2012 +0200
Stop wasting graph space for cut out days. --- rserve/graphs.R | 78 ++++++++++++++++++++++++++++-------------------------- 1 files changed, 40 insertions(+), 38 deletions(-)
diff --git a/rserve/graphs.R b/rserve/graphs.R index 4799726..83d380d 100644 --- a/rserve/graphs.R +++ b/rserve/graphs.R @@ -278,16 +278,16 @@ date_breaks <- function(days) { }
plot_networksize <- function(start, end, path, dpi) { + end <- min(end, as.character(Sys.Date() - 2)) drv <- dbDriver("PostgreSQL") con <- dbConnect(drv, user = dbuser, password = dbpassword, dbname = db) q <- paste("SELECT date, avg_running AS relays FROM network_size ", - "WHERE date >= '", start, "' AND date <= '", end, - "' AND date < current_date - 1", sep = "") + "WHERE date >= '", start, "' AND date <= '", end, "'", sep = "") rs <- dbSendQuery(con, q) relays <- fetch(rs, n = -1) q <- paste("SELECT date, avg_running AS bridges ", "FROM bridge_network_size WHERE date >= '", start, - "' AND date <= '", end, "' AND date < current_date - 1", sep = "") + "' AND date <= '", end, "'", sep = "") rs <- dbSendQuery(con, q) bridges <- fetch(rs, n = -1) dbDisconnect(con) @@ -325,11 +325,12 @@ plot_networksize <- function(start, end, path, dpi) { }
plot_cloudbridges <- function(start, end, path, dpi) { + end <- min(end, as.character(Sys.Date() - 2)) drv <- dbDriver("PostgreSQL") con <- dbConnect(drv, user = dbuser, password = dbpassword, dbname = db) q <- paste("SELECT date, avg_running_ec2 ", "FROM bridge_network_size WHERE date >= '", start, - "' AND date <= '", end, "' AND date < current_date - 1", sep = "") + "' AND date <= '", end, "'", sep = "") rs <- dbSendQuery(con, q) bridges <- fetch(rs, n = -1) dbDisconnect(con) @@ -358,17 +359,16 @@ plot_cloudbridges <- function(start, end, path, dpi) { }
plot_relaycountries <- function(start, end, country, path, dpi) { + end <- min(end, as.character(Sys.Date() - 2)) drv <- dbDriver("PostgreSQL") con <- dbConnect(drv, user = dbuser, password = dbpassword, dbname = db) if (country == "all") { q <- paste("SELECT date, avg_running AS relays FROM network_size ", - "WHERE date >= '", start, "' AND date <= '", end, - "' AND date < current_date - 1", sep = "") + "WHERE date >= '", start, "' AND date <= '", end, "'", sep = "") } else { q <- paste("SELECT date, relays FROM relay_countries ", "WHERE date >= '", start, "' AND date <= '", end, - "' AND date < current_date - 1 ", - "AND country = '", country, "'", sep = "") + "' AND country = '", country, "'", sep = "") } rs <- dbSendQuery(con, q) u <- fetch(rs, n = -1) @@ -403,11 +403,11 @@ plot_relaycountries <- function(start, end, country, path, dpi) { }
plot_versions <- function(start, end, path, dpi) { + end <- min(end, as.character(Sys.Date() - 2)) drv <- dbDriver("PostgreSQL") con <- dbConnect(drv, user = dbuser, password = dbpassword, dbname = db) q <- paste("SELECT date, version, relays FROM relay_versions ", - "WHERE date >= '", start, "' AND date <= '", end, - "' AND date < current_date - 1", sep = "") + "WHERE date >= '", start, "' AND date <= '", end, "'", sep = "") rs <- dbSendQuery(con, q) versions <- fetch(rs, n = -1) dbDisconnect(con) @@ -439,11 +439,12 @@ plot_versions <- function(start, end, path, dpi) { }
plot_platforms <- function(start, end, path, dpi) { + end <- min(end, as.character(Sys.Date() - 2)) drv <- dbDriver("PostgreSQL") con <- dbConnect(drv, user=dbuser, password=dbpassword, dbname=db) q <- paste("SELECT date, avg_linux, avg_darwin, avg_bsd, avg_windows, ", "avg_other FROM relay_platforms WHERE date >= '", start, - "' AND date <= '", end, "' AND date < current_date - 1", sep = "") + "' AND date <= '", end, "'", sep = "") rs <- dbSendQuery(con, q) platforms <- fetch(rs, n = -1) dbDisconnect(con) @@ -471,16 +472,15 @@ plot_platforms <- function(start, end, path, dpi) { }
plot_bandwidth <- function(start, end, path, dpi) { + end <- min(end, as.character(Sys.Date() - 4)) drv <- dbDriver("PostgreSQL") con <- dbConnect(drv, user = dbuser, password = dbpassword, dbname = db) q <- paste("SELECT date, bwadvertised FROM total_bandwidth ", - "WHERE date >= '", start, "' AND date <= '", end, "' ", - "AND date < current_date - 3", sep = "") + "WHERE date >= '", start, "' AND date <= '", end, "'", sep = "") rs <- dbSendQuery(con, q) bw_desc <- fetch(rs, n = -1) q <- paste("SELECT date, read, written FROM total_bwhist ", - "WHERE date >= '", start, "' AND date <= '", end, "' ", - "AND date < current_date - 3", sep = "") + "WHERE date >= '", start, "' AND date <= '", end, "'", sep = "") rs <- dbSendQuery(con, q) bw_hist <- fetch(rs, n = -1) dbDisconnect(con) @@ -509,11 +509,12 @@ plot_bandwidth <- function(start, end, path, dpi) { }
plot_bwhist_flags <- function(start, end, path, dpi) { + end <- min(end, as.character(Sys.Date() - 4)) drv <- dbDriver("PostgreSQL") con <- dbConnect(drv, user = dbuser, password = dbpassword, dbname = db) q <- paste("SELECT date, isexit, isguard, read, written ", "FROM bwhist_flags WHERE date >= '", start, "' AND date <= '", end, - "' AND date < current_date - 3", sep = "") + "'", sep = "") rs <- dbSendQuery(con, q) bw <- fetch(rs, n = -1) dbDisconnect(con) @@ -555,12 +556,12 @@ plot_bwhist_flags <- function(start, end, path, dpi) { }
plot_dirbytes <- function(start, end, path, dpi) { + end <- min(end, as.character(Sys.Date() - 4)) drv <- dbDriver("PostgreSQL") con <- dbConnect(drv, user = dbuser, password = dbpassword, dbname = db) q <- paste("SELECT date, dr, dw, brp, bwp, brd, bwd FROM user_stats ", "WHERE country = 'zy' AND bwp / bwd <= 3 AND date >= '", start, - "' AND date <= '", end, "' AND date < current_date - 3 ", - "ORDER BY date", sep = "") + "' AND date <= '", end, "' ORDER BY date", sep = "") rs <- dbSendQuery(con, q) dir <- fetch(rs, n = -1) dbDisconnect(con) @@ -591,23 +592,23 @@ plot_dirbytes <- function(start, end, path, dpi) { }
plot_relayflags <- function(start, end, flags, granularity, path, dpi) { + end <- min(end, as.character(Sys.Date() - 2)) drv <- dbDriver("PostgreSQL") con <- dbConnect(drv, user = dbuser, password = dbpassword, dbname = db) if (granularity == 'day') { columns <- paste("avg_", tolower(flags), sep = "", collapse = ", ") q <- paste("SELECT date, ", columns, " FROM network_size ", - "WHERE date >= '", start, "' AND date <= '", end, - "' AND date < current_date - 1", sep = "") + "WHERE date >= '", start, "' AND date <= '", end, "'", sep = "") rs <- dbSendQuery(con, q) networksize <- fetch(rs, n = -1) dbDisconnect(con) dbUnloadDriver(drv) networksize <- melt(networksize, id = "date") networksize <- rbind(data.frame( - date = as.Date(rep(end, 5)), + date = as.Date(end) + 1, variable = paste("avg_", c("running", "exit", "guard", "fast", "stable"), sep = ""), - value = rep(NA, 5)), networksize) + value = NA), networksize) dates <- seq(from = as.Date(start, "%Y-%m-%d"), to = as.Date(end, "%Y-%m-%d"), by="1 day") missing <- setdiff(dates, networksize$date) @@ -637,15 +638,14 @@ plot_relayflags <- function(start, end, flags, granularity, path, dpi) { columns <- paste("avg_", tolower(flags), sep = "", collapse = ", ") q <- paste("SELECT validafter, ", columns, " FROM network_size_hour ", "WHERE DATE(validafter) >= '", start, - "' AND DATE(validafter) <= '", end, "' ", - "AND DATE(validafter) < current_date - 1", sep = "") + "' AND DATE(validafter) <= '", end, "'", sep = "") rs <- dbSendQuery(con, q) networksize <- fetch(rs, n = -1) dbDisconnect(con) dbUnloadDriver(drv) networksize <- melt(networksize, id = "validafter") networksize <- rbind(data.frame( - validafter = as.POSIXct(rep(paste(end, "00:00:00"), 5)), + validafter = as.POSIXct(rep(paste(end, "23:59:00"), 5)), variable = paste("avg_", c("running", "exit", "guard", "fast", "stable"), sep = ""), value = rep(NA, 5)), networksize) @@ -666,13 +666,14 @@ plot_relayflags <- function(start, end, flags, granularity, path, dpi) {
plot_direct_users <- function(start, end, country, events, path, nocutoff, dpi) { + if (nocutoff != "off") { + end <- min(end, as.character(Sys.Date() - 4)) + } drv <- dbDriver("PostgreSQL") con <- dbConnect(drv, user = dbuser, password = dbpassword, dbname = db) q <- paste("SELECT date, r, bwp, brn, bwn, brp, bwr, brr, country ", "FROM user_stats WHERE date >= '", start, "' AND date <= '", end, - "' ", ifelse(nocutoff == "off", - " AND date < current_date - 3 ", ""), - " AND (country = 'zy'", ifelse(country == "all", "", + "' AND (country = 'zy'", ifelse(country == "all", "", paste(" OR country = '", country, "'", sep = "")), ")", sep = "") rs <- dbSendQuery(con, q) u <- fetch(rs, n = -1) @@ -743,12 +744,12 @@ plot_direct_users <- function(start, end, country, events, path, nocutoff, }
plot_bridge_users <- function(start, end, country, path, dpi) { + end <- min(end, as.character(Sys.Date() - 4)) drv <- dbDriver("PostgreSQL") con <- dbConnect(drv, user = dbuser, password = dbpassword, dbname = db) q <- paste("SELECT date, users FROM bridge_stats ", "WHERE date >= '", start, "' AND date <= '", end, "' ", - "AND date < current_date - 3", - " AND country = '", ifelse(country == "all", "zy", country), "'", + "AND country = '", ifelse(country == "all", "zy", country), "'", sep = "") rs <- dbSendQuery(con, q) bridgeusers <- fetch(rs, n = -1) @@ -782,12 +783,12 @@ plot_bridge_users <- function(start, end, country, path, dpi) { }
plot_torperf <- function(start, end, source, filesize, path, dpi) { + end <- min(end, as.character(Sys.Date() - 2)) drv <- dbDriver("PostgreSQL") con <- dbConnect(drv, user = dbuser, password = dbpassword, dbname = db) q <- paste("SELECT date, q1, md, q3 FROM torperf_stats ", "WHERE source = '", paste(source, filesize, sep = "-"), - "' AND date >= '", start, "' AND date <= '", end, - "' AND date < current_date - 1", sep = "") + "' AND date >= '", start, "' AND date <= '", end, "'", sep = "") rs <- dbSendQuery(con, q) torperf <- fetch(rs, n = -1) dbDisconnect(con) @@ -832,13 +833,13 @@ plot_torperf <- function(start, end, source, filesize, path, dpi) {
plot_torperf_failures <- function(start, end, source, filesize, path, dpi) { + end <- min(end, as.character(Sys.Date() - 2)) drv <- dbDriver("PostgreSQL") con <- dbConnect(drv, user = dbuser, password = dbpassword, dbname = db) q <- paste("SELECT date, timeouts, failures, requests ", "FROM torperf_stats WHERE source = '", paste(source, filesize, sep = "-"), - "' AND date >= '", start, "' AND date <= '", end, - "' AND date < current_date - 1", sep = "") + "' AND date >= '", start, "' AND date <= '", end, "'", sep = "") rs <- dbSendQuery(con, q) torperf <- fetch(rs, n = -1) dbDisconnect(con) @@ -886,12 +887,12 @@ plot_torperf_failures <- function(start, end, source, filesize, path, }
plot_connbidirect <- function(start, end, path, dpi) { + end <- min(end, as.character(Sys.Date() - 2)) drv <- dbDriver("PostgreSQL") con <- dbConnect(drv, user = dbuser, password = dbpassword, dbname = db) q <- paste("SELECT DATE(statsend) AS date, readnum, writenum, bothnum ", "FROM connbidirect WHERE DATE(statsend) >= '", start, - "' AND DATE(statsend) <= '", end, "' AND DATE(statsend) < ", - "current_date - 1", sep = "") + "' AND DATE(statsend) <= '", end, "'", sep = "") rs <- dbSendQuery(con, q) c <- fetch(rs, n = -1) dbDisconnect(con) @@ -987,17 +988,18 @@ plot_almost_fast_exits <- function(start, end, path, dpi) { }
plot_bandwidth_flags <- function(start, end, path, dpi) { + end <- min(end, as.character(Sys.Date() - 4)) drv <- dbDriver("PostgreSQL") con <- dbConnect(drv, user = dbuser, password = dbpassword, dbname = db) q <- paste("SELECT date, isexit, isguard, bwadvertised AS value ", "FROM bandwidth_flags WHERE date >= '", start, "' AND date <= '", - end, "' AND date < current_date - 3", sep = "") + end, "'", sep = "") rs <- dbSendQuery(con, q) bw_desc <- fetch(rs, n = -1) q <- paste("SELECT date, isexit, isguard, ", "(read + written) / (2 * 86400) ", "AS value FROM bwhist_flags WHERE date >= '", start, - "' AND date <= '", end, "' AND date < current_date - 3", sep = "") + "' AND date <= '", end, "'", sep = "") rs <- dbSendQuery(con, q) bw_hist <- fetch(rs, n = -1) dbDisconnect(con)
tor-commits@lists.torproject.org