From 113b110ab40d4060d59060632b9af7539006335e Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Fri, 20 Jun 2014 23:24:27 +0200 Subject: [PATCH] Summarize OS --- main.go | 6 ++++++ static/app.js | 16 ++++++++++++++++ static/index.html | 20 ++++++++++++++++++-- 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index f25ed7309..c9c7b31b7 100644 --- a/main.go +++ b/main.go @@ -225,6 +225,9 @@ func reportHandler(w http.ResponseWriter, r *http.Request) { func statsForInts(data []int) map[string]int { sort.Ints(data) res := make(map[string]int, 4) + if len(data) == 0 { + return res + } res["fp"] = data[int(float64(len(data))*0.05)] res["med"] = data[len(data)/2] res["nfp"] = data[int(float64(len(data))*0.95)] @@ -235,6 +238,9 @@ func statsForInts(data []int) map[string]int { func statsForFloats(data []float64) map[string]float64 { sort.Float64s(data) res := make(map[string]float64, 4) + if len(data) == 0 { + return res + } res["fp"] = data[int(float64(len(data))*0.05)] res["med"] = data[len(data)/2] res["nfp"] = data[int(float64(len(data))*0.95)] diff --git a/static/app.js b/static/app.js index bbbfadb81..87707db07 100644 --- a/static/app.js +++ b/static/app.js @@ -34,11 +34,27 @@ reports.controller('ReportsCtrl', function ($scope, $http) { $scope.versions = sortedList(data.versions); $scope.platforms = sortedList(data.platforms); + var os = aggregate(data.platforms, function (x) {return x.replace(/-.*/, '');}) + $scope.os = sortedList(os); + }).error(function () { $scope.failure = true; }); }); +function aggregate(d, f) { + var r = {}; + for (var o in d) { + var k = f(o); + if (k in r) { + r[k] += d[o]; + } else { + r[k] = d[o]; + } + } + return r; +} + function sortedList(d) { var l = []; var tot = 0; diff --git a/static/index.html b/static/index.html index 76d06e2e5..6f50934cd 100644 --- a/static/index.html +++ b/static/index.html @@ -52,7 +52,7 @@ found in the LICENSE file.
-
+
@@ -68,7 +68,7 @@ found in the LICENSE file.
-
+
@@ -84,6 +84,22 @@ found in the LICENSE file.
+
+ + + + + + + + + + + + + +
OSNodesShare
{{p[0]}}{{p[1]}}{{p[2] | number:2}}%
+