@transportme/load-ptv-gtfs 1.4.2 → 1.4.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/lib/gtfs-parser/GTFSRoute.mjs +22 -4
  2. package/lib/gtfs-parser/GTFSTrip.mjs +23 -1
  3. package/lib/gtfs-parser/readers/GTFSCalendarReader.mjs +1 -0
  4. package/lib/gtfs-parser/readers/line-reader.mjs +1 -6
  5. package/lib/loader/RouteLoader.mjs +4 -2
  6. package/lib/loader/ShapeLoader.mjs +3 -2
  7. package/lib/loader/StopsLoader.mjs +4 -2
  8. package/lib/loader/TripLoader.mjs +13 -4
  9. package/lib/post-processing/set-route-stops.mjs +12 -3
  10. package/package.json +1 -1
  11. package/.github/workflows/unit-test.yml +0 -46
  12. package/test/gtfs-calendar.test.mjs +0 -182
  13. package/test/gtfs-route-loader.test.mjs +0 -208
  14. package/test/gtfs-routes.test.mjs +0 -77
  15. package/test/gtfs-shapes-loader.test.mjs +0 -105
  16. package/test/gtfs-shapes.test.mjs +0 -23
  17. package/test/gtfs-stop-loader.test.mjs +0 -415
  18. package/test/gtfs-stop-times.test.mjs +0 -37
  19. package/test/gtfs-stops.test.mjs +0 -311
  20. package/test/gtfs-trip-loader.test.mjs +0 -188
  21. package/test/gtfs-trips.test.mjs +0 -108
  22. package/test/line-reader.test.mjs +0 -120
  23. package/test/merge-stops-full.test.mjs +0 -118
  24. package/test/merge-stops.test.mjs +0 -376
  25. package/test/new-metro-loader-test.test.mjs +0 -244
  26. package/test/new-tram-format.test.mjs +0 -49
  27. package/test/newer-metro-loader-test.test.mjs +0 -80
  28. package/test/newer-tram-format.test.mjs +0 -67
  29. package/test/ptv-gtfs.test.mjs +0 -106
  30. package/test/sample-data/calendar/calendar.txt +0 -34
  31. package/test/sample-data/calendar/calendar_dates.txt +0 -26
  32. package/test/sample-data/gtfs-splitting/force_unique_stops_bus.txt +0 -7
  33. package/test/sample-data/gtfs-splitting/force_unique_stops_tram.txt +0 -3
  34. package/test/sample-data/gtfs-splitting/general-stores.txt +0 -19
  35. package/test/sample-data/gtfs-splitting/line_reader_test.txt +0 -8
  36. package/test/sample-data/gtfs-splitting/name_overrides.txt +0 -4
  37. package/test/sample-data/gtfs-splitting/sample_stops.txt +0 -20
  38. package/test/sample-data/gtfs-splitting/special_chars_stops_csv.txt +0 -6
  39. package/test/sample-data/gtfs-splitting/stops_without_secondary.txt +0 -6
  40. package/test/sample-data/gtfs-splitting/union_with_spaces.txt +0 -5
  41. package/test/sample-data/gtfs-unzipping/gtfs.zip +0 -0
  42. package/test/sample-data/merge/shapes.txt +0 -1224
  43. package/test/sample-data/merge/stop_times.txt +0 -103
  44. package/test/sample-data/merge/stops.txt +0 -39
  45. package/test/sample-data/merge/trips.txt +0 -7
  46. package/test/sample-data/mtm-rail/stops.txt +0 -4
  47. package/test/sample-data/new-metro/calendar.txt +0 -13
  48. package/test/sample-data/new-metro/calendar_dates.txt +0 -1
  49. package/test/sample-data/new-metro/routes.txt +0 -18
  50. package/test/sample-data/new-metro/simple_stop_test.txt +0 -6
  51. package/test/sample-data/new-metro/stop_times.txt +0 -64
  52. package/test/sample-data/new-metro/stops.txt +0 -139
  53. package/test/sample-data/new-metro/trips.txt +0 -6
  54. package/test/sample-data/new-metro-2/calendar.txt +0 -13
  55. package/test/sample-data/new-metro-2/calendar_dates.txt +0 -1
  56. package/test/sample-data/new-metro-2/routes.txt +0 -2
  57. package/test/sample-data/new-metro-2/stop_times.txt +0 -5
  58. package/test/sample-data/new-metro-2/stops.txt +0 -9
  59. package/test/sample-data/new-metro-2/trips.txt +0 -2
  60. package/test/sample-data/new-tram/routes.txt +0 -25
  61. package/test/sample-data/new-tram/stops.txt +0 -5
  62. package/test/sample-data/new-tram-2/routes.txt +0 -25
  63. package/test/sample-data/new-tram-2/stops.txt +0 -8
  64. package/test/sample-data/one_line.csv +0 -2
  65. package/test/sample-data/parent-stop/multi_stop.txt +0 -4
  66. package/test/sample-data/parent-stop/stops.txt +0 -15
  67. package/test/sample-data/routes/agency.txt +0 -12
  68. package/test/sample-data/routes/bad_routes.txt +0 -4
  69. package/test/sample-data/routes/metro_bus_routes.txt +0 -4
  70. package/test/sample-data/routes/metro_lines.txt +0 -8
  71. package/test/sample-data/routes/regional_bus_routes.txt +0 -7
  72. package/test/sample-data/routes/vline.txt +0 -7
  73. package/test/sample-data/routes/west_gipp_transit.txt +0 -20
  74. package/test/sample-data/shapes/shapes.txt +0 -89
  75. package/test/sample-data/shapes/stop_times.txt +0 -9
  76. package/test/sample-data/shapes/stops.txt +0 -4
  77. package/test/sample-data/shapes/trips.txt +0 -4
  78. package/test/sample-data/stop-data/name-overrides.json +0 -25
  79. package/test/sample-data/stop-data/unique-stops.json +0 -1
  80. package/test/sample-data/suburbs.json +0 -77
  81. package/test/sample-data/trips/bus_trips.txt +0 -5
  82. package/test/sample-data/trips/stop_times.txt +0 -29
  83. package/test/sample-data/trips/stops.txt +0 -93
  84. package/test/sample-data/trips/trips.txt +0 -5
  85. package/test/utils-test.mjs +0 -12
@@ -1,311 +0,0 @@
1
- import { expect } from 'chai'
2
- import GTFSStopsReader from '../lib/gtfs-parser/readers/GTFSStopsReader.mjs'
3
- import path from 'path'
4
- import url from 'url'
5
- import suburbs from './sample-data/suburbs.json' with { type: 'json' }
6
-
7
- const __filename = url.fileURLToPath(import.meta.url)
8
- const __dirname = path.dirname(__filename)
9
-
10
- const stopsFile = path.join(__dirname, 'sample-data', 'gtfs-splitting', 'line_reader_test.txt')
11
-
12
- const parentStopsFile = path.join(__dirname, 'sample-data', 'parent-stop', 'stops.txt')
13
-
14
- let stopInput = {
15
- stop_id: '1000',
16
- stop_name: 'Dole Ave/Cheddar Rd (Reservoir)',
17
- stop_lat: '-37.7007748061827',
18
- stop_lon: '145.018951051008'
19
- }
20
-
21
- let stopInput2 = {
22
- stop_id: '10001',
23
- stop_name: 'Rex St/Taylors Rd (Kings Park)',
24
- stop_lat: '-37.7269752097338',
25
- stop_lon: '144.776152425766'
26
- }
27
-
28
- let stopInput3 = {
29
- stop_id: '13486',
30
- stop_name: 'Narre Warren, Fountain Gate Primary School/Victoria Rd',
31
- stop_lat: '-38.0093755011572',
32
- stop_lon: '145.296182027229'
33
- }
34
-
35
- describe('The GTFSStopReader class', () => {
36
- describe('The initialProcess function', () => {
37
- it('Should take in the raw CSV line and process it', () => {
38
- let stopData = new GTFSStopsReader('', suburbs).processEntity(stopInput)
39
-
40
- expect(stopData.originalName).to.equal(stopInput.stop_name)
41
- expect(stopData.stopGTFSID).to.equal(stopInput.stop_id)
42
- expect(stopData.location).to.deep.equal({
43
- type: 'Point',
44
- coordinates: [145.018951051008, -37.7007748061827]
45
- })
46
- })
47
-
48
- it('Should populate the suburb and stop number', () => {
49
- let stopData = new GTFSStopsReader('', suburbs).processEntity({
50
- ...stopInput2,
51
- stop_name: '51a-Rex St/Taylors Rd (Kings Park)'
52
- })
53
-
54
- expect(stopData.suburb).to.equal('Kings Park')
55
- expect(stopData.stopNumber).to.equal('51A')
56
- })
57
-
58
- it('Should return the parent stop data if available', async () => {
59
- let stopReader = new GTFSStopsReader(parentStopsFile, suburbs)
60
- await stopReader.open()
61
-
62
- let stopData = await stopReader.getNextEntity()
63
- expect(stopData.rawStopName).to.equal('Clifton Hill Station')
64
- expect(stopData.stopGTFSID).to.equal('14330')
65
- expect(stopData.parentStopGTFSID).to.equal('vic:rail:CHL')
66
- })
67
-
68
- it('Should allow a custom stop suburb hook', async () => {
69
- let stopReader = new GTFSStopsReader(parentStopsFile, suburbs, () => 'Test')
70
- await stopReader.open()
71
-
72
- let stopData = await stopReader.getNextEntity()
73
- expect(stopData.rawStopName).to.equal('Clifton Hill Station')
74
- expect(stopData.suburb).to.equal('Test')
75
- })
76
- })
77
-
78
- describe('The getNextEntity function', () => {
79
- it('Should read the CSV file and return the next stop', async () => {
80
- let stopReader = new GTFSStopsReader(stopsFile)
81
- await stopReader.open()
82
-
83
- let stopData = await stopReader.getNextEntity()
84
-
85
- expect(stopData.rawStopName).to.equal('Dole Ave/Cheddar Rd')
86
- expect(stopData.stopGTFSID).to.equal('1000')
87
- })
88
- })
89
-
90
- describe('The available function', () => {
91
- it('Should return true if there is more data, and false otherwise', async () => {
92
- let stopReader = new GTFSStopsReader(stopsFile)
93
- await stopReader.open()
94
-
95
- for (let i = 0; i < 6; i++) await stopReader.getNextEntity()
96
- expect(stopReader.available()).to.be.true
97
-
98
- await stopReader.getNextEntity()
99
- expect(stopReader.available()).to.be.false
100
- })
101
- })
102
- })
103
-
104
- describe('The GTFSStop class', () => {
105
- describe('The requiresSuburb function', () => {
106
- it('Should return false if the stop name already has a suburb', async () => {
107
- let stopData = new GTFSStopsReader('', suburbs).processEntity(stopInput)
108
- expect(stopData.requiresSuburb()).to.be.false
109
- })
110
-
111
- it('Should return false if the stop name is missing the suburb', async () => {
112
- let stopData = new GTFSStopsReader('', suburbs).processEntity({
113
- ...stopInput,
114
- stop_name: 'Dole Ave/Cheddar Rd'
115
- })
116
- expect(stopData.requiresSuburb()).to.be.true
117
- })
118
- })
119
-
120
- describe('The getSuburbFromName function', () => {
121
- it('Should extract the stop suburb from its name in brackets', () => {
122
- let stopData = new GTFSStopsReader('', suburbs).processEntity(stopInput)
123
- expect(stopData.getSuburbFromName()).to.equal('Reservoir')
124
- })
125
-
126
- it('Should extract the stop suburb from its name if it appears at the front', () => {
127
- let stopData = new GTFSStopsReader('', suburbs).processEntity(stopInput3)
128
- expect(stopData.suburbIsInFront()).to.be.true
129
- expect(stopData.getSuburbFromName()).to.equal('Narre Warren')
130
- })
131
- })
132
-
133
- describe('The getSuburbState function', () => {
134
- it('Should extract the state form a suburb in the form (Suburb (State))', () => {
135
- let stopName = 'Albury Botanic Gardens/Wodonga Pl (Albury (NSW))'
136
- let stopData = new GTFSStopsReader('', suburbs).processEntity({
137
- ...stopInput,
138
- stop_name: stopName
139
- })
140
-
141
- expect(stopData.getSuburbState(stopName.lastIndexOf('('))).to.equal('NSW')
142
- })
143
- })
144
-
145
- it('Should process interstate suburbs in the format (Suburb (State))', () => {
146
- let stopData = new GTFSStopsReader('', suburbs).processEntity({
147
- ...stopInput,
148
- stop_name: 'Albury Botanic Gardens/Wodonga Pl (Albury (NSW))'
149
- })
150
- expect(stopData.getSuburbFromName()).to.equal('Albury, NSW')
151
- })
152
-
153
- it('Should process interstate suburbs in the format (Suburb (Local Area - State))', () => {
154
- let stopData = new GTFSStopsReader('', suburbs).processEntity({
155
- ...stopInput,
156
- stop_name: 'Emma Way/Wright St (Glenroy (Albury - NSW))'
157
- })
158
- expect(stopData.getSuburbFromName()).to.equal('Glenroy, NSW')
159
- })
160
-
161
- it('Should expand St in the suburb name', () => {
162
- let stopData = new GTFSStopsReader('', suburbs).processEntity({
163
- ...stopInput,
164
- stop_name: 'Dundas St/Market St (St Arnaud)'
165
- })
166
- expect(stopData.getSuburbFromName()).to.equal('St. Arnaud')
167
- })
168
-
169
- it('Should expand Mt in the suburb name', () => {
170
- let stopData = new GTFSStopsReader('', suburbs).processEntity({
171
- ...stopInput,
172
- stop_name: 'Tourist Information Centre/Jubilee Hwy East (Mt Gambier (SA))'
173
- })
174
- expect(stopData.getSuburbFromName()).to.equal('Mount Gambier, SA')
175
- })
176
-
177
- describe('The getSuburbFromLocation function', () => {
178
- it('Should expand St in the suburb name', () => {
179
- let stopData = new GTFSStopsReader('', suburbs).processEntity({
180
- stop_id: '912',
181
- stop_name: 'Princes St/Barkly St',
182
- stop_lat: '-37.8597466731382',
183
- stop_lon: '144.98247799877'
184
- })
185
- expect(stopData.getSuburbFromLocation(suburbs)).to.equal('St. Kilda')
186
- })
187
-
188
- it('Should return a generic Interstate suburb if it cannot identify the suburb', () => {
189
- let stopData = new GTFSStopsReader('', suburbs).processEntity({
190
- stop_id: '20815',
191
- stop_name: '85 Franklin St',
192
- stop_lat: '-34.9274852283649',
193
- stop_lon: '138.595751207359'
194
- })
195
- expect(stopData.getSuburbFromLocation(suburbs)).to.equal('Interstate')
196
- })
197
- })
198
-
199
- describe('The getStopNameWithoutSuburb function', () => {
200
- it('Should strip the suburb from the stop name if the suburb appears behind', () => {
201
- let stopData = new GTFSStopsReader('', suburbs).processEntity(stopInput)
202
-
203
- expect(stopData.getStopNameWithoutSuburb()).to.equal('Dole Ave/Cheddar Rd')
204
- })
205
-
206
- it('Should strip the suburb from the stop name for NSW/SA stops', () => {
207
- let stopName = 'Albury Railway Station (Albury (NSW))'
208
- let stopData = new GTFSStopsReader('', suburbs).processEntity({
209
- ...stopInput,
210
- stop_name: stopName
211
- })
212
-
213
- expect(stopData.getStopNameWithoutSuburb()).to.equal('Albury Railway Station')
214
- })
215
-
216
- it('Should strip the suburb from the stop name if the suburb is in front', () => {
217
- let stopData = new GTFSStopsReader('', suburbs).processEntity(stopInput3)
218
-
219
- expect(stopData.getStopNameWithoutSuburb()).to.equal('Fountain Gate Primary School/Victoria Rd')
220
- })
221
- })
222
-
223
- describe('The matchStopNumber function', () => {
224
- it('Should match stop numbers in the format XXX-STOPNAME', () => {
225
- let stopData = new GTFSStopsReader('', suburbs).processEntity({
226
- ...stopInput,
227
- stop_name: '125-Yuille St/Centenary Ave (Melton)'
228
- })
229
-
230
- expect(stopData.matchStopNumber()).to.deep.equal({
231
- stopNumber: '125',
232
- stopName: 'Yuille St/Centenary Ave'
233
- })
234
- })
235
-
236
- // Can randomly happen when PTV exports the data without suburb names or secondary street names
237
- // See 25 Jan 2021 archive
238
- // Seems to be caused when they set some flag incorrectly as this seems to match the stop names on the printed timetables.
239
- // Weird huh.
240
- it('Should match stop numbers in the format STOPNAME - Stop XXX', () => {
241
- let stopData = new GTFSStopsReader('', suburbs).processEntity({
242
- ...stopInput,
243
- stop_name: 'Yuille St - Stop D99'
244
- })
245
-
246
- expect(stopData.matchStopNumber()).to.deep.equal({
247
- stopNumber: 'D99',
248
- stopName: 'Yuille St'
249
- })
250
- })
251
-
252
- it('Should ensure the stop numbers are all uppercase', () => {
253
- let stopData = new GTFSStopsReader('', suburbs).processEntity({
254
- ...stopInput,
255
- stop_name: '125a-Southbank Tram Depot (South Melbourne)'
256
- })
257
-
258
- expect(stopData.matchStopNumber()).to.deep.equal({
259
- stopNumber: '125A',
260
- stopName: 'Southbank Tram Depot'
261
- })
262
- })
263
-
264
- it('Should return null if there is no stop number', () => {
265
- let stopData = new GTFSStopsReader('', suburbs).processEntity({
266
- ...stopInput,
267
- stop_name: 'Southbank Tram Depot (South Melbourne)'
268
- })
269
-
270
- expect(stopData.matchStopNumber()).to.deep.equal({
271
- stopNumber: null,
272
- stopName: 'Southbank Tram Depot'
273
- })
274
- })
275
-
276
- it('Should not match street numbers spanning multiple units', () => {
277
- let stopData = new GTFSStopsReader('', suburbs).processEntity({
278
- ...stopInput,
279
- stop_name: '227-243 Wellington Rd (Mulgrave)'
280
- })
281
-
282
- expect(stopData.matchStopNumber()).to.deep.equal({
283
- stopNumber: null,
284
- stopName: '227-243 Wellington Rd'
285
- })
286
- })
287
- })
288
-
289
- describe('The getFullStopName function', () => {
290
- it('Should expand the stop name', () => {
291
- let stopData = new GTFSStopsReader('', suburbs).processEntity(stopInput2)
292
- expect(stopData.getFullStopName()).to.equal('Rex Street/Taylors Road')
293
- })
294
-
295
- it('Should handle stops with only a primary name', () => {
296
- let stopData = new GTFSStopsReader('', suburbs).processEntity({
297
- ...stopInput,
298
- stop_name: 'Knox City SC (Knoxfield)'
299
- })
300
- expect(stopData.getFullStopName()).to.equal('Knox City Shopping Centre')
301
- })
302
-
303
- it('Should handle the direction appearing as well', () => {
304
- let stopData = new GTFSStopsReader('', suburbs).processEntity({
305
- ...stopInput,
306
- stop_name: 'Newman Cres (north side)/east of Pechell St (Made Up Suburb)'
307
- })
308
- expect(stopData.getFullStopName()).to.equal('Newman Crescent - North/Pechell Street - East')
309
- })
310
- })
311
- })
@@ -1,188 +0,0 @@
1
- import { expect } from 'chai'
2
- import path from 'path'
3
- import url from 'url'
4
- import { TRANSIT_MODES } from '../lib/constants.mjs'
5
- import { LokiDatabaseConnection } from '@transportme/database'
6
- import StopsLoader from '../lib/loader/StopsLoader.mjs'
7
- import RouteLoader from '../lib/loader/RouteLoader.mjs'
8
- import TripLoader from '../lib/loader/TripLoader.mjs'
9
- import suburbs from './sample-data/suburbs.json' with { type: 'json' }
10
-
11
- const __filename = url.fileURLToPath(import.meta.url)
12
- const __dirname = path.dirname(__filename)
13
-
14
- const routesFile = path.join(__dirname, 'sample-data', 'routes', 'metro_lines.txt')
15
- const agencyFile = path.join(__dirname, 'sample-data', 'routes', 'agency.txt')
16
-
17
- const calendarFile = path.join(__dirname, 'sample-data', 'calendar', 'calendar.txt')
18
- const calendarDatesFile = path.join(__dirname, 'sample-data', 'calendar', 'calendar_dates.txt')
19
-
20
- const stopsFile = path.join(__dirname, 'sample-data', 'trips', 'stops.txt')
21
- const stopTimesFile = path.join(__dirname, 'sample-data', 'trips', 'stop_times.txt')
22
- const tripsFile = path.join(__dirname, 'sample-data', 'trips', 'trips.txt')
23
-
24
- describe('The TripLoader class', () => {
25
- it('Should process the trip and add it to the database', async () => {
26
- let database = new LokiDatabaseConnection('test-db')
27
- let stops = await database.createCollection('gtfs-stops')
28
- let routes = await database.createCollection('gtfs-routes')
29
- let trips = await database.createCollection('gtfs-gtfs timetables')
30
-
31
- let stopLoader = new StopsLoader(stopsFile, suburbs, TRANSIT_MODES.metroTrain, database)
32
- await stopLoader.loadStops()
33
-
34
- let routeLoader = new RouteLoader(routesFile, agencyFile, TRANSIT_MODES.metroTrain, database)
35
- await routeLoader.loadRoutes()
36
-
37
- let routeIDMap = routeLoader.getRouteIDMap()
38
-
39
- let tripLoader = new TripLoader({
40
- tripsFile, stopTimesFile,
41
- calendarFile, calendarDatesFile
42
- }, TRANSIT_MODES.metroTrain, database)
43
- await tripLoader.loadTrips({
44
- routeIDMap
45
- })
46
-
47
- let trip = await trips.findDocument({ tripID: '02-ALM--12-T5-2000' })
48
- expect(trip).to.not.be.null
49
-
50
- expect(trip.routeName).to.equal('Alamein')
51
- expect(trip.routeNumber).to.be.null
52
- expect(trip.operationDays.length).to.equal(12)
53
- expect(trip.operationDays[0]).to.equal('20241123')
54
-
55
- expect(trip.shapeID).to.equal('2-ALM-vpt-1.1.R')
56
- expect(trip.block).to.be.null
57
- expect(trip.gtfsDirection).to.equal(1)
58
-
59
- expect(trip.stopTimings.length).to.equal(7)
60
- expect(trip.stopTimings[0].stopName).to.equal('Alamein Railway Station')
61
- expect(trip.stopTimings[0].stopGTFSID).to.equal('vic:rail:ALM')
62
- expect(trip.stopTimings[0].arrivalTime).to.be.null
63
- expect(trip.stopTimings[0].arrivalTimeMinutes).to.be.null
64
- expect(trip.stopTimings[0].stopConditions.dropoff).to.equal(1)
65
- expect(trip.stopTimings[0].stopConditions.pickup).to.equal(0)
66
- expect(trip.stopTimings[0].departureTime).to.equal('04:57')
67
- expect(trip.stopTimings[0].departureTimeMinutes).to.equal(4 * 60 + 57)
68
- expect(trip.stopTimings[0].platform).to.equal('1')
69
-
70
- expect(trip.stopTimings[5].stopName).to.equal('Riversdale Railway Station')
71
- expect(trip.stopTimings[5].stopGTFSID).to.equal('vic:rail:RIV')
72
- expect(trip.stopTimings[5].platform).to.equal('1')
73
-
74
- expect(trip.stopTimings[6].stopName).to.equal('Camberwell Railway Station')
75
- expect(trip.stopTimings[6].stopGTFSID).to.equal('vic:rail:CAM')
76
- expect(trip.stopTimings[6].arrivalTime).to.equal('05:08')
77
- expect(trip.stopTimings[6].arrivalTimeMinutes).to.equal(5 * 60 + 8)
78
- expect(trip.stopTimings[6].departureTime).to.be.null
79
- expect(trip.stopTimings[6].departureTimeMinutes).to.be.null
80
- expect(trip.stopTimings[6].stopConditions.dropoff).to.equal(0)
81
- expect(trip.stopTimings[6].stopConditions.pickup).to.equal(1)
82
- expect(trip.stopTimings[6].platform).to.equal('1')
83
-
84
- expect(trip.origin).to.equal('Alamein Railway Station')
85
- expect(trip.destination).to.equal('Camberwell Railway Station')
86
-
87
- expect(trip.departureTime).to.equal('04:57')
88
- expect(trip.destinationArrivalTime).to.equal('05:08')
89
- })
90
-
91
- it('It should return a mapping of Shape IDs to Route IDs', async () => {
92
- let database = new LokiDatabaseConnection('test-db')
93
- let stops = await database.createCollection('gtfs-stops')
94
- let routes = await database.createCollection('gtfs-routes')
95
- let trips = await database.createCollection('gtfs-gtfs timetables')
96
-
97
- let stopLoader = new StopsLoader(stopsFile, suburbs, TRANSIT_MODES.metroTrain, database)
98
- await stopLoader.loadStops()
99
-
100
- let routeLoader = new RouteLoader(routesFile, agencyFile, TRANSIT_MODES.metroTrain, database)
101
- await routeLoader.loadRoutes()
102
-
103
- let routeIDMap = routeLoader.getRouteIDMap()
104
-
105
- let tripLoader = new TripLoader({
106
- tripsFile, stopTimesFile,
107
- calendarFile, calendarDatesFile
108
- }, TRANSIT_MODES.metroTrain, database)
109
-
110
- await tripLoader.loadTrips({ routeIDMap })
111
- let shapeIDMap = tripLoader.getShapeIDMap()
112
-
113
- expect(shapeIDMap['2-ALM-vpt-1.1.R']).to.equal('2-ALM')
114
- })
115
-
116
- it('Should return a mapping of Route + GTFS Direction ID to PTV Direction Names', async () => {
117
- let database = new LokiDatabaseConnection('test-db')
118
- let stops = await database.createCollection('gtfs-stops')
119
- let routes = await database.createCollection('gtfs-routes')
120
- let trips = await database.createCollection('gtfs-gtfs timetables')
121
-
122
- let stopLoader = new StopsLoader(stopsFile, suburbs, TRANSIT_MODES.metroTrain, database)
123
- await stopLoader.loadStops()
124
-
125
- let routeLoader = new RouteLoader(routesFile, agencyFile, TRANSIT_MODES.metroTrain, database)
126
- await routeLoader.loadRoutes()
127
-
128
- let routeIDMap = routeLoader.getRouteIDMap()
129
-
130
- let tripLoader = new TripLoader({
131
- tripsFile, stopTimesFile,
132
- calendarFile, calendarDatesFile
133
- }, TRANSIT_MODES.metroTrain, database)
134
-
135
- await tripLoader.loadTrips({ routeIDMap })
136
- let directionIDMap = tripLoader.getDirectionIDMap()
137
-
138
- expect(directionIDMap).to.deep.equal({
139
- '2-ALM': { 'Alamein': 0, 'Camberwell': 1 }
140
- })
141
- })
142
-
143
- it('Should return a mapping stop services', async () => {
144
- let database = new LokiDatabaseConnection('test-db')
145
- let stops = await database.createCollection('gtfs-stops')
146
- let routes = await database.createCollection('gtfs-routes')
147
- let trips = await database.createCollection('gtfs-gtfs timetables')
148
-
149
- let stopLoader = new StopsLoader(stopsFile, suburbs, TRANSIT_MODES.metroTrain, database)
150
- await stopLoader.loadStops()
151
-
152
- let routeLoader = new RouteLoader(routesFile, agencyFile, TRANSIT_MODES.metroTrain, database)
153
- await routeLoader.loadRoutes()
154
-
155
- let routeIDMap = routeLoader.getRouteIDMap()
156
-
157
- let tripLoader = new TripLoader({
158
- tripsFile, stopTimesFile,
159
- calendarFile, calendarDatesFile
160
- }, TRANSIT_MODES.metroTrain, database)
161
-
162
- await tripLoader.loadTrips({ routeIDMap })
163
-
164
- let stopServicesMap = tripLoader.getStopServicesMap()
165
-
166
- expect(stopServicesMap['vic:rail:ALM'].services).to.deep.equal([{
167
- routeGTFSID: '2-ALM',
168
- gtfsDirection: 1,
169
- routeNumber: null
170
- }, {
171
- routeGTFSID: '2-ALM',
172
- gtfsDirection: 0,
173
- routeNumber: null
174
- }])
175
-
176
- expect(stopServicesMap['vic:rail:ALM'].screenServices).to.deep.equal([{
177
- routeGTFSID: '2-ALM',
178
- gtfsDirection: 1,
179
- routeNumber: null
180
- }])
181
-
182
- expect(stopServicesMap['vic:rail:CAM'].screenServices).to.deep.equal([{
183
- routeGTFSID: '2-ALM',
184
- gtfsDirection: 0,
185
- routeNumber: null
186
- }])
187
- })
188
- })
@@ -1,108 +0,0 @@
1
- import { expect } from 'chai'
2
- import path from 'path'
3
- import url from 'url'
4
- import GTFSCalendar from '../lib/gtfs-parser/GTFSCalendar.mjs'
5
- import GTFSTrip, { SmartrakTrip } from '../lib/gtfs-parser/GTFSTrip.mjs'
6
- import GTFSTripReader from '../lib/gtfs-parser/readers/GTFSTripReader.mjs'
7
- import { TRANSIT_MODES } from '../lib/constants.mjs'
8
-
9
- const __filename = url.fileURLToPath(import.meta.url)
10
- const __dirname = path.dirname(__filename)
11
-
12
- const tripsFile = path.join(__dirname, 'sample-data', 'trips', 'trips.txt')
13
- const busTripsFile = path.join(__dirname, 'sample-data', 'trips', 'bus_trips.txt')
14
- const calendar = new GTFSCalendar({
15
- id: 'T1',
16
- startDay: '20241122',
17
- endDay: '20241129',
18
- daysOfWeek: ["0","0","0","0","1","1","0"]
19
- })
20
-
21
- describe('The GTFSTrip class', () => {
22
- it('Should process the skeleton trip data and populate the operation days', () => {
23
- // route_id,service_id,trip_id,shape_id,trip_headsign,direction_id,block_id
24
- // "6-452-mjp-1","T0_16","1.T0.6-452-mjp-1.1.H","6-452-mjp-1.1.H","Eynesbury","0",""
25
- let trip = new GTFSTrip({
26
- routeGTFSID: '6-452',
27
- calendar,
28
- id: '1.T0.6-452-mjp-1.1.H',
29
- shapeID: '6-452-mjp-1.1.H',
30
- headsign: 'Eynesbury',
31
- direction: '0',
32
- block: ''
33
- })
34
-
35
- expect(trip.getOperationDays()).to.have.members([
36
- '20241122', '20241123', '20241129'
37
- ])
38
- })
39
- })
40
-
41
- describe('The GTFSTripReader class', () => {
42
- it('Should read the trips.txt file and return a GTFSTrip object', async () => {
43
- let calendars = {
44
- 'T2_2': new GTFSCalendar({
45
- id: 'T2_2',
46
- startDay: '20241122',
47
- endDay: '20241122',
48
- daysOfWeek: ["0","0","0","0","1","0","0"]
49
- })
50
- }
51
-
52
- let routeMappings = { 'aus:vic:vic-02-ALM:': '2-ALM' }
53
-
54
- let reader = new GTFSTripReader(tripsFile, calendars, routeMappings, TRANSIT_MODES.metroTrain)
55
- await reader.open()
56
-
57
- let trip = await reader.getNextEntity()
58
-
59
- expect(trip.getTripID()).to.equal('02-ALM--12-T5-2000')
60
- expect(trip.getRouteGTFSID()).to.equal('2-ALM')
61
- expect(trip.getHeadsign()).to.equal('Camberwell')
62
- expect(trip.getOperationDays()).to.deep.equal(['20241122'])
63
- })
64
-
65
- it('Should return a Smartrak bus trip instance where appropriate', async () => {
66
- let calendars = {
67
- 'T2_2': new GTFSCalendar({
68
- id: 'T2_2',
69
- startDay: '20241122',
70
- endDay: '20241122',
71
- daysOfWeek: ["0","0","0","0","1","0","0"]
72
- })
73
- }
74
-
75
- let routeMappings = { '43-490-aus-1': '4-490', '6-wr9-mjp-1': '6-wr9' }
76
-
77
- let reader = new GTFSTripReader(busTripsFile, calendars, routeMappings, TRANSIT_MODES.bus)
78
- await reader.open()
79
-
80
- let trip = await reader.getNextEntity()
81
-
82
- expect(trip).to.be.instanceOf(SmartrakTrip)
83
- expect(trip.getTripID()).to.equal('43-490--1-MF4-1111914')
84
- expect(trip.getRouteGTFSID()).to.equal('4-490')
85
- expect(trip.getDepotID()).to.equal(43)
86
-
87
- trip = await reader.getNextEntity()
88
-
89
- expect(trip).to.not.be.instanceOf(SmartrakTrip)
90
- expect(trip.getTripID()).to.equal('5.T3.6-wr9-mjp-1.2.R')
91
- expect(trip.getRouteGTFSID()).to.equal('6-wr9')
92
-
93
- // EXPERIMENTAL DATA:
94
- trip = await reader.getNextEntity()
95
-
96
- expect(trip).to.be.instanceOf(SmartrakTrip)
97
- expect(trip.getTripID()).to.equal('58-G01--1-MF1-9942214')
98
- expect(trip.getDepotID()).to.equal(58)
99
- // expect(trip.getRouteGTFSID()).to.equal('6-G01') // Not entirely sure how to handle duplicates
100
-
101
- trip = await reader.getNextEntity()
102
-
103
- expect(trip).to.be.instanceOf(SmartrakTrip)
104
- expect(trip.getTripID()).to.equal('57-83--1-MF2-57586310')
105
- expect(trip.getDepotID()).to.equal(57)
106
- // expect(trip.getRouteGTFSID()).to.equal('6-083')
107
- })
108
- })