commit 3c63bb7dd8d75e7fa9a8805980117936bf93583f Author: Karsten Loesing karsten.loesing@gmx.net Date: Thu Jun 14 09:00:47 2012 +0200
Add Tor Cloud bridges graph and .csv export. --- etc/web.xml | 4 ++ rserve/csv.R | 12 +++++++ rserve/graphs.R | 33 ++++++++++++++++++++ src/org/torproject/ernie/web/GraphDataServlet.java | 1 + src/org/torproject/ernie/web/RObjectGenerator.java | 2 + web/WEB-INF/network.jsp | 32 +++++++++++++++++++ 6 files changed, 84 insertions(+), 0 deletions(-)
diff --git a/etc/web.xml b/etc/web.xml index a5bd7be..24f3ba2 100644 --- a/etc/web.xml +++ b/etc/web.xml @@ -163,6 +163,10 @@ </servlet-mapping> <servlet-mapping> <servlet-name>GraphImage</servlet-name> + <url-pattern>/cloudbridges.png</url-pattern> + </servlet-mapping> + <servlet-mapping> + <servlet-name>GraphImage</servlet-name> <url-pattern>/relaycountries.png</url-pattern> </servlet-mapping> <servlet-mapping> diff --git a/rserve/csv.R b/rserve/csv.R index 596d305..6d76bf7 100644 --- a/rserve/csv.R +++ b/rserve/csv.R @@ -15,6 +15,18 @@ export_networksize <- function(path) { write.csv(networksize, path, quote = FALSE, row.names = FALSE) }
+export_cloudbridges <- function(path) { + drv <- dbDriver("PostgreSQL") + con <- dbConnect(drv, user = dbuser, password = dbpassword, dbname = db) + q <- paste("SELECT date, avg_running_ec2 AS cloudbridges", + "FROM bridge_network_size ORDER BY date") + rs <- dbSendQuery(con, q) + cloudbridges <- fetch(rs, n = -1) + dbDisconnect(con) + dbUnloadDriver(drv) + write.csv(cloudbridges, path, quote = FALSE, row.names = FALSE) +} + export_relaycountries <- function(path) { drv <- dbDriver("PostgreSQL") con <- dbConnect(drv, user = dbuser, password = dbpassword, dbname = db) diff --git a/rserve/graphs.R b/rserve/graphs.R index 61c12f7..f5575c3 100644 --- a/rserve/graphs.R +++ b/rserve/graphs.R @@ -324,6 +324,39 @@ plot_networksize <- function(start, end, path, dpi) { ggsave(filename = path, width = 8, height = 5, dpi = as.numeric(dpi)) }
+plot_cloudbridges <- function(start, end, path, dpi) { + 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, "'", sep = "") + rs <- dbSendQuery(con, q) + bridges <- fetch(rs, n = -1) + dbDisconnect(con) + dbUnloadDriver(drv) + dates <- seq(from = as.Date(start, "%Y-%m-%d"), + to = as.Date(end, "%Y-%m-%d"), by="1 day") + missing <- setdiff(dates, bridges$date) + if (length(missing) > 0) + bridges <- rbind(bridges, + data.frame(date = as.Date(missing, origin = "1970-01-01"), + avg_running_ec2 = NA)) + date_breaks <- date_breaks( + as.numeric(max(as.Date(bridges$date, "%Y-%m-%d")) - + min(as.Date(bridges$date, "%Y-%m-%d")))) + ggplot(bridges, aes(x = as.Date(date, "%Y-%m-%d"), + y = avg_running_ec2)) + + geom_line(size = 1, colour = "green3") + + scale_x_date(name = paste("\nThe Tor Project - ", + "https://metrics.torproject.org/", sep = ""), + format = date_breaks$format, major = date_breaks$major, + minor = date_breaks$minor) + + scale_y_continuous(name = "", limits = c(0, + max(bridges$avg_running_ec2, na.rm = TRUE))) + + opts(title = "Number of Tor Cloud bridges\n") + ggsave(filename = path, width = 8, height = 5, dpi = as.numeric(dpi)) +} + plot_relaycountries <- function(start, end, country, path, dpi) { drv <- dbDriver("PostgreSQL") con <- dbConnect(drv, user = dbuser, password = dbpassword, dbname = db) diff --git a/src/org/torproject/ernie/web/GraphDataServlet.java b/src/org/torproject/ernie/web/GraphDataServlet.java index b335994..209aefe 100644 --- a/src/org/torproject/ernie/web/GraphDataServlet.java +++ b/src/org/torproject/ernie/web/GraphDataServlet.java @@ -53,6 +53,7 @@ public class GraphDataServlet extends HttpServlet { this.availableGraphDataFiles = new TreeMap<String, String>(); this.availableGraphDataFiles.put("relays", "networksize"); this.availableGraphDataFiles.put("bridges", "networksize"); + this.availableGraphDataFiles.put("cloudbridges", "cloudbridges"); this.availableGraphDataFiles.put("relays-by-country", "relaycountries"); this.availableGraphDataFiles.put("relays-by-flags", "relayflags"); diff --git a/src/org/torproject/ernie/web/RObjectGenerator.java b/src/org/torproject/ernie/web/RObjectGenerator.java index 8350de9..993bc59 100644 --- a/src/org/torproject/ernie/web/RObjectGenerator.java +++ b/src/org/torproject/ernie/web/RObjectGenerator.java @@ -57,6 +57,7 @@ public class RObjectGenerator implements ServletContextListener { this.availableCsvFiles.add("bridge-users"); this.availableCsvFiles.add("bwhist-flags"); this.availableCsvFiles.add("connbidirect"); + this.availableCsvFiles.add("cloudbridges"); this.availableCsvFiles.add("direct-users"); this.availableCsvFiles.add("dirreq-stats"); this.availableCsvFiles.add("dirbytes"); @@ -80,6 +81,7 @@ public class RObjectGenerator implements ServletContextListener {
this.availableGraphs = new HashMap<String, String>(); this.availableGraphs.put("networksize", "start,end,filename,dpi"); + this.availableGraphs.put("cloudbridges", "start,end,filename,dpi"); this.availableGraphs.put("relaycountries", "start,end,country,filename,dpi"); this.availableGraphs.put("relayflags", "start,end,flag,granularity," diff --git a/web/WEB-INF/network.jsp b/web/WEB-INF/network.jsp index 73205e0..fa7732f 100644 --- a/web/WEB-INF/network.jsp +++ b/web/WEB-INF/network.jsp @@ -197,6 +197,38 @@ platform.</p> <p><a href="csv/platforms.csv">CSV</a> file containing all data.</p> <br>
+<a name="cloudbridges"></a> +<h3><a href="#cloudbridges" class="anchor">Tor Cloud bridges</a></h3> +<br> +<p>The following graph shows the average daily number of +<a href="http://cloud.torproject.org/">Tor Cloud</a> bridges in the +network.</p> +<img src="cloudbridges.png${cloudbridges_url}" + width="576" height="360" alt="Tor Cloud bridges graph"> +<form action="network.html#cloudbridges"> + <div class="formrow"> + <input type="hidden" name="graph" value="cloudbridges"> + <p> + <label>Start date (yyyy-mm-dd):</label> + <input type="text" name="start" size="10" + value="<c:choose><c:when test="${fn:length(cloudbridges_start) == 0}">${default_start_date}</c:when><c:otherwise>${cloudbridges_start[0]}</c:otherwise></c:choose>"> + <label>End date (yyyy-mm-dd):</label> + <input type="text" name="end" size="10" + value="<c:choose><c:when test="${fn:length(cloudbridges_end) == 0}">${default_end_date}</c:when><c:otherwise>${cloudbridges_end[0]}</c:otherwise></c:choose>"> + </p><p> + Resolution: <select name="dpi"> + <option value="72"<c:if test="${cloudbridges_dpi[0] eq '72'}"> selected</c:if>>Screen - 576x360</option> + <option value="150"<c:if test="${cloudbridges_dpi[0] eq '150'}"> selected</c:if>>Print low - 1200x750</option> + <option value="300"<c:if test="${cloudbridges_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/cloudbridges.csv">CSV</a> file containing all data.</p> +<br> + <a name="bandwidth"></a> <h3><a href="#bandwidth" class="anchor">Total relay bandwidth in the network</a></h3>
tor-commits@lists.torproject.org