-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
39 lines (35 loc) · 1.06 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const fetch = require("node-fetch");
const fs = require("fs-extra");
const NODE_DATA_URL = "https://node-db.netlify.com/nodes.json";
const PRECISION = 4;
var status = "";
fetch(NODE_DATA_URL)
.then(res => res.json())
.then(nodes => {
// Create a map of rounded coordinates and lists of building ids
const nodesByCoords = nodes.reduce((acc, cur) => {
const [lat, lng] = cur.coordinates;
const roundedLat = lat.toFixed(PRECISION);
const roundedLng = lng.toFixed(PRECISION);
const key = `${roundedLat},${roundedLng}`;
status = cur.status
if (typeof status == 'undefined'){
status="";
} else{
status = " "+status
}
acc[key] = acc[key] || [];
acc[key].push(cur.id+status);
return acc;
}, {});
// Get all lists with more than one building
const sameBuilding = [];
Object.keys(nodesByCoords).forEach(key => {
if (nodesByCoords[key].length > 1) {
sameBuilding.push(nodesByCoords[key]);
}
});
// Write to file
fs.outputJSON("./out/sameBuilding.json", sameBuilding, { spaces: 2 });
})
.catch(error => console.log(error));