From c4db68b31f48188759c8c3583c6b823af7432369 Mon Sep 17 00:00:00 2001 From: Nils Schneider Date: Mon, 30 Mar 2015 03:12:30 +0200 Subject: [PATCH] statistics: selected gateway --- lib/proportions.js | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/lib/proportions.js b/lib/proportions.js index e2d7c23..38258cf 100644 --- a/lib/proportions.js +++ b/lib/proportions.js @@ -1,7 +1,7 @@ define(["chartjs", "chroma-js"], function (ChartJS, Chroma) { return function () { var self = this - var fwTable, hwTable, autoTable + var fwTable, hwTable, autoTable, gwTable var scale = Chroma.scale("YlGnBu").mode("lab") function count(nodes, key, def, f) { @@ -50,7 +50,13 @@ define(["chartjs", "chroma-js"], function (ChartJS, Chroma) { } self.setData = function (data) { - var nodes = data.nodes.all.filter(online).concat(data.nodes.lost) + var onlineNodes = data.nodes.all.filter(online) + var nodes = onlineNodes.concat(data.nodes.lost) + var nodeDict = {} + + data.nodes.all.forEach(function (d) { + nodeDict[d.nodeinfo.node_id] = d + }) var fwDict = count(nodes, ["nodeinfo", "software", "firmware", "release"], "n/a") var hwDict = count(nodes, ["nodeinfo", "hardware", "model"], "n/a") @@ -61,9 +67,20 @@ define(["chartjs", "chroma-js"], function (ChartJS, Chroma) { return d.branch }) + var gwDict = count(onlineNodes, ["statistics", "gateway"], "n/a", function (d) { + if (d === null) + return null + + if (d in nodeDict) + return nodeDict[d].nodeinfo.hostname + + return d + }) + fillTable(fwTable, fwDict.sort(function (a, b) { return b[1] - a[1] })) fillTable(hwTable, hwDict.sort(function (a, b) { return b[1] - a[1] })) fillTable(autoTable, autoDict.sort(function (a, b) { return b[1] - a[1] })) + fillTable(gwTable, gwDict.sort(function (a, b) { return b[1] - a[1] })) } self.render = function (el) { @@ -91,6 +108,14 @@ define(["chartjs", "chroma-js"], function (ChartJS, Chroma) { autoTable = document.createElement("table") autoTable.classList.add("proportion") el.appendChild(autoTable) + + h2 = document.createElement("h2") + h2.textContent = "Gewählter Gateway" + el.appendChild(h2) + + gwTable = document.createElement("table") + gwTable.classList.add("proportion") + el.appendChild(gwTable) } return self