-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample.js
143 lines (132 loc) · 3.36 KB
/
example.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import slugg from 'slugg'
import {createGetStableOperatorIds as getOperatorIds} from './operator.js'
import {createGetStableStopIds as getStopIds} from './stop.js'
import {createGetStableLineIds as getLineIds} from './line.js'
import {createGetStableTripIds as getTripIds} from './trip.js'
import {createGetStableArrivalDepartureIds as getArrDepIds} from './arrival-departure.js'
const namespace = 'some-data-source'
const normalizeName = slugg
const operator = {
type: 'operator',
id: 'foo',
name: 'Foo Transit',
serviceArea: {
type: 'Feature',
properties: {},
geometry: {
type: 'Polygon',
coordinates: [[
[-81, 41],
[-88, 36],
[-84, 31],
[-80, 33],
[-77, 39],
[-81, 41]
]]
}
}
}
const operatorIds = getOperatorIds(namespace, normalizeName)(operator)
console.log('operatorIds', operatorIds)
const stop = {
type: 'stop',
id: '900000024101:1',
name: 'S Charlottenburg',
location: {
type: 'location',
latitude: 52.5047,
longitude: 13.3037,
},
station: {
type: 'station',
id: '900000024101',
name: 'S Charlottenburg',
location: {
type: 'location',
latitude: 52.504806,
longitude: 13.303846
},
},
}
const stopIds = getStopIds(namespace, normalizeName)(stop)
console.log('stopIds', stopIds)
{
const station = {
...stop.station,
type: 'stop',
}
const stationIds = getStopIds(namespace, normalizeName)(station)
console.log('stationIds', stationIds)
}
const line = {
type: 'line',
id: '18299',
product: 'suburban',
public: true,
name: 'S9',
fahrtNr: '12345',
}
const lineIds = getLineIds(namespace, normalizeName)(line)
console.log('lineIds', lineIds)
// 19:32 S Charlottenburg 2b
// |
// 19:35 U Moritzplatz 3a
// 19:36 U Moritzplatz 3b
// |
// 19:40 S Charlottenburg 4a
const trip = {
id: 'trip-12345',
direction: 'S Spandau',
line,
stopovers: [{
stop,
plannedArrival: null,
plannedArrivalPlatform: null,
plannedDeparture: '2017-12-17T19:32:00+01:00',
plannedDeparturePlatform: '2b',
}, {
stop: {
type: 'station',
id: '900000013101',
name: 'U Moritzplatz',
location: {latitude: 52.503737, longitude: 13.410944},
},
plannedArrival: '2017-12-17T19:35:00+01:00',
plannedArrivalPlatform: '3a',
plannedDeparture: '2017-12-17T19:36:00+01:00',
plannedDeparturePlatform: '3b',
}, {
stop,
plannedArrival: '2017-12-17T19:40:00+01:00',
plannedArrivalPlatform: '4a',
plannedDeparture: null,
plannedDeparturePlatform: null,
}],
}
const depIds = trip.stopovers.map((st) => {
const stopIds = getStopIds(namespace, normalizeName)(st.stop)
return getArrDepIds(stopIds, [[trip.id, 20]], [], lineIds, normalizeName)('departure', st)
})
console.log('depIds', depIds)
const arrIds = trip.stopovers.map((st) => {
const stopIds = getStopIds(namespace, normalizeName)(st.stop)
return getArrDepIds(stopIds, [[trip.id, 20]], [], lineIds, normalizeName)('arrival', st)
})
console.log('arrIds', arrIds)
{
const tripIds = getTripIds(namespace, lineIds, depIds, arrIds)(trip)
console.log('tripIds', tripIds)
}
const dep0 = {
tripId: trip.id,
stop,
plannedWhen: trip.stopovers[0].plannedDeparture,
plannedPlatform: trip.stopovers[0].plannedDeparturePlatform,
line,
fahrtNr: trip.fahrtNr,
direction: trip.direction,
}
const routeIds = []
const tripIds = [[dep0.tripId, 20]]
const getDep0Ids = getArrDepIds(stopIds, tripIds, routeIds, lineIds, normalizeName)
console.log('dep0Ids', getDep0Ids('departure', dep0))