statistics: selected gateway

This commit is contained in:
Nils Schneider 2015-03-30 03:12:30 +02:00
parent 35c4690ad6
commit c4db68b31f

View File

@ -1,7 +1,7 @@
define(["chartjs", "chroma-js"], function (ChartJS, Chroma) { define(["chartjs", "chroma-js"], function (ChartJS, Chroma) {
return function () { return function () {
var self = this var self = this
var fwTable, hwTable, autoTable var fwTable, hwTable, autoTable, gwTable
var scale = Chroma.scale("YlGnBu").mode("lab") var scale = Chroma.scale("YlGnBu").mode("lab")
function count(nodes, key, def, f) { function count(nodes, key, def, f) {
@ -50,7 +50,13 @@ define(["chartjs", "chroma-js"], function (ChartJS, Chroma) {
} }
self.setData = function (data) { 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 fwDict = count(nodes, ["nodeinfo", "software", "firmware", "release"], "n/a")
var hwDict = count(nodes, ["nodeinfo", "hardware", "model"], "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 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(fwTable, fwDict.sort(function (a, b) { return b[1] - a[1] }))
fillTable(hwTable, hwDict.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(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) { self.render = function (el) {
@ -91,6 +108,14 @@ define(["chartjs", "chroma-js"], function (ChartJS, Chroma) {
autoTable = document.createElement("table") autoTable = document.createElement("table")
autoTable.classList.add("proportion") autoTable.classList.add("proportion")
el.appendChild(autoTable) 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 return self