From 80967c625900332ebc36c4a04f8a31c0cd532416 Mon Sep 17 00:00:00 2001 From: PetaByteBoy Date: Sat, 18 Jul 2015 16:28:07 +0200 Subject: [PATCH] statistics: site code statistics configurable and documented! --- README.md | 18 ++++++++++++++++++ config.json.example | 6 ++++++ lib/infobox/node.js | 12 ++++++++++++ lib/proportions.js | 26 ++++++++++++++++++++++++++ 4 files changed, 62 insertions(+) diff --git a/README.md b/README.md index 15b4de2..4ff1959 100644 --- a/README.md +++ b/README.md @@ -130,3 +130,21 @@ Examples for `globalInfos` using Grafana server rendering: "caption": "Bild mit Wochenstatistik" } ] + +## siteNames (array, optional) + +In this array name definitions for site statistics and node info can be saved. This requires one object for each site code. This object must contain: + +- `site` the site code +- `name` the defined written name for this site code + +If neither `siteNames` nor `showSites` are set, site statistics and node info won't be displayed + +Example for `siteNames`: + + "siteNames": [ + { "site": "ffhl", "name": "Lübeck" }, + { "site": "ffeh", "name": "Entenhausen" ), + { "site": "ffgt", "name": "Gothamcity" }, + { "site": "ffal", "name": "Atlantis" } + ] diff --git a/config.json.example b/config.json.example index 8d7e9ed..c4616e2 100644 --- a/config.json.example +++ b/config.json.example @@ -17,5 +17,11 @@ { "name": "Stamen.TonerLite" } + ], + "siteNames": [ + { "site": "ffhl", "name": "Lübeck" }, + { "site": "ffeh", "name": "Entenhausen" }, + { "site": "ffgt", "name": "Gothamcity" }, + { "site": "ffal", "name": "Atlantis" } ] } diff --git a/lib/infobox/node.js b/lib/infobox/node.js index 54dd801..8eb3421 100644 --- a/lib/infobox/node.js +++ b/lib/infobox/node.js @@ -53,6 +53,17 @@ define(["moment", "numeral", "tablesort", "tablesort.numeric"], return release + " / " + base } + function showSite(d, config) { + var site = dictGet(d.nodeinfo, ["system", "site_code"]) + var rt = site + if (config.siteNames) + config.siteNames.forEach( function (t) { + if(site === t.site) + rt = t.name + }) + return rt + } + function showUptime(d) { if (!("uptime" in d.statistics)) return undefined @@ -192,6 +203,7 @@ define(["moment", "numeral", "tablesort", "tablesort.numeric"], attributeEntry(attributes, "Primäre MAC", dictGet(d.nodeinfo, ["network", "mac"])) attributeEntry(attributes, "Node ID", dictGet(d.nodeinfo, ["node_id"])) attributeEntry(attributes, "Firmware", showFirmware(d)) + attributeEntry(attributes, "Site", showSite(d, config)) attributeEntry(attributes, "Uptime", showUptime(d)) attributeEntry(attributes, "Teil des Netzes", showFirstseen(d)) attributeEntry(attributes, "Arbeitsspeicher", showRAM(d)) diff --git a/lib/proportions.js b/lib/proportions.js index 805b30c..49ba4ca 100644 --- a/lib/proportions.js +++ b/lib/proportions.js @@ -26,6 +26,9 @@ define(["chroma-js", "virtual-dom", "numeral-intl", "filters/genericnode", "verc var gwTable = document.createElement("table") gwTable.classList.add("proportion") + var siteTable = document.createElement("table") + siteTable.classList.add("proportion") + function showStatGlobal(o) { var content, caption @@ -158,6 +161,16 @@ define(["chroma-js", "virtual-dom", "numeral-intl", "filters/genericnode", "verc return d }) + var siteDict = count(onlineNodes, ["nodeinfo", "system", "site_code"], function (d) { + var rt = d + if (config.siteNames) + config.siteNames.forEach( function (t) { + if(d === t.site) + rt = t.name + }) + return rt + }) + fillTable("Status", statusTable, statusDict.sort(function (a, b) { return b[1] - a[1] })) fillTable("Firmware", fwTable, fwDict.sort(function (a, b) { return vercomp(b[0], a[0]) })) fillTable("Hardware", hwTable, hwDict.sort(function (a, b) { return b[1] - a[1] })) @@ -165,6 +178,7 @@ define(["chroma-js", "virtual-dom", "numeral-intl", "filters/genericnode", "verc fillTable("Autom. Updates", autoTable, autoDict.sort(function (a, b) { return b[1] - a[1] })) fillTable("Uplink", uplinkTable, uplinkDict.sort(function (a, b) { return b[1] - a[1] })) fillTable("Gewähltes Gateway", gwTable, gwDict.sort(function (a, b) { return b[1] - a[1] })) + fillTable("Site", siteTable, siteDict.sort(function (a, b) { return b[1] - a[1] })) } self.render = function (el) { @@ -179,6 +193,13 @@ define(["chroma-js", "virtual-dom", "numeral-intl", "filters/genericnode", "verc el.appendChild(h2) el.appendChild(fwTable) + if(config.siteNames || config.showSites) { + h2 = document.createElement("h2") + h2.textContent = "Orte" + el.appendChild(h2) + el.appendChild(siteTable) + } + h2 = document.createElement("h2") h2.textContent = "Hardwaremodelle" el.appendChild(h2) @@ -204,6 +225,11 @@ define(["chroma-js", "virtual-dom", "numeral-intl", "filters/genericnode", "verc el.appendChild(h2) el.appendChild(gwTable) + h2 = document.createElement("h2") + h2.textContent = "Site" + el.appendChild(h2) + el.appendChild(siteTable) + if (config.globalInfos) config.globalInfos.forEach( function (globalInfo) { h2 = document.createElement("h2")