From 2bbdd1e07775332508671a3b5382f390e9f17613 Mon Sep 17 00:00:00 2001 From: Johannes Rudolph Date: Sun, 5 Jun 2016 22:55:26 +0200 Subject: [PATCH] main: filter duplicate nodes from different data sources * add jquery * filter duplicate nodes by online state * remove old stuff * remove debug output * remove curly braces --- lib/main.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/main.js b/lib/main.js index 396aed1..21fabe9 100644 --- a/lib/main.js +++ b/lib/main.js @@ -4,12 +4,14 @@ function (moment, Router, L, GUI, numeral) { function handleData(data) { var dataNodes = {} dataNodes.nodes = [] + dataNodes.nodeIds = [] var dataGraph = {} dataGraph.batadv = {} dataGraph.batadv.nodes = [] dataGraph.batadv.links = [] + function rearrangeLinks(d) { d.source += dataGraph.batadv.nodes.length d.target += dataGraph.batadv.nodes.length @@ -32,11 +34,22 @@ function (moment, Router, L, GUI, numeral) { vererr = "Unsupported nodes version: " + data[i].version console.log(vererr) //silent fail } else { - dataNodes.nodes = dataNodes.nodes.concat(data[i].nodes) + data[i].nodes.forEach(fillData) dataNodes.timestamp = data[i].timestamp } } + function fillData (node) { + var position = dataNodes.nodeIds.indexOf(node.nodeinfo.node_id) + if(position === -1){ + dataNodes.nodes.push(node) + dataNodes.nodeIds.push(node.nodeinfo.node_id) + } + else + if(node.flags.online === true) + dataNodes.nodes[position] = node + } + var nodes = dataNodes.nodes.filter( function (d) { return "firstseen" in d && "lastseen" in d })