[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] [ernie/master 2/2] Generate graphs in subdirectories of website/graphs/.



Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date: Fri, 19 Feb 2010 19:35:34 +0100
Subject: Generate graphs in subdirectories of website/graphs/.
Commit: d6e0fc9445bee7dd9f52bd05130c63933d485448

---
 R/bridge-stats.R    |    4 +-
 R/consensus-stats.R |   61 +++++++++++++++++++++++++++---------------------
 R/dirreq-stats.R    |   63 +++++++++++++++++++++++++++-----------------------
 R/torperf.R         |    4 +-
 4 files changed, 72 insertions(+), 60 deletions(-)

diff --git a/R/bridge-stats.R b/R/bridge-stats.R
index f8fe32f..f2b6672 100644
--- a/R/bridge-stats.R
+++ b/R/bridge-stats.R
@@ -13,8 +13,8 @@ plot_bridges <- function(filename, title, limits, code) {
     scale_y_continuous(name = "", limits = c(0, max(bridge[[code]],
     na.rm = TRUE))) +
     opts(title = title)
-  ggsave(filename = paste("website/graphs/", filename, sep = ""),
-    width = 8, height = 5, dpi = 72)
+  ggsave(filename = paste("website/graphs/bridge-users/", filename,
+    sep = ""), width = 8, height = 5, dpi = 72)
 }
 
 plot_pastdays <- function(days, countries) {
diff --git a/R/consensus-stats.R b/R/consensus-stats.R
index 8721436..6488d6b 100644
--- a/R/consensus-stats.R
+++ b/R/consensus-stats.R
@@ -10,7 +10,7 @@ write.csv(data.frame(date = consensuses$date,
   all = consensuses$running, exit = consensuses$exit),
   "website/csv/exit.csv", quote = FALSE, row.names = FALSE)
 
-plot_consensus <- function(filename, title, limits, rows, breaks,
+plot_consensus <- function(directory, filename, title, limits, rows, breaks,
     labels) {
   c <- melt(consensuses[rows], id = "date")
   ggplot(c, aes(x = as.Date(date, "%Y-%m-%d"), y = value,
@@ -22,55 +22,56 @@ plot_consensus <- function(filename, title, limits, rows, breaks,
     limits = c(0, max(c$value, na.rm = TRUE))) +
     scale_colour_hue("", breaks = breaks, labels = labels) +
     opts(title = title)
-  ggsave(filename = paste("website/graphs/", filename, sep = ""),
+  ggsave(filename = paste(directory, filename, sep = ""),
     width = 8, height = 5, dpi = 72)
 }
 
-plot_pastdays <- function(filenamePart, titlePart, days, rows, breaks,
-    labels) {
+plot_pastdays <- function(directory, filenamePart, titlePart, days, rows,
+    breaks, labels) {
   for (day in days) {
     end <- seq(from = Sys.Date(), length = 2, by = "-1 day")[2]
     start <- seq(from = end, length = 2, by = paste("-", day, " days",
       sep = ""))[2]
-    plot_consensus(paste(filenamePart, "-", day, "d.png", sep = ""),
-      paste(titlePart, "(past", day, "days)\n"), c(start, end),
+    plot_consensus(directory, paste(filenamePart, "-", day, "d.png",
+      sep = ""), paste(titlePart, "(past", day, "days)\n"), c(start, end),
       rows, breaks, labels)
   }
 }
 
-plot_years <- function(filenamePart, titlePart, years, rows, breaks,
-    labels) {
+plot_years <- function(directory, filenamePart, titlePart, years, rows,
+    breaks, labels) {
   for (year in years) {
-    plot_consensus(paste(filenamePart, "-", year, ".png", sep = ""),
-      paste(titlePart, " (", year, ")\n", sep = ""),
+    plot_consensus(directory, paste(filenamePart, "-", year, ".png",
+      sep = ""), paste(titlePart, " (", year, ")\n", sep = ""),
       as.Date(c(paste(year, "-01-01", sep = ""),
       paste(year, "-12-31", sep = ""))), rows, breaks, labels)
   }
 }
 
-plot_quarters <- function(filenamePart, titlePart, years, quarters, rows,
-    breaks, labels) {
+plot_quarters <- function(directory, filenamePart, titlePart, years,
+    quarters, rows, breaks, labels) {
   for (year in years) {
     for (quarter in quarters) {
       start <- as.Date(paste(year, "-", (quarter - 1) * 3 + 1, "-01",
         sep = ""))
       end <- seq(seq(start, length = 2, by = "3 months")[2], length = 2,
         by = "-1 day")[2]
-      plot_consensus(paste(filenamePart, "-", year, "-q", quarter, ".png",
+      plot_consensus(directory, paste(filenamePart, "-", year, "-q",
+        quarter, ".png",
         sep = ""), paste(titlePart, " (Q", quarter, " ", year, ")\n",
         sep = ""), c(start, end), rows, breaks, labels)
     }
   }
 }
 
-plot_months <- function(filenamePart, titlePart, years, months, rows,
-    breaks, labels) {
+plot_months <- function(directory, filenamePart, titlePart, years, months,
+    rows, breaks, labels) {
   for (year in years) {
     for (month in months) {
       start <- as.Date(paste(year, "-", month, "-01", sep = ""))
       end <- seq(seq(start, length = 2, by = "1 month")[2], length = 2,
         by = "-1 day")[2]
-      plot_consensus(paste(filenamePart, "-", year, "-",
+      plot_consensus(directory, paste(filenamePart, "-", year, "-",
         format(start, "%m"), ".png", sep = ""), paste(titlePart,
         " (", format(start, "%B"), " ", year, ")\n", sep = ""),
         c(start, end), rows, breaks, labels)
@@ -78,25 +79,31 @@ plot_months <- function(filenamePart, titlePart, years, months, rows,
   }
 }
 
-plot_all <- function(filenamePart, titlePart, rows, breaks, labels) {
-  plot_consensus(paste(filenamePart, "-all.png", sep = ""),
+plot_all <- function(directory, filenamePart, titlePart, rows, breaks,
+    labels) {
+  plot_consensus(directory, paste(filenamePart, "-all.png", sep = ""),
     paste(titlePart, " (all data)\n", sep = ""),
     as.Date(c(min(consensuses$date), max(consensuses$date))), rows,
     breaks, labels)
 }
 
 # TODO these need to be updated manually
-plot_current <- function(filenamePart, titlePart, rows, breaks, labels) {
-  plot_pastdays(filenamePart, titlePart, c(30, 90, 180), rows, breaks,
+plot_current <- function(directory, filenamePart, titlePart, rows, breaks,
+    labels) {
+  plot_pastdays(directory, filenamePart, titlePart, c(30, 90, 180), rows,
+    breaks, labels)
+  plot_years(directory, filenamePart, titlePart, "2010", rows, breaks,
+    labels)
+  plot_quarters(directory, filenamePart, titlePart, "2010", 1, rows,
+    breaks, labels)
+  plot_months(directory, filenamePart, titlePart, "2010", 2, rows, breaks,
     labels)
-  plot_years(filenamePart, titlePart, "2010", rows, breaks, labels)
-  plot_quarters(filenamePart, titlePart, "2010", 1, rows, breaks, labels)
-  plot_months(filenamePart, titlePart, "2010", 2, rows, breaks, labels)
-  plot_all(filenamePart, titlePart, rows, breaks, labels)
+  plot_all(directory, filenamePart, titlePart, rows, breaks, labels)
 }
 
-plot_current("networksize", "Number of relays and bridges", c(1, 5, 7),
+plot_current("website/graphs/networksize/", "networksize",
+  "Number of relays and bridges", c(1, 5, 7),
   c("running", "brunning"), c("Relays", "Bridges"))
-plot_current("exit", "Number of exit relays", c(1, 5, 2),
-  c("running", "exit"), c("All relays", "Exit relays"))
+plot_current("website/graphs/exit/", "exit", "Number of exit relays",
+  c(1, 5, 2), c("running", "exit"), c("All relays", "Exit relays"))
 
diff --git a/R/dirreq-stats.R b/R/dirreq-stats.R
index c525f14..3bd2222 100644
--- a/R/dirreq-stats.R
+++ b/R/dirreq-stats.R
@@ -15,7 +15,7 @@ write.csv(moria1, "website/csv/new-users.csv", quote = FALSE,
 write.csv(trusted, "website/csv/recurring-users.csv", quote = FALSE,
   row.names = FALSE)
 
-plot_dirreq <- function(filename, title, limits, data, code) {
+plot_dirreq <- function(directory, filename, title, limits, data, code) {
   c <- data.frame(date = data$date, users = data[[code]])
   ggplot(c, aes(x = as.Date(date, "%Y-%m-%d"), y = users)) +
     geom_line() +
@@ -25,11 +25,11 @@ plot_dirreq <- function(filename, title, limits, data, code) {
     scale_y_continuous(name = "",
     limits = c(0, max(c$users, na.rm = TRUE))) +
     opts(title = title)
-  ggsave(filename = paste("website/graphs/", filename, sep = ""),
+  ggsave(filename = paste(directory, filename, sep = ""),
     width = 8, height = 5, dpi = 72)
 }
 
-plot_pastdays <- function(filenamePart, titlePart, days, data,
+plot_pastdays <- function(directory, filenamePart, titlePart, days, data,
     countries) {
   for (day in days) {
     for (country in 1:length(countries$code)) {
@@ -39,29 +39,30 @@ plot_pastdays <- function(filenamePart, titlePart, days, data,
       end <- seq(from = Sys.Date(), length = 2, by = "-1 day")[2]
       start <- seq(from = end, length = 2, by = paste("-", day, " days",
         sep = ""))[2]
-      plot_dirreq(paste(filename, filenamePart, "-", day, "d.png",
-        sep = ""), paste(titlePart, people, "Tor users (past", day,
-        "days)\n"), c(start, end), data, code)
+      plot_dirreq(directory, paste(filename, filenamePart, "-", day,
+        "d.png", sep = ""), paste(titlePart, people, "Tor users (past",
+        day, "days)\n"), c(start, end), data, code)
     }
   }
 }
 
-plot_years <- function(filenamePart, titlePart, years, data, countries) {
+plot_years <- function(directory, filenamePart, titlePart, years, data,
+    countries) {
   for (year in years) {
     for (country in 1:length(countries$code)) {
       code <- countries[country, 1]
       people <- countries[country, 2]
       filename <- countries[country, 3]
-      plot_dirreq(paste(filename, filenamePart, "-", year, ".png",
-        sep = ""), paste(titlePart, " ", people, " Tor users (", year,
-        ")\n", sep = ""), as.Date(c(paste(year, "-01-01", sep = ""),
+      plot_dirreq(directory, paste(filename, filenamePart, "-", year,
+        ".png", sep = ""), paste(titlePart, " ", people, " Tor users (",
+        year, ")\n", sep = ""), as.Date(c(paste(year, "-01-01", sep = ""),
         paste(year, "-12-31", sep = ""))), data, code)
     }
   }
 }
 
-plot_quarters <- function(filenamePart, titlePart, years, quarters, data,
-    countries) {
+plot_quarters <- function(directory, filenamePart, titlePart, years,
+    quarters, data, countries) {
   for (year in years) {
     for (quarter in quarters) {
       for (country in 1:length(countries$code)) {
@@ -72,8 +73,8 @@ plot_quarters <- function(filenamePart, titlePart, years, quarters, data,
           sep = ""))
         end <- seq(seq(start, length = 2, by = "3 months")[2], length = 2,
           by = "-1 day")[2]
-        plot_dirreq(paste(filename, filenamePart, "-", year, "-q",
-          quarter, ".png", sep = ""), paste(titlePart, " ", people,
+        plot_dirreq(directory, paste(filename, filenamePart, "-", year,
+          "-q", quarter, ".png", sep = ""), paste(titlePart, " ", people,
           " Tor users (Q", quarter, " ", year, ")\n", sep = ""),
           c(start, end), data, code)
       }
@@ -81,8 +82,8 @@ plot_quarters <- function(filenamePart, titlePart, years, quarters, data,
   }
 }
 
-plot_months <- function(filenamePart, titlePart, years, months, data,
-    countries) {
+plot_months <- function(directory, filenamePart, titlePart, years, months,
+    data, countries) {
   for (year in years) {
     for (month in months) {
       for (country in 1:length(countries$code)) {
@@ -92,21 +93,25 @@ plot_months <- function(filenamePart, titlePart, years, months, data,
         start <- as.Date(paste(year, "-", month, "-01", sep = ""))
         end <- seq(seq(start, length = 2, by = "1 month")[2], length = 2,
           by = "-1 day")[2]
-        plot_dirreq(paste(filename, filenamePart, "-", year, "-",
-          format(start, "%m"), ".png", sep = ""), paste(titlePart, " ",
-          people, " Tor users (", format(start, "%B"), " ", year, ")\n",
-          sep = ""), c(start, end), data, code)
+        plot_dirreq(directory, paste(filename, filenamePart, "-", year,
+          "-", format(start, "%m"), ".png", sep = ""), paste(titlePart,
+          " ", people, " Tor users (", format(start, "%B"), " ", year,
+          ")\n", sep = ""), c(start, end), data, code)
       }
     }
   }
 }
 
 # TODO these need to be updated manually
-plot_current <- function(filenamePart, titlePart, data, countries) {
-  plot_pastdays(filenamePart, titlePart, c(30, 90, 180), data, countries)
-  plot_years(filenamePart, titlePart, "2010", data, countries)
-  plot_quarters(filenamePart, titlePart, "2010", 1, data, countries)
-  plot_months(filenamePart, titlePart, "2010", 1:2, data, countries)
+plot_current <- function(directory, filenamePart, titlePart, data,
+    countries) {
+  plot_pastdays(directory, filenamePart, titlePart, c(30, 90, 180), data,
+    countries)
+  plot_years(directory, filenamePart, titlePart, "2010", data, countries)
+  plot_quarters(directory, filenamePart, titlePart, "2010", 1, data,
+    countries)
+  plot_months(directory, filenamePart, titlePart, "2010", 1:2, data,
+    countries)
 }
 
 countries <- data.frame(code = c("bh", "cn", "cu", "et", "ir", "mm", "sa",
@@ -117,8 +122,8 @@ countries <- data.frame(code = c("bh", "cn", "cu", "et", "ir", "mm", "sa",
   "syria", "tunisia", "turkmenistan", "uzbekistan", "vietnam", "yemen"),
   stringsAsFactors = FALSE)
 
-plot_current("-new", "New or returning, directly connecting", moria1,
-  countries)
-plot_current("-direct", "Recurring, directly connecting", trusted,
-  countries)
+plot_current("website/graphs/new-users/", "-new",
+  "New or returning, directly connecting", moria1, countries)
+plot_current("website/graphs/direct-users/", "-direct",
+  "Recurring, directly connecting", trusted, countries)
 
diff --git a/R/torperf.R b/R/torperf.R
index 79ff1ac..43c0b4c 100644
--- a/R/torperf.R
+++ b/R/torperf.R
@@ -51,8 +51,8 @@ for (intervalInd in 1:length(intervals)) {
   for (sizeInd in 1:length(sizes)) {
     size <- sizes[sizeInd]
     sizePr <- sizePrint[sizeInd]
-    png(paste("website/graphs/torperf-", size, "-", interval, ".png",
-        sep = ""), width=600, height=height)
+    png(paste("website/graphs/torperf/torperf-", size, "-", interval,
+        ".png", sep = ""), width=600, height=height)
     par(mfrow=c(length(sources), 1))
     par(mar=c(4.3,3.1,2.1,0.1))
     maxY <- max(na.omit(subset(t, source %in% paste(sources, size,
-- 
1.6.5