history: introduce config.json

This commit is contained in:
Nils Schneider 2015-03-20 21:03:20 +01:00
parent c0be742802
commit 420a11e72d
2 changed files with 31 additions and 24 deletions

5
config.json Normal file
View File

@ -0,0 +1,5 @@
{
"dataPath": "https://map.luebeck.freifunk.net/data/",
"longLinkPercentile": 0.1,
"showContact": true
}

View File

@ -29,6 +29,7 @@ function getJSON(url) {
} }
function main() { function main() {
getJSON("config.json").then( function (config) {
var options = { worldCopyJump: true, var options = { worldCopyJump: true,
zoomControl: false zoomControl: false
} }
@ -48,12 +49,13 @@ function main() {
} }
var urls = [ 'https://map.luebeck.freifunk.net/data/nodes.json', var urls = [ config.dataPath + 'nodes.json',
'https://map.luebeck.freifunk.net/data/graph.json' config.dataPath + 'graph.json'
] ]
var p = Promise.all(urls.map(getJSON)) var p = Promise.all(urls.map(getJSON))
p.then(handle_data(map)) p.then(handle_data(config, map))
})
} }
function sort(key, d) { function sort(key, d) {
@ -92,7 +94,7 @@ function subtract(a, b) {
}) })
} }
function handle_data(map) { function handle_data(config, map) {
return function (data) { return function (data) {
var nodedict = data[0] var nodedict = data[0]
var nodes = Object.keys(nodedict.nodes).map(function (key) { return nodedict.nodes[key] }) var nodes = Object.keys(nodedict.nodes).map(function (key) { return nodedict.nodes[key] })
@ -113,8 +115,8 @@ function handle_data(map) {
var onlinenodes = subtract(nodes.filter(online).filter(has_location), newnodes) var onlinenodes = subtract(nodes.filter(online).filter(has_location), newnodes)
addToList(document.getElementById("newnodes"), "firstseen", newnodes) addToList(document.getElementById("newnodes"), config.showContact, "firstseen", newnodes)
addToList(document.getElementById("lostnodes"), "lastseen", lostnodes) addToList(document.getElementById("lostnodes"), config.showContact, "lastseen", lostnodes)
var graph = data[1].batadv var graph = data[1].batadv
var nodes = data[0].nodes var nodes = data[0].nodes
@ -151,7 +153,7 @@ function handle_data(map) {
longlinks = graph.slice().sort( function (a, b) { longlinks = graph.slice().sort( function (a, b) {
return a.distance - b.distance return a.distance - b.distance
}).reverse().slice(0, Math.ceil(0.1 * graph.length)) }).reverse().slice(0, Math.ceil(config.longLinkPercentile * graph.length))
addToLongLinksList(document.getElementById("longlinks"), longlinks) addToLongLinksList(document.getElementById("longlinks"), longlinks)
@ -260,7 +262,7 @@ function addToLongLinksList(el, links) {
}) })
} }
function addToList(el, tf, list) { function addToList(el, showContact, tf, list) {
list.forEach( function (d) { list.forEach( function (d) {
var time = moment(d[tf]).fromNow() var time = moment(d[tf]).fromNow()
@ -279,7 +281,7 @@ function addToList(el, tf, list) {
td1.appendChild(span) td1.appendChild(span)
} }
if ("owner" in d.nodeinfo) { if ("owner" in d.nodeinfo && showContact) {
var contact = d.nodeinfo.owner.contact var contact = d.nodeinfo.owner.contact
td1.appendChild(document.createTextNode(" " + contact + "")) td1.appendChild(document.createTextNode(" " + contact + ""))
} }