[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] [metrics-web/master] Merge relayflags graphs with granularities of 1 day and 1 hour.
commit 774015b6067ab319235c9b6928075433d39c6cdb
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date: Mon Jan 31 14:43:32 2011 +0100
Merge relayflags graphs with granularities of 1 day and 1 hour.
---
rserve/graphs.R | 103 ++++++++++----------
.../ernie/web/GraphParameterChecker.java | 26 ++++-
web/WEB-INF/network.jsp | 42 +-------
3 files changed, 77 insertions(+), 94 deletions(-)
diff --git a/rserve/graphs.R b/rserve/graphs.R
index e20e133..70ab86f 100644
--- a/rserve/graphs.R
+++ b/rserve/graphs.R
@@ -155,60 +155,59 @@ plot_dirbytes <- function(start, end, path, dpi) {
ggsave(filename = path, width = 8, height = 5, dpi = as.numeric(dpi))
}
-plot_relayflags <- function(start, end, flags, path, dpi) {
+plot_relayflags <- function(start, end, flags, granularity, path, dpi) {
drv <- dbDriver("PostgreSQL")
con <- dbConnect(drv, user = dbuser, password = dbpassword, dbname = db)
- columns <- paste("avg_", tolower(flags), sep = "", collapse = ", ")
- q <- paste("SELECT date, ", columns, " FROM network_size ",
- "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)),
- variable = paste("avg_", c("running", "exit", "guard", "fast",
- "stable"), sep = ""),
- value = rep(NA, 5)), networksize)
- ggplot(networksize, aes(x = as.Date(date, "%Y-%m-%d"), y = value,
- colour = variable)) + geom_line(size = 1) +
- scale_x_date(name = paste("\nThe Tor Project - ",
- "https://metrics.torproject.org/", sep = "")) +
- scale_y_continuous(name = "", limits = c(0, max(networksize$value,
- na.rm = TRUE))) +
- scale_colour_hue(name = "Relay flags", h.start = 280,
- breaks = paste("avg_", tolower(flags), sep = ""), labels = flags) +
- opts(title = "Number of relays with relay flags assigned\n")
- ggsave(filename = path, width = 8, height = 5, dpi = as.numeric(dpi))
-}
-
-plot_relayflags_hour <- function(start, end, flags, path, dpi) {
- drv <- dbDriver("PostgreSQL")
- con <- dbConnect(drv, user = dbuser, password = dbpassword, dbname = db)
- columns <- paste("avg_", tolower(flags), sep = "", collapse = ", ")
- q <- paste("SELECT validafter, ", columns, " FROM network_size_hour ",
- "WHERE DATE(validafter) >= '", start, "' 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)),
- variable = paste("avg_", c("running", "exit", "guard", "fast",
- "stable"), sep = ""),
- value = rep(NA, 5)), networksize)
- ggplot(networksize, aes(x = as.POSIXct(validafter), y = value,
- colour = variable)) + geom_line(size = 1) +
- scale_x_datetime(name = paste("\nThe Tor Project - ",
- "https://metrics.torproject.org/", sep = "")) +
- scale_y_continuous(name = "", limits = c(0, max(networksize$value,
- na.rm = TRUE))) +
- scale_colour_hue(name = "Relay flags", h.start = 280,
- breaks = paste("avg_", tolower(flags), sep = ""), labels = flags) +
- opts(title = "Number of relays with relay flags assigned\n")
+ if (granularity == 'day') {
+ columns <- paste("avg_", tolower(flags), sep = "", collapse = ", ")
+ q <- paste("SELECT date, ", columns, " FROM network_size ",
+ "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)),
+ variable = paste("avg_", c("running", "exit", "guard", "fast",
+ "stable"), sep = ""),
+ value = rep(NA, 5)), networksize)
+ ggplot(networksize, aes(x = as.Date(date, "%Y-%m-%d"), y = value,
+ colour = variable)) + geom_line(size = 1) +
+ scale_x_date(name = paste("\nThe Tor Project - ",
+ "https://metrics.torproject.org/", sep = "")) +
+ scale_y_continuous(name = "", limits = c(0, max(networksize$value,
+ na.rm = TRUE))) +
+ scale_colour_hue(name = "Relay flags", h.start = 280,
+ breaks = paste("avg_", tolower(flags), sep = ""),
+ labels = flags) +
+ opts(title = "Number of relays with relay flags assigned\n")
+ } else {
+ columns <- paste("avg_", tolower(flags), sep = "", collapse = ", ")
+ q <- paste("SELECT validafter, ", columns, " FROM network_size_hour ",
+ "WHERE DATE(validafter) >= '", start,
+ "' 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)),
+ variable = paste("avg_", c("running", "exit", "guard", "fast",
+ "stable"), sep = ""),
+ value = rep(NA, 5)), networksize)
+ ggplot(networksize, aes(x = as.POSIXct(validafter), y = value,
+ colour = variable)) + geom_line(size = 1) +
+ scale_x_datetime(name = paste("\nThe Tor Project - ",
+ "https://metrics.torproject.org/", sep = "")) +
+ scale_y_continuous(name = "", limits = c(0, max(networksize$value,
+ na.rm = TRUE))) +
+ scale_colour_hue(name = "Relay flags", h.start = 280,
+ breaks = paste("avg_", tolower(flags), sep = ""),
+ labels = flags) +
+ opts(title = "Number of relays with relay flags assigned\n")
+ }
ggsave(filename = path, width = 8, height = 5, dpi = as.numeric(dpi))
}
diff --git a/src/org/torproject/ernie/web/GraphParameterChecker.java b/src/org/torproject/ernie/web/GraphParameterChecker.java
index 27f4956..20914a8 100644
--- a/src/org/torproject/ernie/web/GraphParameterChecker.java
+++ b/src/org/torproject/ernie/web/GraphParameterChecker.java
@@ -40,9 +40,8 @@ public class GraphParameterChecker {
this.availableGraphs = new HashMap<String, String>();
this.availableGraphs.put("networksize", "start,end,filename,dpi");
- this.availableGraphs.put("relayflags", "start,end,flag,filename,dpi");
- this.availableGraphs.put("relayflags-hour",
- "start,end,flag,filename,dpi");
+ this.availableGraphs.put("relayflags", "start,end,flag,granularity,"
+ + "filename,dpi");
this.availableGraphs.put("versions", "start,end,filename,dpi");
this.availableGraphs.put("platforms", "start,end,filename,dpi");
this.availableGraphs.put("bandwidth", "start,end,filename,dpi");
@@ -62,6 +61,7 @@ public class GraphParameterChecker {
this.knownParameterValues = new HashMap<String, String>();
this.knownParameterValues.put("flag",
"Running,Exit,Guard,Fast,Stable");
+ this.knownParameterValues.put("granularity", "day,hour");
this.knownParameterValues.put("country", "all,ae,au,bh,br,ca,cn,cu,"
+ "de,dj,dz,eg,et,fr,gb,il,ir,it,iq,jo,jp,kp,kr,kw,lb,ly,ma,mm,"
+ "om,pl,ps,qa,ru,sa,sd,se,sy,tn,tm,us,uz,vn,ye");
@@ -161,6 +161,25 @@ public class GraphParameterChecker {
recognizedGraphParameters.put("flag", flagParameters);
}
+ /* Parse granularity, which can be 1 day or 1 hour, if supported by
+ * the graph type. The default is 1 day. */
+ if (supportedGraphParameters.contains("granularity")) {
+ String[] granularityParameter = (String[]) requestParameters.get(
+ "granularity");
+ List<String> knownGranularities = Arrays.asList(
+ this.knownParameterValues.get("granularity").split(","));
+ if (granularityParameter != null) {
+ if (granularityParameter.length != 1 ||
+ granularityParameter[0] == null ||
+ !knownGranularities.contains(granularityParameter[0])) {
+ return null;
+ }
+ } else {
+ granularityParameter = new String[] { "day" };
+ }
+ recognizedGraphParameters.put("granularity", granularityParameter);
+ }
+
/* Parse country codes if supported by the graph type. If no countries
* are passed, use country code "all" (all countries) as default. */
if (supportedGraphParameters.contains("country")) {
@@ -264,7 +283,6 @@ public class GraphParameterChecker {
}
}
-
/* Parse graph resolution in dpi. The default is 72. */
if (supportedGraphParameters.contains("dpi")) {
String[] dpiParameter = (String[]) requestParameters.get("dpi");
diff --git a/web/WEB-INF/network.jsp b/web/WEB-INF/network.jsp
index 25e4125..2f457d9 100644
--- a/web/WEB-INF/network.jsp
+++ b/web/WEB-INF/network.jsp
@@ -70,6 +70,10 @@ average number of relays with these flags assigned.</p>
<input type="checkbox" name="flag" value="Guard"> Guard
<input type="checkbox" name="flag" value="Stable"> Stable
</p><p>
+ Granularity:
+ <input type="radio" name="granularity" value="day"> 1 day
+ <input type="radio" name="granularity" value="hour"> 1 hour
+ </p><p>
Resolution: <select name="dpi">
<option value="72"<c:if test="${relayflags_dpi[0] eq '72'}"> selected</c:if>>Screen - 576x360</option>
<option value="150"<c:if test="${relayflags_dpi[0] eq '150'}"> selected</c:if>>Print low - 1200x750</option>
@@ -83,44 +87,6 @@ average number of relays with these flags assigned.</p>
<p><a href="csv/relayflags.csv">CSV</a> file containing all data.</p>
<br>
-<h3>Relays with Exit, Fast, Guard, and Stable flags on 1-hour detail</h3>
-<br>
-<p>The same graph on the average number of relays with flags assigned is
-available on 1-hour detail.</p>
-<a name="relayflags-hour"></a>
-<img src="relayflags-hour.png${relayflags_hour_url}"
- width="576" height="360" alt="Relay flags graph">
-<form action="network.html#relayflags-hour">
- <div class="formrow">
- <input type="hidden" name="graph" value="relayflags-hour">
- <p>
- <label>Start date (yyyy-mm-dd):</label>
- <input type="text" name="start" size="10"
- value="${relayflags_hour_start[0]}">
- <label>End date (yyyy-mm-dd):</label>
- <input type="text" name="end" size="10"
- value="${relayflags_hour_end[0]}">
- </p><p>
- <label>Relay flags: </label>
- <input type="checkbox" name="flag" value="Running"> Running
- <input type="checkbox" name="flag" value="Exit"> Exit
- <input type="checkbox" name="flag" value="Fast"> Fast
- <input type="checkbox" name="flag" value="Guard"> Guard
- <input type="checkbox" name="flag" value="Stable"> Stable
- </p><p>
- Resolution: <select name="dpi">
- <option value="72"<c:if test="${relayflags_hour_dpi[0] eq '72'}"> selected</c:if>>Screen - 576x360</option>
- <option value="150"<c:if test="${relayflags_hour_dpi[0] eq '150'}"> selected</c:if>>Print low - 1200x750</option>
- <option value="300"<c:if test="${relayflags_hour_dpi[0] eq '300'}"> selected</c:if>>Print high - 2400x1500</option>
- </select>
- </p><p>
- <input class="submit" type="submit" value="Update graph">
- </p>
- </div>
-</form>
-<p><a href="csv/relayflags-hour.csv">CSV</a> file containing all data.</p>
-<br>
-
<h3>Relays by version</h3>
<br>
<p>Relays report the Tor version that they are running to the directory