@transportme/load-ptv-gtfs 1.4.19 → 1.4.21
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.
|
@@ -51,7 +51,7 @@ export default class GTFSTrip {
|
|
|
51
51
|
* @returns {GTFSTrip} A trip instance representing the data being passed in
|
|
52
52
|
*/
|
|
53
53
|
static create(data, mode) {
|
|
54
|
-
let types = [ SmartrakTrip,
|
|
54
|
+
let types = [ SmartrakTrip, IdentifiableTrip, GTFSTrip ]
|
|
55
55
|
for (let type of types) {
|
|
56
56
|
if (type.canProcess(data, mode)) return new type(data)
|
|
57
57
|
}
|
|
@@ -157,19 +157,19 @@ export class SmartrakTrip extends GTFSTrip {
|
|
|
157
157
|
* Example: 02-BEG--58-T5_n4-3651
|
|
158
158
|
* RRB Example: 02-SUY--13-T2-BS000
|
|
159
159
|
*/
|
|
160
|
-
export class
|
|
160
|
+
export class IdentifiableTrip extends GTFSTrip {
|
|
161
161
|
|
|
162
162
|
#runID
|
|
163
163
|
|
|
164
164
|
constructor(data) {
|
|
165
165
|
super(data)
|
|
166
166
|
|
|
167
|
-
let runID = data.id.match(
|
|
167
|
+
let runID = data.id.match(/^\d\d-\w{1,3}-.*-(\w+)$/)
|
|
168
168
|
this.#runID = runID[1]
|
|
169
169
|
}
|
|
170
170
|
|
|
171
171
|
static canProcess(data, mode) {
|
|
172
|
-
return mode === TRANSIT_MODES.metroTrain && data.id.match(
|
|
172
|
+
return mode === TRANSIT_MODES.metroTrain && data.id.match(/^\d\d-\w{1,3}-.*-(\w+)$/)
|
|
173
173
|
}
|
|
174
174
|
|
|
175
175
|
getTrainDirection() {
|
|
@@ -201,6 +201,7 @@ export default class TripLoader {
|
|
|
201
201
|
this.updateStopServices(processedData)
|
|
202
202
|
|
|
203
203
|
this.#tripsToLoad.push(processedData)
|
|
204
|
+
this.#tripDetails[tripID] = null // Clear it from the cache once loaded to free up some memory
|
|
204
205
|
}
|
|
205
206
|
|
|
206
207
|
updateStopServices(trip) {
|
|
@@ -226,7 +227,7 @@ export default class TripLoader {
|
|
|
226
227
|
* @param {object} options.routeIDMap A mapping of full route IDs to their simplified IDs.
|
|
227
228
|
* @param {function} [options.processTrip] A function to modify trip data on a per-trip basis. It should return null to discard the trip.
|
|
228
229
|
*/
|
|
229
|
-
async loadTrips({ routeIDMap, processTrip }) {
|
|
230
|
+
async loadTrips({ routeIDMap, processTrip, onWrite = () => {} }) {
|
|
230
231
|
this.#routeIDMap = routeIDMap
|
|
231
232
|
|
|
232
233
|
await this.loadCalendarData()
|
|
@@ -242,11 +243,13 @@ export default class TripLoader {
|
|
|
242
243
|
if (this.#tripsToLoad.length === 5000) { // Flush the cache every 5000 trips
|
|
243
244
|
tripsLoaded += this.#tripsToLoad.length
|
|
244
245
|
await this.writeTrips()
|
|
246
|
+
onWrite(tripsLoaded)
|
|
245
247
|
}
|
|
246
248
|
}
|
|
247
249
|
|
|
248
250
|
tripsLoaded += this.#tripsToLoad.length
|
|
249
251
|
await this.writeTrips()
|
|
252
|
+
onWrite(tripsLoaded)
|
|
250
253
|
}
|
|
251
254
|
|
|
252
255
|
getTripsToLoad() {
|