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