[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"
}
],
// String or array of data provider are supported
"dataPath": "https://regensburg.freifunk.net/data/",
// Array of data provider are supported
"dataPath": [
"https://regensburg.freifunk.net/data/"
],
"siteName": "Freifunk Regensburg",
"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) {
intNodes = data.nodes.all.map(function (d) {
intNodes = data.nodes.online.map(function (d) {
var e = dictNodes[d.node_id];
if (!e) {
e = {};
@ -208,12 +208,10 @@ define(['d3-selection', 'd3-force', 'd3-zoom', 'd3-drag', 'd3-timer', 'd3-ease',
e.o = d;
return e;
}).filter(function (e) {
return e.o.is_online;
});
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) {
return {
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 });
for (var i = 0; i < intLinks.length; 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 [0, 0, (ZOOM_MIN + 1) / 2];

View File

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

View File

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

View File

@ -23,8 +23,15 @@ define(['moment', 'utils/router', 'leaflet', 'gui', 'helper', 'utils/language'],
var now = moment();
var age = moment(now).subtract(config.maxAge, 'days');
var newnodes = helper.limit('firstseen', age, helper.sortByKey('firstseen', nodes).filter(helper.online));
var lostnodes = helper.limit('lastseen', age, helper.sortByKey('lastseen', nodes).filter(helper.offline));
var online = nodes.filter(function (d) {
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) {
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 {
now: now,
timestamp: moment.utc(timestamp).local(),
nodes: {
all: nodes,
online: online,
offline: offline,
new: newnodes,
lost: lostnodes
},
@ -70,22 +75,14 @@ define(['moment', 'utils/router', 'leaflet', 'gui', 'helper', 'utils/language'],
var language = new Language(config);
var router = new Router(language);
var urls = [];
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');
}
}
config.dataPath.forEach(function (d, i) {
config.dataPath[i] += 'meshviewer.json';
});
language.init(router);
function update() {
return Promise.all(urls.map(helper.getJSON))
return Promise.all(config.dataPath.map(helper.getJSON))
.then(handleData);
}

View File

@ -13,7 +13,7 @@ define(['leaflet', 'rbush', 'helper'],
setData: function (data) {
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
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);
groupLines = L.featureGroup(lines).addTo(map);
var nodesOnline = helper.subtract(data.nodes.all.filter(helper.online), data.nodes.new);
var nodesOffline = helper.subtract(data.nodes.all.filter(helper.offline), data.nodes.lost);
var nodesOnline = helper.subtract(data.nodes.online, data.nodes.new);
var nodesOffline = helper.subtract(data.nodes.offline, data.nodes.lost);
var markersOnline = nodesOnline.filter(helper.hasLocation)
.map(mkMarker(nodeDict, function () {

View File

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

View File

@ -76,7 +76,7 @@ define(['d3-interpolate', 'snabbdom', 'filters/genericnode', 'helper'],
}
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);
function hostnameOfNodeID(nodeid) {

View File

@ -27,9 +27,9 @@ define({
},
sortByKey: function sortByKey(key, d) {
return d.slice().sort(function (a, b) {
return a[key] - b[key];
}).reverse();
return d.sort(function (a, b) {
return b[key] - a[key];
});
},
limit: function limit(key, m, d) {
@ -72,15 +72,6 @@ define({
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) {
return 'location' in d &&
Math.abs(d.location.latitude) < 90 &&
@ -95,7 +86,7 @@ define({
});
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) {
var init = false;
var objects = { nodes: {}, links: {}, nodeDict: {} };
var objects = {};
var targets = [];
var views = {};
var current = {};
@ -16,17 +16,20 @@ define(['Navigo'], function (Navigo) {
}
function gotoNode(d) {
if (d.nodeId in objects.nodes) {
if (objects.nodeDict[d.nodeId]) {
targets.forEach(function (t) {
t.gotoNode(objects.nodes[d.nodeId], objects.nodeDict);
t.gotoNode(objects.nodeDict[d.nodeId], objects.nodeDict);
});
}
}
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) {
t.gotoLink(objects.links[d.linkId]);
t.gotoLink(link);
});
}
}
@ -139,17 +142,7 @@ define(['Navigo'], function (Navigo) {
};
router.setData = function setData(data) {
objects.nodes = {};
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;
});
objects = data;
};
return router;