Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Setting this to `false` will hide contact information for nodes.
## maxAge (integer)

Nodes being online for less than maxAge days are considered "new". Likewise,
nodes being offline for less than than maxAge days are considered "lost".
nodes being offline for more than than maxAge days are considered "lost".

## mapLayers (List)

Expand Down
4 changes: 2 additions & 2 deletions lib/about.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ define(function () {
s += "https://www.gnu.org/licenses/</a>.</p>"

s += "<p>You may find the source code at "
s += "<a href=\"http://draic.info/meshviewer\">"
s += "http://draic.info/meshviewer</a>."
s += "<a href=\"https://github.com/ffnord/meshviewer\">"
s += "https://github.com/ffnord/meshviewer</a>."

el.innerHTML = s
}
Expand Down
15 changes: 9 additions & 6 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@ function (moment, Router, L, GUI, numeral) {
var dataNodes = data[0]
var dataGraph = data[1]

if (dataNodes.version !== 1 || dataGraph.version !== 1) {
if (dataNodes.version !== 2 || dataGraph.version !== 1) {
var err = "Unsupported nodes or graph version: " + dataNodes.version + " " + dataGraph.version
throw err
}

var nodes = Object.keys(dataNodes.nodes).map(function (key) { return dataNodes.nodes[key] })

nodes = nodes.filter( function (d) {
var nodes = dataNodes.nodes.filter( function (d) {
return "firstseen" in d && "lastseen" in d
})

Expand All @@ -27,7 +25,12 @@ function (moment, Router, L, GUI, numeral) {
var newnodes = limit("firstseen", age, sortByKey("firstseen", nodes).filter(online))
var lostnodes = limit("lastseen", age, sortByKey("lastseen", nodes).filter(offline))

var graphnodes = dataNodes.nodes
var graphnodes = {}

dataNodes.nodes.forEach( function (d) {
graphnodes[d.nodeinfo.node_id] = d
})

var graph = dataGraph.batadv

graph.nodes.forEach( function (d) {
Expand Down Expand Up @@ -75,7 +78,7 @@ function (moment, Router, L, GUI, numeral) {
})

return { now: now,
timestamp: moment.utc(data[0].timestamp).local(),
timestamp: moment.utc(dataNodes.timestamp).local(),
nodes: {
all: nodes,
new: newnodes,
Expand Down
6 changes: 3 additions & 3 deletions lib/proportions.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
define(["chroma-js", "virtual-dom", "numeral-intl"],
function (Chroma, V, numeral) {
define(["chroma-js", "virtual-dom", "numeral-intl", "vercomp" ],
function (Chroma, V, numeral, vercomp) {

return function (config) {
var self = this
Expand Down Expand Up @@ -128,7 +128,7 @@ define(["chroma-js", "virtual-dom", "numeral-intl"],
})

fillTable(statusTable, statusDict.sort(function (a, b) { return b[1] - a[1] }))
fillTable(fwTable, fwDict.sort(function (a, b) { return b[1] - a[1] }))
fillTable(fwTable, fwDict.sort(function (a, b) { return vercomp(b[0], a[0]) }))
fillTable(hwTable, hwDict.sort(function (a, b) { return b[1] - a[1] }))
fillTable(geoTable, geoDict.sort(function (a, b) { return b[1] - a[1] }))
fillTable(autoTable, autoDict.sort(function (a, b) { return b[1] - a[1] }))
Expand Down
60 changes: 60 additions & 0 deletions lib/vercomp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
define([], function () {
function order(c) {
if (/^\d$/.test(c))
return 0
else if (/^[a-z]$/i.test(c))
return c.charCodeAt(0)
else if (c === "~")
return -1
else if (c)
return c.charCodeAt(0) + 256
else
return 0
}

// Based on dpkg code
function vercomp(a, b) {
var apos = 0, bpos = 0
while (apos < a.length || bpos < b.length) {
var firstDiff = 0

while ((apos < a.length && !/^\d$/.test(a[apos])) || (bpos < b.length && !/^\d$/.test(b[bpos]))) {
var ac = order(a[apos])
var bc = order(b[bpos])

if (ac !== bc)
return ac - bc

apos++
bpos++
}

while (a[apos] === "0")
apos++

while (b[bpos] === "0")
bpos++

while (/^\d$/.test(a[apos]) && /^\d$/.test(b[bpos])) {
if (firstDiff === 0)
firstDiff = a.charCodeAt(apos) - b.charCodeAt(bpos)

apos++
bpos++
}

if (/^\d$/.test(a[apos]))
return 1

if (/^\d$/.test(b[bpos]))
return -1

if (firstDiff !== 0)
return firstDiff
}

return 0
}

return vercomp
})