[tor-commits] [metrics-web/master] Adds summary row to simple and aggregated search

karsten at torproject.org karsten at torproject.org
Wed Jul 18 14:30:12 UTC 2018


commit cda3abd6fb91f4739d0ef8f350ba701bbc1782f5
Author: Iain R. Learmonth <irl at fsfe.org>
Date:   Tue Jul 10 22:33:01 2018 +0100

    Adds summary row to simple and aggregated search
    
    For the simple search, only the advertised bandwidth row is really
    aggregatable. For aggregated search, all columns except version, country
    and autonomous system are aggregated. All aggregations are just sums.
    
    Fixes: #25050
---
 .../resources/web/js/rs/views/aggregate/search.js  | 33 ++++++++++++++++++++--
 src/main/resources/web/js/rs/views/search/do.js    | 13 +++++++--
 .../web/templates/rs/aggregate/search.html         | 13 +++++++++
 src/main/resources/web/templates/rs/search/do.html | 16 +++++++++++
 4 files changed, 71 insertions(+), 4 deletions(-)

diff --git a/src/main/resources/web/js/rs/views/aggregate/search.js b/src/main/resources/web/js/rs/views/aggregate/search.js
index 5cb8c82..3c656fc 100644
--- a/src/main/resources/web/js/rs/views/aggregate/search.js
+++ b/src/main/resources/web/js/rs/views/aggregate/search.js
@@ -18,9 +18,10 @@ define([
     },
     render: function(query){
       document.title = "Relay Search";
-      var compiledTemplate = _.template(aggregateSearchTemplate)
+      var compiledTemplate = _.template(aggregateSearchTemplate);
+      var aggregates = this.collection.models;
       this.$el.html(compiledTemplate({query: query,
-                                     aggregates: this.collection.models,
+                                     aggregates: aggregates,
                                      aType: this.collection.aType,
                                      countries: CountryCodes,
                                      error: this.error,
@@ -34,6 +35,34 @@ define([
         "aaSorting": [[(this.collection.aType == "version") ? 3 : 2, "desc"]],
         "fnDrawCallback": function( oSettings ) {
           $(".tip").tooltip({'html': true});
+        },
+        "footerCallback": function( tfoot, data, start, end, display ) {
+          var sumConsensusWeight = 0;
+          var sumAdvertisedBandwidths = 0;
+          var sumGuardProbability = 0;
+          var sumMiddleProbability = 0;
+          var sumExitProbability = 0;
+          var sumRelays = 0;
+          var sumGuards = 0;
+          var sumExits = 0;
+          for (var i = 0; i < aggregates.length; i++) {
+            sumConsensusWeight += aggregates[i]["consensus_weight_fraction"];
+            sumAdvertisedBandwidths += aggregates[i]["advertised_bandwidth"];
+            sumGuardProbability += aggregates[i]["guard_probability"];
+            sumMiddleProbability += aggregates[i]["middle_probability"];
+            sumExitProbability += aggregates[i]["exit_probability"];
+            sumRelays += aggregates[i]["relays"];
+            sumGuards += aggregates[i]["guards"];
+            sumExits += aggregates[i]["exits"];
+          }
+          $(tfoot).find('th').eq(1).html((sumConsensusWeight * 100).toFixed(2) + "%");
+          $(tfoot).find('th').eq(2).html(hrBandwidth(sumAdvertisedBandwidths));
+          $(tfoot).find('th').eq(3).html((sumGuardProbability * 100).toFixed(2) + "%");
+          $(tfoot).find('th').eq(4).html((sumMiddleProbability * 100).toFixed(2) + "%");
+          $(tfoot).find('th').eq(5).html((sumExitProbability * 100).toFixed(2) + "%");
+          $(tfoot).find('th').eq(6).html(sumRelays);
+          $(tfoot).find('th').eq(7).html(sumGuards);
+          $(tfoot).find('th').eq(8).html(sumExits);
         }
       });
     },
diff --git a/src/main/resources/web/js/rs/views/search/do.js b/src/main/resources/web/js/rs/views/search/do.js
index 18b1f05..5383580 100644
--- a/src/main/resources/web/js/rs/views/search/do.js
+++ b/src/main/resources/web/js/rs/views/search/do.js
@@ -18,9 +18,10 @@ define([
     },
     render: function(query){
       document.title = "Relay Search";
-      var compiledTemplate = _.template(doSearchTemplate)
+      var compiledTemplate = _.template(doSearchTemplate);
+      var relays = this.relays;
       this.$el.html(compiledTemplate({query: query,
-                                     relays: this.relays,
+                                     relays: relays,
                                      countries: CountryCodes,
                                      error: this.error,
                                      relaysPublished: this.relaysPublished,
@@ -49,6 +50,14 @@ define([
         "aaSorting": [[2, "desc"]],
         "fnDrawCallback": function( oSettings ) {
           $(".tip").tooltip({'html':true});
+        },
+        "footerCallback": function( tfoot, data, start, end, display ) {
+          console.log(relays);
+          var sumAdvertisedBandwidths = 0;
+          for (var i = 0; i < relays.length; i++) {
+            sumAdvertisedBandwidths += relays[i].get("advertised_bandwidth");
+          }
+          $(tfoot).find('th').eq(2).html(hrBandwidth(sumAdvertisedBandwidths));
         }
       });
     },
diff --git a/src/main/resources/web/templates/rs/aggregate/search.html b/src/main/resources/web/templates/rs/aggregate/search.html
index 5775057..19e45e7 100644
--- a/src/main/resources/web/templates/rs/aggregate/search.html
+++ b/src/main/resources/web/templates/rs/aggregate/search.html
@@ -53,6 +53,19 @@
                         <th>Exit</th>
 		</tr>
 	</thead>
+	<tfoot>
+		<tr>
+                        <th colspan="<% if (aType == "version") { %>3<% } else { %>2<% } %>">Total</th>
+                        <th> </th>
+                        <th> </th>
+                        <th> </th>
+                        <th> </th>
+                        <th> </th>
+                        <th> </th>
+                        <th> </th>
+                        <th> </th>
+		</tr>
+	</tfoot>
 	<tbody>
 
 <% _.each(aggregates, function(aggregate) { %>
diff --git a/src/main/resources/web/templates/rs/search/do.html b/src/main/resources/web/templates/rs/search/do.html
index 71ec7be..4f48a50 100644
--- a/src/main/resources/web/templates/rs/search/do.html
+++ b/src/main/resources/web/templates/rs/search/do.html
@@ -68,6 +68,22 @@
 			<th>Type</th>
 		</tr>
 	</thead>
+        <tfoot>
+		<tr>
+			<th> </th>
+			<th>Total</th>
+			<th> </th>
+			<th> </th>
+			<th> </th>
+			<th> </th>
+			<th> </th>
+			<th> </th>
+			<th> </th>
+			<th> </th>
+			<th> </th>
+			<th> </th>
+		</tr>
+	</tfoot>
 	<tbody>
 
 <% _.each(relays, function(relay) { %>





More information about the tor-commits mailing list