@transportme/load-ptv-gtfs 1.4.30 → 1.4.32
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 +2 -2
- package/lib/gtfs-parser/GTFSRoute.mjs +2 -2
- package/lib/gtfs-parser/GTFSTrip.mjs +8 -3
- package/lib/gtfs-parser/readers/line-reader.mjs +1 -1
- package/lib/loader/RouteLoader.mjs +6 -2
- package/lib/loader/ShapeLoader.mjs +6 -2
- package/lib/loader/StopsLoader.mjs +6 -2
- package/lib/loader/TripLoader.mjs +6 -2
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -10,7 +10,7 @@ import GTFSRoute from './lib/gtfs-parser/GTFSRoute.mjs'
|
|
|
10
10
|
import { GTFSShape, GTFSShapePoint } from './lib/gtfs-parser/GTFSShape.mjs'
|
|
11
11
|
import { GTFSStop, GTFSPlatformStop } from './lib/gtfs-parser/GTFSStop.mjs'
|
|
12
12
|
import { GTFSStopTime } from './lib/gtfs-parser/GTFSStopTime.mjs'
|
|
13
|
-
import GTFSTrip from './lib/gtfs-parser/GTFSTrip.mjs'
|
|
13
|
+
import GTFSTrip, { IdentifiableTrip, SmartrakTrip } from './lib/gtfs-parser/GTFSTrip.mjs'
|
|
14
14
|
|
|
15
15
|
import setRouteStops from './lib/post-processing/set-route-stops.mjs'
|
|
16
16
|
|
|
@@ -29,7 +29,7 @@ const GTFSTypes = {
|
|
|
29
29
|
GTFSAgency, GTFSCalendar, GTFSCalendarDate,
|
|
30
30
|
GTFSRoute, GTFSShape, GTFSShapePoint,
|
|
31
31
|
GTFSStop, GTFSPlatformStop,
|
|
32
|
-
GTFSStopTime, GTFSTrip
|
|
32
|
+
GTFSStopTime, GTFSTrip, SmartrakTrip, IdentifiableTrip
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
const GTFSReaders = {
|
|
@@ -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+\-(
|
|
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) {
|
|
@@ -151,12 +151,17 @@ export class SmartrakTrip extends GTFSTrip {
|
|
|
151
151
|
}
|
|
152
152
|
|
|
153
153
|
getRunID() {
|
|
154
|
-
|
|
154
|
+
return this.constructor.getRunIDFromTripID(this.getTripID())
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
static getRunIDFromTripID(tripID) {
|
|
158
|
+
const tripIDParts = tripID.split('-')
|
|
159
|
+
const depotID = tripIDParts[0]
|
|
155
160
|
const routeNumber = tripIDParts[1]
|
|
156
161
|
const routeVariant = tripIDParts[2]
|
|
157
|
-
const rosterType =
|
|
162
|
+
const rosterType = tripIDParts[4].replace(/\d+/, '')
|
|
158
163
|
const tripRunID = tripIDParts[5]
|
|
159
|
-
return `${
|
|
164
|
+
return `${depotID}-${routeNumber}-${routeVariant}-${rosterType}-${tripRunID}`
|
|
160
165
|
}
|
|
161
166
|
}
|
|
162
167
|
|
|
@@ -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
|
-
|
|
117
|
-
|
|
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
|
-
|
|
92
|
-
|
|
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
|
-
|
|
201
|
-
|
|
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
|
}
|
|
@@ -237,8 +237,12 @@ export default class TripLoader {
|
|
|
237
237
|
|
|
238
238
|
await this.#stopTimesReader.open()
|
|
239
239
|
while (this.#stopTimesReader.available()) {
|
|
240
|
-
|
|
241
|
-
|
|
240
|
+
try {
|
|
241
|
+
let gtfsTrip = await this.#stopTimesReader.getNextEntity()
|
|
242
|
+
await this.loadTrip(gtfsTrip, processTrip)
|
|
243
|
+
} catch (e) {
|
|
244
|
+
console.error('Failed to load trip', e)
|
|
245
|
+
}
|
|
242
246
|
|
|
243
247
|
if (this.#tripsToLoad.length === 5000) { // Flush the cache every 5000 trips
|
|
244
248
|
tripsLoaded += this.#tripsToLoad.length
|