forked from michielbdejong/bogor-angkot-gtfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjoinData.js
79 lines (69 loc) · 2.33 KB
/
joinData.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
var fs = require('fs');
var data = {
majalah: JSON.parse(fs.readFileSync('./build/majalah.json')),
'2menit': JSON.parse(fs.readFileSync('./build/2menit.json')),
lovelybogor: JSON.parse(fs.readFileSync('./build/lovelybogor.json')),
kotabogor: JSON.parse(fs.readFileSync('./build/kotabogor.json')),
enterbogor: JSON.parse(fs.readFileSync('./build/enterbogor.json')),
};
var coordLines = fs.readFileSync('./coords.txt').toString().split('\n').map(line => {
return line.split('\t');
});
var manualLines = fs.readFileSync('./manual-from-transitwand/kota/shapes.txt').toString().split('\n').map(line => {
return line.split(',');
});
var joined = {
places: {},
routes: {},
coords: {},
};
for (var i=0; i<coordLines.length; i++) {
if (coordLines[i].length>2) {
joined.coords[coordLines[i][2]] = coordLines[i];
}
}
function normalize(data) {
if (typeof data === 'string') {
return data.split(' ').join('').toLowerCase();
} else if (Array.isArray(data)) {
return data.map(elt => normalize(elt));
} else {
return data;
}
}
for (var source in data) {
for (var i=0; i < data[source].places.length; i++) {
joined.places[data[source].places[i]] = true;
}
for (var lineNo in data[source].routes) {
if (typeof joined.routes[lineNo] === 'undefined') {
joined.routes[lineNo] = {
name: {},
colour: {},
stops: {}
};
}
joined.routes[lineNo].name[source] = normalize(data[source].routes[lineNo].name);
joined.routes[lineNo].colour[source] = normalize(data[source].routes[lineNo].colour);
joined.routes[lineNo].stops[source] = normalize(data[source].routes[lineNo].stops);
joined.routes[lineNo].stops[`${source}-back`] = normalize(data[source].routes[lineNo].stopsBack);
}
}
for (var i=1; i<manualLines.length; i++) {
var lineNo = manualLines[i][0];
if (typeof joined.routes[lineNo] === 'undefined') {
joined.routes[lineNo] = {
name: {},
colour: {},
stops: {}
};
}
if (typeof joined.routes[lineNo].stops.manual == 'undefined') {
joined.routes[lineNo].stops.manual = [];
}
joined.routes[lineNo].stops.manual.push(`ll_${manualLines[i][1]}_${manualLines[i][2]}`);
}
joined.places = Object.keys(joined.places).sort();
// For creating coords.txt:
// console.log(joined.places.join('\n-6.6\t106.8\t'));
console.log(JSON.stringify(joined, null, 2));