@transportme/load-ptv-gtfs 1.4.31 → 1.4.33

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.
@@ -76,8 +76,8 @@ export default class GTFSRoute {
76
76
  class SmartrakGTFSRoute extends GTFSRoute {
77
77
 
78
78
  parseRouteID(routeGTFSID) {
79
- let [ _, routeNumber ] = routeGTFSID.match(/^\d+\-(\w+)/)
80
- return `4-${routeNumber}`
79
+ let [ _, routeNumber ] = routeGTFSID.match(/^\d+\-(...)/)
80
+ return `4-${routeNumber.replace(/[^\w_]/g, 'z')}`
81
81
  }
82
82
 
83
83
  static canProcess(routeGTFSID, mode) {
@@ -61,7 +61,7 @@ export default class CSVLineReader {
61
61
  let parts = [ ...line.matchAll(/(?:,"|^")(""|[\w\W]*?)(?=",|"$)|(?:,(?!")|^(?!"))([^,]*?)(?=$|,)|(\r\n|\n)/gm) ].map(match => match[1] || match[2])
62
62
 
63
63
  return this.#headers.reduce((acc, header, i) => {
64
- acc[header] = parts[i]
64
+ acc[header] = parts[i] || ''
65
65
  return acc
66
66
  }, {})
67
67
  }
@@ -113,8 +113,12 @@ export default class RouteLoader {
113
113
 
114
114
  await this.#routesReader.open()
115
115
  while (this.#routesReader.available()) {
116
- let route = await this.#routesReader.getNextEntity()
117
- await this.loadRoute(route, processRoute)
116
+ try {
117
+ let route = await this.#routesReader.getNextEntity()
118
+ await this.loadRoute(route, processRoute)
119
+ } catch (e) {
120
+ console.error('Failed to load trip', e)
121
+ }
118
122
  }
119
123
  }
120
124
 
@@ -88,8 +88,12 @@ export default class ShapeLoader {
88
88
  let shapesLoaded = 0
89
89
 
90
90
  while (this.#shapeReader.available()) {
91
- let shape = await this.#shapeReader.getNextEntity()
92
- await this.loadShape(shape, shapeIDMap)
91
+ try {
92
+ let shape = await this.#shapeReader.getNextEntity()
93
+ await this.loadShape(shape, shapeIDMap)
94
+ } catch (e) {
95
+ console.error('Failed to load shape', e)
96
+ }
93
97
 
94
98
  if (++shapesLoaded === 1000) {
95
99
  await this.writeShapes()
@@ -197,8 +197,12 @@ export default class StopsLoader {
197
197
  async loadStops(options) {
198
198
  await this.#stopsReader.open()
199
199
  while (this.#stopsReader.available()) {
200
- let stop = await this.#stopsReader.getNextEntity()
201
- await this.loadStop(stop, options)
200
+ try {
201
+ let stop = await this.#stopsReader.getNextEntity()
202
+ await this.loadStop(stop, options)
203
+ } catch (e) {
204
+ console.error('Failed to load stop', e)
205
+ }
202
206
  }
203
207
  }
204
208
  }
@@ -116,7 +116,12 @@ export default class TripLoader {
116
116
  if (this.#stopCache[stopGTFSID]) return this.#stopCache[stopGTFSID]
117
117
 
118
118
  let stop = await this.stops.findDocument({
119
- 'bays.stopGTFSID': stopGTFSID
119
+ bays: {
120
+ $elemMatch: {
121
+ stopGTFSID,
122
+ mode: this.#mode
123
+ }
124
+ }
120
125
  })
121
126
 
122
127
  this.#stopCache[stopGTFSID] = stop
@@ -131,6 +136,7 @@ export default class TripLoader {
131
136
  let stopData = await this.findMatchingStop(stop.stopID)
132
137
  if (!stopData) throw new Error(`Failed to match stop ${stop.stopID} in trip ${tripData.getTripID()}`)
133
138
  let bay = stopData.bays.find(bay => bay.stopGTFSID === stop.stopID && bay.mode === this.#mode)
139
+ if (!bay) throw new Error(`Missing bay for given stop ID ${stop.stopID} in trip ${tripData.getTripID()}`)
134
140
 
135
141
  let data = {
136
142
  stopName: bay.fullStopName,
@@ -237,8 +243,12 @@ export default class TripLoader {
237
243
 
238
244
  await this.#stopTimesReader.open()
239
245
  while (this.#stopTimesReader.available()) {
240
- let gtfsTrip = await this.#stopTimesReader.getNextEntity()
241
- await this.loadTrip(gtfsTrip, processTrip)
246
+ try {
247
+ let gtfsTrip = await this.#stopTimesReader.getNextEntity()
248
+ await this.loadTrip(gtfsTrip, processTrip)
249
+ } catch (e) {
250
+ console.error('Failed to load trip', e)
251
+ }
242
252
 
243
253
  if (this.#tripsToLoad.length === 5000) { // Flush the cache every 5000 trips
244
254
  tripsLoaded += this.#tripsToLoad.length
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@transportme/load-ptv-gtfs",
3
- "version": "1.4.31",
3
+ "version": "1.4.33",
4
4
  "description": "",
5
5
  "main": "index.mjs",
6
6
  "scripts": {