history: introduce config.json
This commit is contained in:
parent
c0be742802
commit
420a11e72d
5
config.json
Normal file
5
config.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"dataPath": "https://map.luebeck.freifunk.net/data/",
|
||||
"longLinkPercentile": 0.1,
|
||||
"showContact": true
|
||||
}
|
20
history.js
20
history.js
@ -29,6 +29,7 @@ function getJSON(url) {
|
||||
}
|
||||
|
||||
function main() {
|
||||
getJSON("config.json").then( function (config) {
|
||||
var options = { worldCopyJump: true,
|
||||
zoomControl: false
|
||||
}
|
||||
@ -48,12 +49,13 @@ function main() {
|
||||
}
|
||||
|
||||
|
||||
var urls = [ 'https://map.luebeck.freifunk.net/data/nodes.json',
|
||||
'https://map.luebeck.freifunk.net/data/graph.json'
|
||||
var urls = [ config.dataPath + 'nodes.json',
|
||||
config.dataPath + 'graph.json'
|
||||
]
|
||||
|
||||
var p = Promise.all(urls.map(getJSON))
|
||||
p.then(handle_data(map))
|
||||
p.then(handle_data(config, map))
|
||||
})
|
||||
}
|
||||
|
||||
function sort(key, d) {
|
||||
@ -92,7 +94,7 @@ function subtract(a, b) {
|
||||
})
|
||||
}
|
||||
|
||||
function handle_data(map) {
|
||||
function handle_data(config, map) {
|
||||
return function (data) {
|
||||
var nodedict = data[0]
|
||||
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)
|
||||
|
||||
addToList(document.getElementById("newnodes"), "firstseen", newnodes)
|
||||
addToList(document.getElementById("lostnodes"), "lastseen", lostnodes)
|
||||
addToList(document.getElementById("newnodes"), config.showContact, "firstseen", newnodes)
|
||||
addToList(document.getElementById("lostnodes"), config.showContact, "lastseen", lostnodes)
|
||||
|
||||
var graph = data[1].batadv
|
||||
var nodes = data[0].nodes
|
||||
@ -151,7 +153,7 @@ function handle_data(map) {
|
||||
|
||||
longlinks = graph.slice().sort( function (a, b) {
|
||||
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)
|
||||
|
||||
@ -260,7 +262,7 @@ function addToLongLinksList(el, links) {
|
||||
})
|
||||
}
|
||||
|
||||
function addToList(el, tf, list) {
|
||||
function addToList(el, showContact, tf, list) {
|
||||
list.forEach( function (d) {
|
||||
var time = moment(d[tf]).fromNow()
|
||||
|
||||
@ -279,7 +281,7 @@ function addToList(el, tf, list) {
|
||||
td1.appendChild(span)
|
||||
}
|
||||
|
||||
if ("owner" in d.nodeinfo) {
|
||||
if ("owner" in d.nodeinfo && showContact) {
|
||||
var contact = d.nodeinfo.owner.contact
|
||||
td1.appendChild(document.createTextNode(" – " + contact + ""))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user