@transportme/load-ptv-gtfs 1.1.1 → 1.1.3

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.
package/index.mjs CHANGED
@@ -15,6 +15,15 @@ import GTFSTrip from './lib/gtfs-parser/GTFSTrip.mjs'
15
15
  import setRouteStops from './lib/post-processing/set-route-stops.mjs'
16
16
  import setStopServices from './lib/post-processing/set-stop-services.mjs'
17
17
 
18
+ import GTFSAgencyReader from './lib/gtfs-parser/readers/GTFSAgencyReader.mjs'
19
+ import GTFSCalendarDateReader from './lib/gtfs-parser/readers/GTFSCalendarDatesReader.mjs'
20
+ import GTFSCalendarReader from './lib/gtfs-parser/readers/GTFSCalendarReader.mjs'
21
+ import GTFSRouteReader from './lib/gtfs-parser/readers/GTFSRouteReader.mjs'
22
+ import GTFSShapeReader from './lib/gtfs-parser/readers/GTFSShapeReader.mjs'
23
+ import GTFSStopsReader from './lib/gtfs-parser/readers/GTFSStopsReader.mjs'
24
+ import GTFSStopTimesReader from './lib/gtfs-parser/readers/GTFSStopTimesReader.mjs'
25
+ import GTFSTripReader from './lib/gtfs-parser/readers/GTFSTripReader.mjs'
26
+
18
27
  const GTFSTypes = {
19
28
  GTFSAgency, GTFSCalendar, GTFSCalendarDate,
20
29
  GTFSRoute, GTFSShape, GTFSShapePoint,
@@ -22,9 +31,15 @@ const GTFSTypes = {
22
31
  GTFSStopTime, GTFSTrip
23
32
  }
24
33
 
34
+ const GTFSReaders = {
35
+ GTFSAgencyReader, GTFSCalendarDateReader, GTFSCalendarReader,
36
+ GTFSRouteReader, GTFSShapeReader, GTFSStopsReader,
37
+ GTFSStopTimesReader, GTFSTripReader
38
+ }
39
+
25
40
  export {
26
41
  RouteLoader, ShapeLoader,
27
42
  StopsLoader, TripLoader,
28
- GTFSTypes,
43
+ GTFSTypes, GTFSReaders,
29
44
  setRouteStops, setStopServices
30
45
  }
@@ -96,7 +96,14 @@ export default class StopsLoader {
96
96
  }
97
97
 
98
98
  async mergeStops(matchingStop, stopData) {
99
- matchingStop.bays.push(stopData.bays[0])
99
+ let newBay = stopData.bays[0]
100
+ let hasIdenticalBay = matchingStop.bays.some(bay =>
101
+ bay.mode === newBay.mode && bay.stopGTFSID === newBay.stopGTFSID
102
+ )
103
+
104
+ if (hasIdenticalBay) return
105
+
106
+ matchingStop.bays.push(newBay)
100
107
 
101
108
  this.updateStopSuburb(matchingStop)
102
109
  this.updateStopName(matchingStop)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@transportme/load-ptv-gtfs",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
4
4
  "description": "",
5
5
  "main": "index.mjs",
6
6
  "scripts": {
@@ -220,4 +220,74 @@ describe('The GTFS Stops Loader', () => {
220
220
  expect(huntingdale).to.not.be.null
221
221
  expect(huntingdale.stopName).to.equal('Huntingdale Railway Station')
222
222
  })
223
+
224
+ it('Should not load duplicate stops with the same mode in', async () => {
225
+ let database = new LokiDatabaseConnection('test-db')
226
+ let stops = await database.createCollection('stops')
227
+
228
+ let loader = new StopsLoader(specialHeader, suburbs, TRANSIT_MODES.bus, database)
229
+ let reader = new GTFSStopsReader('')
230
+
231
+ await loader.loadStop(reader.processEntity({
232
+ stop_id: '51586',
233
+ stop_name: 'Huntingdale Station/Haughton Road (Oakleigh)',
234
+ stop_lat: '-37.9111998619901',
235
+ stop_lon: '145.103064853799'
236
+ }))
237
+
238
+ let huntingdale = await stops.findDocument({
239
+ 'bays.stopGTFSID': '51586'
240
+ })
241
+ expect(huntingdale.bays.length).to.equal(1)
242
+ expect(huntingdale.bays[0].stopGTFSID).to.equal('51586')
243
+
244
+ await loader.loadStop(reader.processEntity({
245
+ stop_id: '51586',
246
+ stop_name: 'Huntingdale Station/Haughton Road (Oakleigh)',
247
+ stop_lat: '-37.9111998619901',
248
+ stop_lon: '145.103064853799'
249
+ }))
250
+
251
+ huntingdale = await stops.findDocument({
252
+ 'bays.stopGTFSID': '51586'
253
+ })
254
+ expect(huntingdale.bays.length).to.equal(1)
255
+ })
256
+
257
+ it('Should load duplicate stops with the different mode in', async () => {
258
+ let database = new LokiDatabaseConnection('test-db')
259
+ let stops = await database.createCollection('stops')
260
+
261
+ let busLoader = new StopsLoader(specialHeader, suburbs, TRANSIT_MODES.bus, database)
262
+ let coachLoader = new StopsLoader(specialHeader, suburbs, TRANSIT_MODES.regionalCoach, database)
263
+ let reader = new GTFSStopsReader('')
264
+
265
+ await busLoader.loadStop(reader.processEntity({
266
+ stop_id: '51586',
267
+ stop_name: 'Huntingdale Station/Haughton Road (Oakleigh)',
268
+ stop_lat: '-37.9111998619901',
269
+ stop_lon: '145.103064853799'
270
+ }))
271
+
272
+ let huntingdale = await stops.findDocument({
273
+ 'bays.stopGTFSID': '51586'
274
+ })
275
+ expect(huntingdale.bays.length).to.equal(1)
276
+ expect(huntingdale.bays[0].stopGTFSID).to.equal('51586')
277
+ expect(huntingdale.bays[0].mode).to.equal(TRANSIT_MODES.bus)
278
+
279
+ await coachLoader.loadStop(reader.processEntity({
280
+ stop_id: '51586',
281
+ stop_name: 'Huntingdale Station/Haughton Road (Oakleigh)',
282
+ stop_lat: '-37.9111998619901',
283
+ stop_lon: '145.103064853799'
284
+ }))
285
+
286
+ huntingdale = await stops.findDocument({
287
+ 'bays.stopGTFSID': '51586'
288
+ })
289
+ expect(huntingdale.bays.length).to.equal(2)
290
+ expect(huntingdale.bays[1].stopGTFSID).to.equal('51586')
291
+ expect(huntingdale.bays[1].mode).to.equal(TRANSIT_MODES.regionalCoach)
292
+ })
223
293
  })