commit f00cfbe8f43d851b5e7a1f32336b20880e312cb6 Author: Karsten Loesing karsten.loesing@gmx.net Date: Tue Jun 19 08:56:50 2012 +0200
Fix missing values in direct users graphs.
When we didn't have a single directory mirror reporting requests from a given country, we treated these dates as "don't have any data" and interrupted drawing the line. This makes sense for times when there was a general problem with statistics gathering in the network; we wouldn't want all graphs to drop to zero in that case. But if there was no such network-wide event, we could interpret "no data for that country, but lots of data for other countries" as "no users from that country" and continue drawing the line at 0 users.
Fixes the rest of #6170. --- rserve/graphs.R | 16 ++++++++++++---- 1 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/rserve/graphs.R b/rserve/graphs.R index 30413b8..41dd22b 100644 --- a/rserve/graphs.R +++ b/rserve/graphs.R @@ -656,26 +656,34 @@ plot_direct_users <- function(start, end, country, events, path, nocutoff, dpi) { drv <- dbDriver("PostgreSQL") con <- dbConnect(drv, user = dbuser, password = dbpassword, dbname = db) - q <- paste("SELECT date, r, bwp, brn, bwn, brp, bwr, brr ", + 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 < (SELECT MAX(date) FROM user_stats) - 1 ", ""), - " AND country = '", ifelse(country == "all", "zy", country), "'", - sep = "") + " AND (country = 'zy'", ifelse(country == "all", "", + paste(" OR country = '", country, "'", sep = "")), ")", sep = "") rs <- dbSendQuery(con, q) u <- fetch(rs, n = -1) dbDisconnect(con) dbUnloadDriver(drv) + a <- u[u$country == "zy", ] + if (country != "all") + u <- u[u$country == country, ] u <- data.frame(date = u$date, users = u$r * (u$bwp * u$brn / u$bwn - u$brp) / (u$bwr * u$brn / u$bwn - u$brr) / 10) dates <- seq(from = as.Date(start, "%Y-%m-%d"), to = as.Date(end, "%Y-%m-%d"), by="1 day") - missing <- setdiff(dates, u$date) + missing <- setdiff(dates, a$date) if (length(missing) > 0) u <- rbind(u, data.frame(date = as.Date(missing, origin = "1970-01-01"), users = NA)) + missing <- setdiff(dates, u$date) + if (length(missing) > 0) + u <- rbind(u, + data.frame(date = as.Date(missing, origin = "1970-01-01"), + users = 0)) title <- ifelse(country == "all", "Directly connecting users from all countries\n", paste("Directly connecting users from ", countryname(country), "\n",