[TASK] Cleanup old code

This commit is contained in:
Xaver Maierhofer 2017-10-31 13:32:39 +01:00 committed by Xaver Maierhofer
parent a0378348b5
commit 4caf38e990
No known key found for this signature in database
GPG Key ID: 7FDCE23FD2EC9FE8
11 changed files with 45 additions and 68 deletions

View File

@ -23,8 +23,10 @@
"title": "Jahresstatistik - weiteren Statistiken" "title": "Jahresstatistik - weiteren Statistiken"
} }
], ],
// String or array of data provider are supported // Array of data provider are supported
"dataPath": "https://regensburg.freifunk.net/data/", "dataPath": [
"https://regensburg.freifunk.net/data/"
],
"siteName": "Freifunk Regensburg", "siteName": "Freifunk Regensburg",
"mapLayers": [ "mapLayers": [
{ {

View File

@ -198,7 +198,7 @@ define(['d3-selection', 'd3-force', 'd3-zoom', 'd3-drag', 'd3-timer', 'd3-ease',
}); });
self.setData = function setData(data) { self.setData = function setData(data) {
intNodes = data.nodes.all.map(function (d) { intNodes = data.nodes.online.map(function (d) {
var e = dictNodes[d.node_id]; var e = dictNodes[d.node_id];
if (!e) { if (!e) {
e = {}; e = {};
@ -208,12 +208,10 @@ define(['d3-selection', 'd3-force', 'd3-zoom', 'd3-drag', 'd3-timer', 'd3-ease',
e.o = d; e.o = d;
return e; return e;
}).filter(function (e) {
return e.o.is_online;
}); });
intLinks = data.links.filter(function (d) { intLinks = data.links.filter(function (d) {
return dictNodes[d.source.node_id].o.is_online && dictNodes[d.target.node_id].o.is_online; return data.nodeDict[d.source.node_id].is_online && data.nodeDict[d.target.node_id].is_online;
}).map(function (d) { }).map(function (d) {
return { return {
o: d, o: d,
@ -261,9 +259,6 @@ define(['d3-selection', 'd3-force', 'd3-zoom', 'd3-drag', 'd3-timer', 'd3-ease',
draw.setHighlight({ type: 'link', o: d }); draw.setHighlight({ type: 'link', o: d });
for (var i = 0; i < intLinks.length; i++) { for (var i = 0; i < intLinks.length; i++) {
var l = intLinks[i]; var l = intLinks[i];
if (l.o !== d) {
continue;
}
return [(l.source.x + l.target.x) / 2, (l.source.y + l.target.y) / 2, (ZOOM_MAX / 2) + ZOOM_MIN]; return [(l.source.x + l.target.x) / 2, (l.source.y + l.target.y) / 2, (ZOOM_MAX / 2) + ZOOM_MIN];
} }
return [0, 0, (ZOOM_MIN + 1) / 2]; return [0, 0, (ZOOM_MIN + 1) / 2];

View File

@ -293,9 +293,9 @@ define(['sorttable', 'snabbdom', 'd3-interpolate', 'moment', 'helper'],
}; };
self.setData = function setData(data) { self.setData = function setData(data) {
d = data.nodes.all.find(function (a) { if (data.nodeDict[d.node_id]) {
return a.node_id === d.node_id; d = data.nodeDict[d.node_id];
}); }
self.render(); self.render();
}; };
return self; return self;

View File

@ -7,12 +7,12 @@ define(['helper'], function (helper) {
var timestamp = document.createTextNode(''); var timestamp = document.createTextNode('');
self.setData = function setData(d) { self.setData = function setData(d) {
var totalNodes = helper.sum(d.nodes.all.map(helper.one)); var totalNodes = Object.keys(d.nodeDict).length;
var totalOnlineNodes = helper.sum(d.nodes.all.filter(helper.online).map(helper.one)); var totalOnlineNodes = d.nodes.online.length;
var totalClients = helper.sum(d.nodes.all.filter(helper.online).map(function (n) { var totalClients = helper.sum(d.nodes.online.map(function (n) {
return n.clients; return n.clients;
})); }));
var totalGateways = helper.sum(d.nodes.all.filter(helper.online).filter(function (n) { var totalGateways = helper.sum(d.nodes.online.filter(function (n) {
return n.is_gateway; return n.is_gateway;
}).map(helper.one)); }).map(helper.one));

View File

@ -23,8 +23,15 @@ define(['moment', 'utils/router', 'leaflet', 'gui', 'helper', 'utils/language'],
var now = moment(); var now = moment();
var age = moment(now).subtract(config.maxAge, 'days'); var age = moment(now).subtract(config.maxAge, 'days');
var newnodes = helper.limit('firstseen', age, helper.sortByKey('firstseen', nodes).filter(helper.online)); var online = nodes.filter(function (d) {
var lostnodes = helper.limit('lastseen', age, helper.sortByKey('lastseen', nodes).filter(helper.offline)); return d.is_online;
});
var offline = nodes.filter(function (d) {
return !d.is_online;
});
var newnodes = helper.limit('firstseen', age, helper.sortByKey('firstseen', online));
var lostnodes = helper.limit('lastseen', age, helper.sortByKey('lastseen', offline));
nodes.forEach(function (d) { nodes.forEach(function (d) {
d.neighbours = []; d.neighbours = [];
@ -50,15 +57,13 @@ define(['moment', 'utils/router', 'leaflet', 'gui', 'helper', 'utils/language'],
} }
}); });
links.sort(function (a, b) {
return b.source_tq - a.source_tq;
});
return { return {
now: now, now: now,
timestamp: moment.utc(timestamp).local(), timestamp: moment.utc(timestamp).local(),
nodes: { nodes: {
all: nodes, all: nodes,
online: online,
offline: offline,
new: newnodes, new: newnodes,
lost: lostnodes lost: lostnodes
}, },
@ -70,22 +75,14 @@ define(['moment', 'utils/router', 'leaflet', 'gui', 'helper', 'utils/language'],
var language = new Language(config); var language = new Language(config);
var router = new Router(language); var router = new Router(language);
var urls = []; config.dataPath.forEach(function (d, i) {
config.dataPath[i] += 'meshviewer.json';
if (typeof config.dataPath === 'string' || config.dataPath instanceof String) { });
config.dataPath = [config.dataPath];
}
for (var i in config.dataPath) {
if (config.dataPath.hasOwnProperty(i)) {
urls.push(config.dataPath[i] + 'meshviewer.json');
}
}
language.init(router); language.init(router);
function update() { function update() {
return Promise.all(urls.map(helper.getJSON)) return Promise.all(config.dataPath.map(helper.getJSON))
.then(handleData); .then(handleData);
} }

View File

@ -13,7 +13,7 @@ define(['leaflet', 'rbush', 'helper'],
setData: function (data) { setData: function (data) {
var rtreeOnlineAll = rbush(9); var rtreeOnlineAll = rbush(9);
this.data = rtreeOnlineAll.load(data.nodes.all.filter(helper.online).filter(helper.hasLocation).map(this.mapRTree)); this.data = rtreeOnlineAll.load(data.nodes.online.filter(helper.hasLocation).map(this.mapRTree));
// pre-calculate start angles // pre-calculate start angles
this.data.all().forEach(function (n) { this.data.all().forEach(function (n) {

View File

@ -154,8 +154,8 @@ define(['leaflet', 'rbush', 'helper', 'moment'],
var lines = addLinksToMap(linkDict, linkScale, data.links, router); var lines = addLinksToMap(linkDict, linkScale, data.links, router);
groupLines = L.featureGroup(lines).addTo(map); groupLines = L.featureGroup(lines).addTo(map);
var nodesOnline = helper.subtract(data.nodes.all.filter(helper.online), data.nodes.new); var nodesOnline = helper.subtract(data.nodes.online, data.nodes.new);
var nodesOffline = helper.subtract(data.nodes.all.filter(helper.offline), data.nodes.lost); var nodesOffline = helper.subtract(data.nodes.offline, data.nodes.lost);
var markersOnline = nodesOnline.filter(helper.hasLocation) var markersOnline = nodesOnline.filter(helper.hasLocation)
.map(mkMarker(nodeDict, function () { .map(mkMarker(nodeDict, function () {

View File

@ -92,7 +92,6 @@ define(['sorttable', 'snabbdom', 'helper'], function (SortTable, V, helper) {
} else { } else {
n.uptime = e.lastseen - d.now; n.uptime = e.lastseen - d.now;
} }
n.neighbours = e.neighbours;
return n; return n;
}); });

View File

@ -76,7 +76,7 @@ define(['d3-interpolate', 'snabbdom', 'filters/genericnode', 'helper'],
} }
self.setData = function setData(data) { self.setData = function setData(data) {
var onlineNodes = data.nodes.all.filter(helper.online); var onlineNodes = data.nodes.online;
var nodes = onlineNodes.concat(data.nodes.lost); var nodes = onlineNodes.concat(data.nodes.lost);
function hostnameOfNodeID(nodeid) { function hostnameOfNodeID(nodeid) {

View File

@ -27,9 +27,9 @@ define({
}, },
sortByKey: function sortByKey(key, d) { sortByKey: function sortByKey(key, d) {
return d.slice().sort(function (a, b) { return d.sort(function (a, b) {
return a[key] - b[key]; return b[key] - a[key];
}).reverse(); });
}, },
limit: function limit(key, m, d) { limit: function limit(key, m, d) {
@ -72,15 +72,6 @@ define({
return s; return s;
}, },
/* Helpers working with nodes */
offline: function offline(d) {
return !d.is_online;
},
online: function online(d) {
return d.is_online;
},
hasLocation: function hasLocation(d) { hasLocation: function hasLocation(d) {
return 'location' in d && return 'location' in d &&
Math.abs(d.location.latitude) < 90 && Math.abs(d.location.latitude) < 90 &&
@ -95,7 +86,7 @@ define({
}); });
return a.filter(function (d) { return a.filter(function (d) {
return !(d.node_id in ids); return !ids[d.node_id];
}); });
}, },

View File

@ -3,7 +3,7 @@ define(['Navigo'], function (Navigo) {
return function (language) { return function (language) {
var init = false; var init = false;
var objects = { nodes: {}, links: {}, nodeDict: {} }; var objects = {};
var targets = []; var targets = [];
var views = {}; var views = {};
var current = {}; var current = {};
@ -16,17 +16,20 @@ define(['Navigo'], function (Navigo) {
} }
function gotoNode(d) { function gotoNode(d) {
if (d.nodeId in objects.nodes) { if (objects.nodeDict[d.nodeId]) {
targets.forEach(function (t) { targets.forEach(function (t) {
t.gotoNode(objects.nodes[d.nodeId], objects.nodeDict); t.gotoNode(objects.nodeDict[d.nodeId], objects.nodeDict);
}); });
} }
} }
function gotoLink(d) { function gotoLink(d) {
if (d.linkId in objects.links) { var link = objects.links.find(function (value) {
return value.id === d.linkId;
});
if (link) {
targets.forEach(function (t) { targets.forEach(function (t) {
t.gotoLink(objects.links[d.linkId]); t.gotoLink(link);
}); });
} }
} }
@ -139,17 +142,7 @@ define(['Navigo'], function (Navigo) {
}; };
router.setData = function setData(data) { router.setData = function setData(data) {
objects.nodes = {}; objects = data;
objects.links = {};
objects.nodeDict = data.nodeDict;
data.nodes.all.forEach(function (d) {
objects.nodes[d.node_id] = d;
});
data.links.forEach(function (d) {
objects.links[d.id] = d;
});
}; };
return router; return router;