-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
43 lines (35 loc) · 792 Bytes
/
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
40
41
42
43
'use strict'
const walk = require('discover-db-stations')
// todo: filterStations, filterLines, projection
const createWalker = (startId, nodes, edges, report, cb) => {
const s = walk(startId)
const onNode = (node) => {
nodes.write({
id: node.id,
label: node.name,
metadata: node.coordinates
})
}
const onEdge = (edge) => {
edges.write({
source: edge.from.id,
target: edge.to.id,
relation: edge.line.product || edge.line.mode,
metadata: {
line: edge.line.name,
time: edge.duration
}
})
}
const onError = (err) => {
if (err.isHafasError) return
cb(err)
s.removeListener('error', onError)
}
s.on('error', onError)
s.once('end', cb)
s.on('stats', report)
s.on('data', onNode)
s.on('edge', onEdge)
}
module.exports = createWalker