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

[tor-commits] [atlas/master] map: Add simple relay count map



commit 2364b5b6fb0fa494e6f704ab92f5d4093da2d855
Author: Iain R. Learmonth <irl@xxxxxxxx>
Date:   Sat Jan 13 23:14:13 2018 +0000

    map: Add simple relay count map
---
 js/views/aggregate/map.js    | 39 +++++++++++++++++++++++----------------
 templates/aggregate/map.html |  1 +
 2 files changed, 24 insertions(+), 16 deletions(-)

diff --git a/js/views/aggregate/map.js b/js/views/aggregate/map.js
index d7411b4..19b2f35 100644
--- a/js/views/aggregate/map.js
+++ b/js/views/aggregate/map.js
@@ -18,6 +18,7 @@ define([
   var aggregateSearchView = Backbone.View.extend({
     el: "#content",
     explanations: {
+        "relays": "The map shows the total number of relays running in each country.",
         "consensus_weight_fraction": "This map shows the total <a href=\"https://metrics.torproject.org/glossary.html#consensus-weight\"; target=\"_blank\">consensus weight</a> of each country's relays as a percentage of all consensus weights in the network.  This percentage is a very rough approximation of the probability of a relay in each country to be selected by clients.",
         "guard_probability": "This map shows the total guard probability of each country's relays as a percentage of the guard probabilities of all relays in the network. This probability is calculated based on consensus weights, relay flags, and bandwidth weights in the consensus. Path selection depends on more factors, so that this probability can only be an approximation.",
         "middle_probability": "This map shows the total middle probability of each country's relays as a percentage of the middle probabilities of all relays in the network. This probability is calculated based on consensus weights, relay flags, and bandwidth weights in the consensus. Path selection depends on more factors, so that this probability can only be an approximation.",
@@ -88,30 +89,38 @@ define([
         }
       }
 
-      var getCountryTooltip = function(code, aggregate_property) {
-        found = getCountryAggregate(code, aggregate_property);
-        text = CountryCodes[code.toLowerCase()] + " (" + code + ") - ";
+      var formatValue = function(value, aggregate_property) {
         switch (aggregate_property) {
+          case "relays":
+            text = value.toFixed(0) + " relays";
+            break;
           case "consensus_weight_fraction":
           case "guard_probability":
           case "middle_probability":
           case "exit_probability":
-              text += (found*100).toFixed(3) + "%";
-              break;
+            text = (value*100).toFixed(3) + "%";
+            break;
           case "advertised_bandwidth":
-              text += found + "KBps";
-              break;
+            text = value + "KBps";
+            break;
           case "consensus_weight_to_bandwidth":
-              if (found == 0) {
-                text += "No relays";
-              } else {
-                text += (found<1) ? "1:" + (1/found).toFixed(1) :
-                                    found.toFixed(1) + ":1";
-              }
+            if (value == 0) {
+              text = "No relays";
+            } else {
+              text = (value<1) ? "1:" + (1/value).toFixed(1) :
+                                  value.toFixed(1) + ":1";
+            }
         }
         return text;
       }
 
+      var getCountryTooltip = function(code, aggregate_property) {
+        found = getCountryAggregate(code, aggregate_property);
+        text = CountryCodes[code.toLowerCase()] + " (" + code + ") - ";
+        text += formatValue(found, aggregate_property);
+        return text;
+      }
+
       d3.json("json/countries.topo.json", function(error, us) {
       g.append("g")
         .attr("id", "countries")
@@ -168,9 +177,7 @@ define([
           .style("font-size", "12px")
           .style("fill", "#484848")
           .text( function() {
-            return (aggregate_property == "advertised_bandwidth") ?
-             "" + (i * maximum_value/(1024*1024)).toFixed(2) + "MiB/s" :
-             "" + (i * maximum_value*100).toFixed(3) + "%";
+            return formatValue(i*maximum_value, aggregate_property);
           });
        }
     }
diff --git a/templates/aggregate/map.html b/templates/aggregate/map.html
index c36a226..87ce0dc 100644
--- a/templates/aggregate/map.html
+++ b/templates/aggregate/map.html
@@ -51,6 +51,7 @@
    <div class="panel panel-default">
    <div class="panel-body">
    <form id="map-radio-buttons">
+     <label class="radio-inline"><input type="radio" name="aggregate-property" value="relays"<% if (mapProperty == "relays") { %> checked="checked"<% } %>> Number of Relays</label>
      <label class="radio-inline"><input type="radio" name="aggregate-property" value="consensus_weight_fraction"<% if (mapProperty == "consensus_weight_fraction") { %> checked="checked"<% } %>> Consensus Weight</label>
      <label class="radio-inline"><input type="radio" name="aggregate-property" value="guard_probability"<% if (mapProperty == "guard_probability") { %> checked="checked"<% } %>> Guard Probability</label>
      <label class="radio-inline"><input type="radio" name="aggregate-property" value="middle_probability"<% if (mapProperty == "middle_probability") { %> checked="checked"<% } %>> Middle Probability</label>



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