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

[tor-commits] [metrics-web/master] Rip out metrics table.



commit bdfca8e75e23c3dd29e1fb6eca7ae835d26acde4
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date:   Mon Dec 12 12:16:33 2016 +0100

    Rip out metrics table.
---
 .../org/torproject/metrics/web/IndexServlet.java   | 246 +--------------------
 website/web/WEB-INF/about.jsp                      |   6 +-
 website/web/WEB-INF/index.jsp                      |  86 ++-----
 3 files changed, 25 insertions(+), 313 deletions(-)

diff --git a/website/src/org/torproject/metrics/web/IndexServlet.java b/website/src/org/torproject/metrics/web/IndexServlet.java
index 576bac2..f365cbb 100644
--- a/website/src/org/torproject/metrics/web/IndexServlet.java
+++ b/website/src/org/torproject/metrics/web/IndexServlet.java
@@ -4,261 +4,23 @@
 package org.torproject.metrics.web;
 
 import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.BitSet;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
 
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
-@SuppressWarnings("serial")
 public class IndexServlet extends HttpServlet {
 
-  private static final String[][] knownTags = new String[][] {
-    { "cl", "Clients" },
-    { "rl", "Relays" },
-    { "br", "Bridges" },
-    { "pt", "Pluggable transports" },
-    { "hs", "Hidden services" },
-    { "bw", "Bandwidth" },
-    { "pf", "Performance" },
-    { "dv", "Diversity" }
-  };
-  private static final String[] defaultTags =
-      new String[] { "cl", "rl", "br", "pt", "hs", "bw", "pf", "dv" };
-
-  private static final String[][] knownTypes = new String[][] {
-    { "gr", "Graph" },
-    { "tb", "Table" },
-    { "ln", "Link" },
-    { "dt", "Data" }
-  };
-  private static final String[] defaultTypes =
-      new String[] { "gr", "tb", "ln", "dt" };
-
-  private static final String[][] knownLevels = new String[][] {
-    { "bs", "Basic" },
-    { "ad", "Advanced" }
-  };
-  private static final String[] defaultLevels = new String[] { "bs" };
-
-  private static final String[][] knownOrders = new String[][] {
-    { "name", "Name" },
-    { "tags", "Tags" },
-    { "type", "Type" },
-    { "level", "Level" },
-    { "shuffle", "None (shuffle)" }
-  };
-  private static final String[] defaultOrders = new String[] { "type" };
-
-  private List<Metric> availableMetrics;
-
-  @Override
-  public void init() throws ServletException {
-    this.availableMetrics = new ArrayList<Metric>();
-    for (org.torproject.metrics.web.Metric metric
-        : MetricsProvider.getInstance().getMetricsList()) {
-      this.availableMetrics.add(new Metric(metric.getId() + ".html",
-          metric.getTitle(), metric.getTags(), metric.getType(),
-          metric.getLevel()));
-    }
-  }
+  private static final long serialVersionUID = -5156539049907533057L;
 
   @Override
   public void doGet(HttpServletRequest request,
       HttpServletResponse response) throws IOException, ServletException {
-    @SuppressWarnings("rawtypes")
-    Map parameterMap = request.getParameterMap();
-    BitSet requestedTags = this.parseParameter(
-        (String[]) parameterMap.get("tag"), knownTags, defaultTags);
-    BitSet requestedTypes = this.parseParameter(
-        (String[]) parameterMap.get("type"), knownTypes, defaultTypes);
-    BitSet requestedLevels = this.parseParameter(
-        (String[]) parameterMap.get("level"), knownLevels, defaultLevels);
-    BitSet requestedOrder = this.parseParameter(
-        (String[]) parameterMap.get("order"), knownOrders, defaultOrders);
-    request.setAttribute("tags", this.formatParameter(knownTags,
-        requestedTags));
-    request.setAttribute("types", this.formatParameter(knownTypes,
-        requestedTypes));
-    request.setAttribute("levels", this.formatParameter(knownLevels,
-        requestedLevels));
-    request.setAttribute("order", this.formatParameter(knownOrders,
-        requestedOrder));
-    List<Metric> filteredAndOrderedMetrics = this.filterMetrics(
-        requestedTags, requestedTypes, requestedLevels);
-    this.orderMetrics(filteredAndOrderedMetrics, requestedOrder);
-    request.setAttribute("results", this.formatMetrics(
-        filteredAndOrderedMetrics));
+
+    /* Forward the request to the JSP that does all the hard work. */
     request.getRequestDispatcher("WEB-INF/index.jsp").forward(request,
         response);
   }
-
-  private BitSet parseParameter(String[] unparsedValues,
-      String[][] knownValues, String[] defaultValues) {
-    BitSet result = new BitSet();
-    if (unparsedValues == null || unparsedValues.length == 0
-        || unparsedValues.length > knownValues.length) {
-      unparsedValues = defaultValues;
-    }
-    Set<String> requestedValues =
-        new HashSet<String>(Arrays.asList(unparsedValues));
-    for (int i = 0; i < knownValues.length; i++) {
-      if (requestedValues.contains(knownValues[i][0])) {
-        result.set(i);
-      }
-    }
-    return result;
-  }
-
-  private String[][] formatParameter(String[][] strings, BitSet bitSet) {
-    String[][] formattedParameter = new String[strings.length][];
-    for (int i = 0; i < formattedParameter.length; i++) {
-      String[] formatted = new String[] { strings[i][0], strings[i][1],
-          "" };
-      if (bitSet.get(i)) {
-        formatted[2] = " checked";
-      }
-      formattedParameter[i] = formatted;
-    }
-    return formattedParameter;
-  }
-
-  private static class Metric {
-
-    private String url;
-
-    private String name;
-
-    private BitSet tags;
-
-    private BitSet type;
-
-    private BitSet level;
-
-    private Metric(String url, String name, String[] tagStrings,
-        String typeString, String levelString) {
-      this.url = url;
-      this.name = name;
-      this.tags = this.convertStringsToBitSet(knownTags, tagStrings);
-      this.type = this.convertStringToBitSet(knownTypes, typeString);
-      this.level = this.convertStringToBitSet(knownLevels, levelString);
-    }
-
-    private BitSet convertStringsToBitSet(String[][] knownKeysAndValues,
-        String[] givenKeyStrings) {
-      BitSet result = new BitSet(knownKeysAndValues.length);
-      Set<String> keys = new HashSet<String>(Arrays.asList(
-          givenKeyStrings));
-      for (int i = 0; i < knownKeysAndValues.length; i++) {
-        if (keys.contains(knownKeysAndValues[i][1])) {
-          result.set(i);
-        }
-      }
-      if (result.cardinality() != givenKeyStrings.length) {
-        throw new RuntimeException("Unknown key(s): " + keys);
-      }
-      return result;
-    }
-
-    private BitSet convertStringToBitSet(String[][] knownKeysAndValues,
-        String givenKeyString) {
-      return this.convertStringsToBitSet(knownKeysAndValues,
-          new String[] { givenKeyString });
-    }
-
-    private String[] toStrings() {
-      return new String[] { this.url, this.name,
-          this.convertBitSetToString(knownTags, this.tags),
-          this.convertBitSetToString(knownTypes, this.type),
-          this.convertBitSetToString(knownLevels, this.level) };
-    }
-
-    private String convertBitSetToString(String[][] knownKeysAndValues,
-        BitSet bitSet) {
-      StringBuilder sb = new StringBuilder();
-      int index = -1;
-      while ((index = bitSet.nextSetBit(index + 1)) >= 0) {
-        sb.append(", " + knownKeysAndValues[index][1]);
-      }
-      return sb.substring(Math.min(sb.length(), 2));
-    }
-  }
-
-  private List<Metric> filterMetrics(BitSet requestedTags,
-      BitSet requestedTypes, BitSet requestedLevels) {
-    List<Metric> filteredMetrics = new ArrayList<Metric>();
-    for (Metric metric : availableMetrics) {
-      if (requestedTags.intersects(metric.tags)
-          && requestedTypes.intersects(metric.type)
-          && requestedLevels.intersects(metric.level)) {
-        filteredMetrics.add(metric);
-      }
-    }
-    return filteredMetrics;
-  }
-
-  private void orderMetrics(List<Metric> resultMetrics,
-      BitSet requestedOrder) {
-    switch (requestedOrder.nextSetBit(0)) {
-      case 0:
-        Collections.sort(resultMetrics, new Comparator<Metric>() {
-          public int compare(Metric first, Metric second) {
-            return first.name.compareTo(second.name);
-          }
-        });
-        break;
-      case 1:
-        Collections.sort(resultMetrics, new Comparator<Metric>() {
-          public int compare(Metric first, Metric second) {
-            return compareTwoBitSets(first.tags, second.tags);
-          }
-        });
-        break;
-      case 2:
-        Collections.sort(resultMetrics, new Comparator<Metric>() {
-          public int compare(Metric first, Metric second) {
-            return compareTwoBitSets(first.type, second.type);
-          }
-        });
-        break;
-      case 3:
-        Collections.sort(resultMetrics, new Comparator<Metric>() {
-          public int compare(Metric first, Metric second) {
-            return compareTwoBitSets(first.level, second.level);
-          }
-        });
-        break;
-      default:
-        Collections.shuffle(resultMetrics);
-        break;
-    }
-  }
-
-  private int compareTwoBitSets(BitSet first, BitSet second) {
-    if (first.equals(second)) {
-      return 0;
-    }
-    BitSet xor = (BitSet) first.clone();
-    xor.xor(second);
-    return xor.length() == second.length() ? -1 : 1;
-  }
-
-  private String[][] formatMetrics(
-      List<Metric> filteredAndOrderedMetrics) {
-    String[][] formattedMetrics =
-        new String[filteredAndOrderedMetrics.size()][];
-    for (int i = 0; i < formattedMetrics.length; i++) {
-      formattedMetrics[i] = filteredAndOrderedMetrics.get(i).toStrings();
-    }
-    return formattedMetrics;
-  }
 }
+
diff --git a/website/web/WEB-INF/about.jsp b/website/web/WEB-INF/about.jsp
index 91a696b..a067674 100644
--- a/website/web/WEB-INF/about.jsp
+++ b/website/web/WEB-INF/about.jsp
@@ -9,11 +9,7 @@
 <body>
   <div class="center">
     <div class="main-column">
-        <h2><a href="/"><img src="images/metrics-logo.png" width="153"
-height="200" al
-t="Metrics logo"><img src="images/metrics-wordmark.png" width="384" height="50"
-alt="M
-etrics wordmark"></a></h2>
+        <h2><a href="/"><img src="images/metrics-logo.png" width="153" height="200" alt="Metrics logo"><img src="images/metrics-wordmark.png" width="384" height="50" alt="Metrics wordmark"></a></h2>
         <br>
 
 <p>"Tor metrics are the ammunition that lets Tor and other security
diff --git a/website/web/WEB-INF/index.jsp b/website/web/WEB-INF/index.jsp
index 6e06474..ad4b79f 100644
--- a/website/web/WEB-INF/index.jsp
+++ b/website/web/WEB-INF/index.jsp
@@ -30,77 +30,31 @@ of data, rather than just dogma or perspective."
         <br>
         <!-- Navigation end -->
 
-        <p>Welcome to Tor Metrics, the primary place to learn interesting
-        facts about the Tor network, the largest deployed anonymity
-        network to date.
-        If something can be measured safely, you'll find it here.*</p>
-        <p><small>*And if you come across something that is missing here,
-        please
-        <a href="https://www.torproject.org/about/contact.html.en";>let us
-        know</a>.</small></p>
+        <p>Welcome! What would you like to know about the Tor network?</p>
 
 <div>
-<div style="border:1px solid gray;border-radius:10px;padding:10px;float:left;overflow:hidden;margin-right:20px;">
-<form action="/">
-<p>
-<b>Tags</b><br>
-<c:forEach var="row" items="${tags}">
-<label><input name="tag" type="checkbox" value="${row[0]}" <c:if test="${fn:length(row[2]) > 0}"> checked</c:if>> ${row[1]}</label></br>
-</c:forEach>
-</p>
-<p>
-<b>Type</b></br>
-<c:forEach var="row" items="${types}">
-<label><input name="type" type="checkbox" value="${row[0]}" <c:if test="${fn:length(row[2]) > 0}"> checked</c:if>> ${row[1]}</label></br>
-</c:forEach>
-</p>
-<p>
-<b>Level</b></br>
-<c:forEach var="row" items="${levels}">
-<label><input name="level" type="checkbox" value="${row[0]}" <c:if test="${fn:length(row[2]) > 0}"> checked</c:if>> ${row[1]}</label></br>
-</c:forEach>
-</p>
-<p>
-<b>Order</b></br>
-<c:forEach var="row" items="${order}">
-<label><input name="order" type="radio" value="${row[0]}" <c:if test="${fn:length(row[2]) > 0}"> checked</c:if>> ${row[1]}</label></br>
-</c:forEach>
-</p>
-<p>
-<input type="submit" value="Update">
-</p>
-</form>
-</div>
+<a href="userstats-relay-country.html"><h3>Users</h3></a>
+<p>Where are Tor users from? How do they connect to Tor?</p>
 
-<div style="overflow:hidden;">
-<style>
-table {
-  border-spacing: 10px;
-}
-</style>
-<table>
-<thead>
-<tr>
-<th>Name</th>
-<th>Tags</th>
-<th>Type</th>
-<th>Level</th>
-</tr>
-</thead>
-<tbody>
-<c:forEach var="row" items="${results}">
-<tr>
-<td><a href="${row[0]}">${row[1]}</a></td>
-<td>${row[2]}</td>
-<td>${row[3]}</td>
-<td>${row[4]}</td>
-</tr>
-</c:forEach>
-</tbody>
-</table>
-</div>
+<a href="networksize.html"><h3>Relays and Bridges</h3></a>
+<p>How many relays and bridges are online? What do we know about them?</p>
+
+<a href="bandwidth.html"><h3>Traffic</h3></a>
+<p>How much traffic can the Tor network handle? How much traffic is there?</p>
+
+<a href="torperf.html"><h3>Performance</h3></a>
+<p>How fast and reliable is the Tor network?</p>
+
+<a href="hidserv-dir-onions-seen.html"><h3>Onion Services</h3></a>
+<p>How many onion services are there? How much traffic do they pull?</p>
+
+<h3>Downloads (coming soon)</h3>
+<p>How many downloads of Tor applications are there? How many updates?</p>
 </div>
 
+<p>Let us know if we're missing anything, or if we should measure something
+else.</p>
+
     </div>
   </div>
   <div class="bottom" id="bottom">



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