proportions: count only values that are present

This commit is contained in:
Nils Schneider 2015-04-22 01:35:31 +02:00
parent d5a9c52788
commit f65e89aaca

View file

@ -6,7 +6,7 @@ define(["chroma-js", "virtual-dom", "numeral-intl"],
var fwTable, hwTable, autoTable, gwTable
var scale = Chroma.scale("YlGnBu").mode("lab")
function count(nodes, key, def, f) {
function count(nodes, key, f) {
var dict = {}
nodes.forEach( function (d) {
@ -16,7 +16,7 @@ define(["chroma-js", "virtual-dom", "numeral-intl"],
v = f(v)
if (v === null)
v = def
return
dict[v] = 1 + (v in dict ? dict[v] : 0)
})
@ -63,16 +63,18 @@ define(["chroma-js", "virtual-dom", "numeral-intl"],
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")
var autoDict = count(nodes, ["nodeinfo", "software", "autoupdater"], "deaktiviert", function (d) {
if (d === null || !d.enabled)
var fwDict = count(nodes, ["nodeinfo", "software", "firmware", "release"])
var hwDict = count(nodes, ["nodeinfo", "hardware", "model"])
var autoDict = count(nodes, ["nodeinfo", "software", "autoupdater"], function (d) {
if (d === null)
return null
else
else if (d.enabled)
return d.branch
else
return "(deaktiviert)"
})
var gwDict = count(onlineNodes, ["statistics", "gateway"], "n/a", function (d) {
var gwDict = count(onlineNodes, ["statistics", "gateway"], function (d) {
if (d === null)
return null