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

[tor-commits] [metrics-web/master] Move available R object lists to RObjectGenerator.



commit e33d4702e2d1c33a9e6c91db40bedc393c3bc7c9
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date:   Tue Mar 20 14:17:21 2012 +0100

    Move available R object lists to RObjectGenerator.
---
 src/org/torproject/ernie/web/CsvServlet.java       |   22 +-------
 .../ernie/web/GraphParameterChecker.java           |   26 +-------
 src/org/torproject/ernie/web/RObjectGenerator.java |   61 ++++++++++++++++++++
 .../ernie/web/TableParameterChecker.java           |    6 +-
 4 files changed, 69 insertions(+), 46 deletions(-)

diff --git a/src/org/torproject/ernie/web/CsvServlet.java b/src/org/torproject/ernie/web/CsvServlet.java
index 4f60eaf..1e9fbf8 100644
--- a/src/org/torproject/ernie/web/CsvServlet.java
+++ b/src/org/torproject/ernie/web/CsvServlet.java
@@ -33,31 +33,11 @@ public class CsvServlet extends HttpServlet {
     /* Initialize logger. */
     this.logger = Logger.getLogger(CsvServlet.class.toString());
 
-    /* Initialize map of available CSV files. */
-    this.availableCsvFiles = new TreeSet<String>();
-    this.availableCsvFiles.add("bandwidth");
-    this.availableCsvFiles.add("bridge-users");
-    this.availableCsvFiles.add("bwhist-flags");
-    this.availableCsvFiles.add("connbidirect");
-    this.availableCsvFiles.add("direct-users");
-    this.availableCsvFiles.add("dirreq-stats");
-    this.availableCsvFiles.add("dirbytes");
-    this.availableCsvFiles.add("gettor");
-    this.availableCsvFiles.add("monthly-users-average");
-    this.availableCsvFiles.add("monthly-users-peak");
-    this.availableCsvFiles.add("networksize");
-    this.availableCsvFiles.add("platforms");
-    this.availableCsvFiles.add("relaycountries");
-    this.availableCsvFiles.add("relayflags");
-    this.availableCsvFiles.add("relayflags-hour");
-    this.availableCsvFiles.add("torperf");
-    this.availableCsvFiles.add("torperf-failures");
-    this.availableCsvFiles.add("versions");
-
     /* Get a reference to the R object generator that we need to generate
      * CSV files. */
     this.rObjectGenerator = (RObjectGenerator) getServletContext().
         getAttribute("RObjectGenerator");
+    this.availableCsvFiles = rObjectGenerator.getAvailableCsvFiles();
   }
 
   public void doGet(HttpServletRequest request,
diff --git a/src/org/torproject/ernie/web/GraphParameterChecker.java b/src/org/torproject/ernie/web/GraphParameterChecker.java
index 96efed0..19a4081 100644
--- a/src/org/torproject/ernie/web/GraphParameterChecker.java
+++ b/src/org/torproject/ernie/web/GraphParameterChecker.java
@@ -47,28 +47,6 @@ public class GraphParameterChecker {
     this.dateFormat = new SimpleDateFormat("yyyy-MM-dd");
     this.dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
 
-    this.availableGraphs = new HashMap<String, String>();
-    this.availableGraphs.put("networksize", "start,end,filename,dpi");
-    this.availableGraphs.put("relaycountries",
-        "start,end,country,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");
-    this.availableGraphs.put("bwhist-flags", "start,end,filename,dpi");
-    this.availableGraphs.put("dirbytes", "start,end,filename,dpi");
-    this.availableGraphs.put("direct-users",
-        "start,end,country,events,filename,nocutoff,dpi");
-    this.availableGraphs.put("bridge-users",
-         "start,end,country,filename,dpi");
-    this.availableGraphs.put("gettor", "start,end,language,filename,dpi");
-    this.availableGraphs.put("torperf",
-         "start,end,source,filesize,filename,dpi");
-    this.availableGraphs.put("torperf-failures",
-         "start,end,source,filesize,filename,dpi");
-    this.availableGraphs.put("connbidirect", "start,end,filename,dpi");
-
     this.knownParameterValues = new HashMap<String, String>();
     this.knownParameterValues.put("flag",
         "Running,Exit,Guard,Fast,Stable");
@@ -86,6 +64,10 @@ public class GraphParameterChecker {
     this.knownParameterValues.put("dpi", "72,150,300");
   }
 
+  public void setAvailableGraphs(Map<String, String> availableGraphs) {
+    this.availableGraphs = availableGraphs;
+  }
+
   /**
    * Checks request parameters for the given graph type and returns a map
    * of recognized parameters, or null if the graph type doesn't exist or
diff --git a/src/org/torproject/ernie/web/RObjectGenerator.java b/src/org/torproject/ernie/web/RObjectGenerator.java
index 2fb4477..da79d43 100644
--- a/src/org/torproject/ernie/web/RObjectGenerator.java
+++ b/src/org/torproject/ernie/web/RObjectGenerator.java
@@ -14,6 +14,8 @@ import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.SortedSet;
+import java.util.TreeSet;
 
 import javax.servlet.ServletContext;
 import javax.servlet.ServletContextEvent;
@@ -33,6 +35,10 @@ public class RObjectGenerator implements ServletContextListener {
   private String cachedGraphsDirectory;
   private long maxCacheAge;
 
+  private SortedSet<String> availableCsvFiles;
+  private Map<String, String> availableTables;
+  private Map<String, String> availableGraphs;
+
   public void contextInitialized(ServletContextEvent event) {
 
     /* Initialize using context parameters. */
@@ -45,6 +51,57 @@ public class RObjectGenerator implements ServletContextListener {
     this.cachedGraphsDirectory = servletContext.getInitParameter(
         "cachedGraphsDir");
 
+    /* Initialize map of available CSV files. */
+    this.availableCsvFiles = new TreeSet<String>();
+    this.availableCsvFiles.add("bandwidth");
+    this.availableCsvFiles.add("bridge-users");
+    this.availableCsvFiles.add("bwhist-flags");
+    this.availableCsvFiles.add("connbidirect");
+    this.availableCsvFiles.add("direct-users");
+    this.availableCsvFiles.add("dirreq-stats");
+    this.availableCsvFiles.add("dirbytes");
+    this.availableCsvFiles.add("gettor");
+    this.availableCsvFiles.add("monthly-users-average");
+    this.availableCsvFiles.add("monthly-users-peak");
+    this.availableCsvFiles.add("networksize");
+    this.availableCsvFiles.add("platforms");
+    this.availableCsvFiles.add("relaycountries");
+    this.availableCsvFiles.add("relayflags");
+    this.availableCsvFiles.add("relayflags-hour");
+    this.availableCsvFiles.add("torperf");
+    this.availableCsvFiles.add("torperf-failures");
+    this.availableCsvFiles.add("versions");
+
+    this.availableTables = new HashMap<String, String>();
+    this.availableTables.put("direct-users", "start,end,filename");
+    this.availableTables.put("censorship-events", "start,end,filename");
+    TableParameterChecker.getInstance().setAvailableTables(
+        availableTables);
+
+    this.availableGraphs = new HashMap<String, String>();
+    this.availableGraphs.put("networksize", "start,end,filename,dpi");
+    this.availableGraphs.put("relaycountries",
+        "start,end,country,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");
+    this.availableGraphs.put("bwhist-flags", "start,end,filename,dpi");
+    this.availableGraphs.put("dirbytes", "start,end,filename,dpi");
+    this.availableGraphs.put("direct-users",
+        "start,end,country,events,filename,nocutoff,dpi");
+    this.availableGraphs.put("bridge-users",
+         "start,end,country,filename,dpi");
+    this.availableGraphs.put("gettor", "start,end,language,filename,dpi");
+    this.availableGraphs.put("torperf",
+         "start,end,source,filesize,filename,dpi");
+    this.availableGraphs.put("torperf-failures",
+         "start,end,source,filesize,filename,dpi");
+    this.availableGraphs.put("connbidirect", "start,end,filename,dpi");
+    GraphParameterChecker.getInstance().setAvailableGraphs(
+        availableGraphs);
+
     /* Register ourself, so that servlets can use us. */
     servletContext.setAttribute("RObjectGenerator", this);
   }
@@ -141,6 +198,10 @@ public class RObjectGenerator implements ServletContextListener {
     return result;
   }
 
+  public SortedSet<String> getAvailableCsvFiles() {
+    return this.availableCsvFiles;
+  }
+
   public String generateCsv(String requestedCsvFile) {
     /* Prepare filename and R query string. */
     String rQuery = "export_" + requestedCsvFile.replaceAll("-", "_")
diff --git a/src/org/torproject/ernie/web/TableParameterChecker.java b/src/org/torproject/ernie/web/TableParameterChecker.java
index 3209bda..25bd8fa 100644
--- a/src/org/torproject/ernie/web/TableParameterChecker.java
+++ b/src/org/torproject/ernie/web/TableParameterChecker.java
@@ -41,10 +41,10 @@ public class TableParameterChecker {
   public TableParameterChecker() {
     this.dateFormat = new SimpleDateFormat("yyyy-MM-dd");
     this.dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
+  }
 
-    this.availableTables = new HashMap<String, String>();
-    this.availableTables.put("direct-users", "start,end,filename");
-    this.availableTables.put("censorship-events", "start,end,filename");
+  public void setAvailableTables(Map<String, String> availableTables) {
+    this.availableTables = availableTables;
   }
 
   /**



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits