@transportme/load-ptv-gtfs 1.4.33 → 1.4.35
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/lib/gtfs-parser/GTFSCalendarDate.mjs +2 -0
- package/lib/gtfs-parser/readers/GTFSCalendarReader.mjs +34 -2
- package/lib/gtfs-parser/readers/line-reader.mjs +4 -1
- package/lib/loader/RouteLoader.mjs +6 -2
- package/lib/loader/ShapeLoader.mjs +5 -1
- package/lib/loader/StopsLoader.mjs +8 -1
- package/lib/loader/TripLoader.mjs +13 -3
- package/package.json +1 -1
|
@@ -6,6 +6,9 @@ export default class GTFSCalendarReader extends GTFSReader {
|
|
|
6
6
|
|
|
7
7
|
#calendarDateFile
|
|
8
8
|
#calendarDates = {}
|
|
9
|
+
#unprocessedCalendarDates = new Set()
|
|
10
|
+
|
|
11
|
+
#hasCalendar = true
|
|
9
12
|
|
|
10
13
|
/**
|
|
11
14
|
* Constructs a new GTFS Calendar reader.
|
|
@@ -19,14 +22,19 @@ export default class GTFSCalendarReader extends GTFSReader {
|
|
|
19
22
|
}
|
|
20
23
|
|
|
21
24
|
async open() {
|
|
22
|
-
|
|
25
|
+
try {
|
|
26
|
+
await super.open()
|
|
27
|
+
} catch (e) { this.#hasCalendar = false }
|
|
23
28
|
|
|
24
29
|
if (!this.#calendarDateFile) return
|
|
25
30
|
let calendarDateReader = new GTFSCalendarDateReader(this.#calendarDateFile)
|
|
26
31
|
await calendarDateReader.open()
|
|
27
32
|
while (calendarDateReader.available()) {
|
|
28
33
|
let calendarDate = await calendarDateReader.getNextEntity()
|
|
29
|
-
if (!this.#calendarDates[calendarDate.id])
|
|
34
|
+
if (!this.#calendarDates[calendarDate.id]) {
|
|
35
|
+
this.#calendarDates[calendarDate.id] = []
|
|
36
|
+
this.#unprocessedCalendarDates.add(calendarDate.id)
|
|
37
|
+
}
|
|
30
38
|
this.#calendarDates[calendarDate.id].push(calendarDate)
|
|
31
39
|
}
|
|
32
40
|
}
|
|
@@ -59,6 +67,30 @@ export default class GTFSCalendarReader extends GTFSReader {
|
|
|
59
67
|
endDay: data.end_date
|
|
60
68
|
}
|
|
61
69
|
|
|
70
|
+
this.#unprocessedCalendarDates.delete(data.service_id)
|
|
71
|
+
|
|
62
72
|
return new GTFSCalendar(calendarData, this.#calendarDates[data.service_id])
|
|
63
73
|
}
|
|
74
|
+
|
|
75
|
+
available() {
|
|
76
|
+
const underlyingAvailable = this.#hasCalendar ? super.available() : false
|
|
77
|
+
if (underlyingAvailable) return true
|
|
78
|
+
return this.#unprocessedCalendarDates.size > 0
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
getNextEntity() {
|
|
82
|
+
if (this.#hasCalendar && super.available()) return super.getNextEntity()
|
|
83
|
+
const calendarDate = Array.from(this.#unprocessedCalendarDates.values())[0]
|
|
84
|
+
const calendarData = this.#calendarDates[calendarDate]
|
|
85
|
+
|
|
86
|
+
const calendar = new GTFSCalendar({
|
|
87
|
+
id: calendarDate,
|
|
88
|
+
daysOfWeek: Array(7).fill(false),
|
|
89
|
+
startDay: calendarData[0].rawDate,
|
|
90
|
+
endDay: calendarData[0].rawDate
|
|
91
|
+
}, calendarData)
|
|
92
|
+
|
|
93
|
+
this.#unprocessedCalendarDates.delete(calendarDate)
|
|
94
|
+
return calendar
|
|
95
|
+
}
|
|
64
96
|
}
|
|
@@ -31,7 +31,10 @@ export default class CSVLineReader {
|
|
|
31
31
|
async open() {
|
|
32
32
|
await new Promise((resolve, reject) => {
|
|
33
33
|
lineReader.open(this.#file, async (err, reader) => {
|
|
34
|
-
if (err)
|
|
34
|
+
if (err) {
|
|
35
|
+
err.stack = `${err.stack}\n${new Error().stack.split('\n').slice(1).join('\n')}`
|
|
36
|
+
return reject(err)
|
|
37
|
+
}
|
|
35
38
|
|
|
36
39
|
this.#reader = reader
|
|
37
40
|
this.#headers = (await this.#readNextLine()).split(',')
|
|
@@ -13,9 +13,11 @@ export default class RouteLoader {
|
|
|
13
13
|
#routesReader
|
|
14
14
|
#operators = {}
|
|
15
15
|
#agencyFile
|
|
16
|
+
#routesFile
|
|
16
17
|
|
|
17
18
|
#routeIDMap = {}
|
|
18
19
|
|
|
20
|
+
|
|
19
21
|
/**
|
|
20
22
|
* Creates a new Shape Loader.
|
|
21
23
|
*
|
|
@@ -27,8 +29,8 @@ export default class RouteLoader {
|
|
|
27
29
|
constructor(routesFile, agencyFile, mode, database) {
|
|
28
30
|
this.#routes = this.getRoutesDB(database)
|
|
29
31
|
this.#mode = mode
|
|
30
|
-
this.#
|
|
31
|
-
this.#agencyFile = agencyFile
|
|
32
|
+
this.#routesFile = routesFile
|
|
33
|
+
this.#agencyFile = agencyFile
|
|
32
34
|
}
|
|
33
35
|
|
|
34
36
|
getRoutesDB(db) {
|
|
@@ -111,6 +113,8 @@ export default class RouteLoader {
|
|
|
111
113
|
async loadRoutes({ processRoute } = {}) {
|
|
112
114
|
await this.loadAgencies()
|
|
113
115
|
|
|
116
|
+
this.#routesReader = this.createRouteReader(this.#routesFile, this.#mode)
|
|
117
|
+
|
|
114
118
|
await this.#routesReader.open()
|
|
115
119
|
while (this.#routesReader.available()) {
|
|
116
120
|
try {
|
|
@@ -6,6 +6,8 @@ export default class ShapeLoader {
|
|
|
6
6
|
#routes
|
|
7
7
|
#shapeReader
|
|
8
8
|
|
|
9
|
+
#shapeFile
|
|
10
|
+
|
|
9
11
|
#routeCache = {}
|
|
10
12
|
|
|
11
13
|
/**
|
|
@@ -16,7 +18,7 @@ export default class ShapeLoader {
|
|
|
16
18
|
*/
|
|
17
19
|
constructor(shapeFile, database) {
|
|
18
20
|
this.#routes = this.getRoutesDB(database)
|
|
19
|
-
this.#
|
|
21
|
+
this.#shapeFile = shapeFile
|
|
20
22
|
}
|
|
21
23
|
|
|
22
24
|
getRoutesDB(db) {
|
|
@@ -83,6 +85,8 @@ export default class ShapeLoader {
|
|
|
83
85
|
* @param {function} options.shapeIDMap A mapping of shape IDs to their trip IDs.
|
|
84
86
|
*/
|
|
85
87
|
async loadShapes({ shapeIDMap }) {
|
|
88
|
+
this.#shapeReader = this.createShapeReader(this.#shapeFile)
|
|
89
|
+
|
|
86
90
|
await this.#shapeReader.open()
|
|
87
91
|
|
|
88
92
|
let shapesLoaded = 0
|
|
@@ -10,6 +10,10 @@ export default class StopsLoader {
|
|
|
10
10
|
#mode
|
|
11
11
|
#stopsReader
|
|
12
12
|
|
|
13
|
+
#stopsFile
|
|
14
|
+
#suburbs
|
|
15
|
+
#suburbHook
|
|
16
|
+
|
|
13
17
|
#parentHolding = {}
|
|
14
18
|
|
|
15
19
|
/**
|
|
@@ -25,7 +29,9 @@ export default class StopsLoader {
|
|
|
25
29
|
constructor(stopsFile, suburbs, mode, database, suburbHook) {
|
|
26
30
|
this.#stops = this.getStopsDB(database)
|
|
27
31
|
this.#mode = mode
|
|
28
|
-
this.#
|
|
32
|
+
this.#stopsFile = stopsFile
|
|
33
|
+
this.#suburbs = suburbs
|
|
34
|
+
this.#suburbHook = suburbHook
|
|
29
35
|
}
|
|
30
36
|
|
|
31
37
|
getStopsDB(db) {
|
|
@@ -195,6 +201,7 @@ export default class StopsLoader {
|
|
|
195
201
|
* @param {function} options.getMergeName Used to get a stop's merge name. Return null to use the default merge name.
|
|
196
202
|
*/
|
|
197
203
|
async loadStops(options) {
|
|
204
|
+
this.#stopsReader = this.createStopReader(this.#stopsFile, this.#suburbs, this.#suburbHook)
|
|
198
205
|
await this.#stopsReader.open()
|
|
199
206
|
while (this.#stopsReader.available()) {
|
|
200
207
|
try {
|
|
@@ -32,6 +32,11 @@ export default class TripLoader {
|
|
|
32
32
|
|
|
33
33
|
#tripsToLoad = []
|
|
34
34
|
|
|
35
|
+
#tripsFile
|
|
36
|
+
#stopTimesFile
|
|
37
|
+
#calendarFile
|
|
38
|
+
#calendarDatesFile
|
|
39
|
+
|
|
35
40
|
/**
|
|
36
41
|
* Creates a new Trip Loader.
|
|
37
42
|
*
|
|
@@ -50,9 +55,10 @@ export default class TripLoader {
|
|
|
50
55
|
|
|
51
56
|
this.#mode = mode
|
|
52
57
|
|
|
53
|
-
this.#
|
|
54
|
-
this.#
|
|
55
|
-
this.#
|
|
58
|
+
this.#tripsFile = tripsFile
|
|
59
|
+
this.#stopTimesFile = stopTimesFile
|
|
60
|
+
this.#calendarFile = calendarFile
|
|
61
|
+
this.#calendarDatesFile = calendarDatesFile
|
|
56
62
|
}
|
|
57
63
|
|
|
58
64
|
getRoutesDB(db) {
|
|
@@ -236,6 +242,10 @@ export default class TripLoader {
|
|
|
236
242
|
async loadTrips({ routeIDMap, processTrip, onWrite = () => {} }) {
|
|
237
243
|
this.#routeIDMap = routeIDMap
|
|
238
244
|
|
|
245
|
+
this.#stopTimesReader = this.createStopTimesReader(this.#stopTimesFile, this.#mode)
|
|
246
|
+
this.#tripsReader = this.createTripReader(this.#tripsFile, null, null, this.#mode)
|
|
247
|
+
this.#calendarReader = this.createCalendarReader(this.#calendarFile, this.#calendarDatesFile)
|
|
248
|
+
|
|
239
249
|
await this.loadCalendarData()
|
|
240
250
|
await this.loadTripsData()
|
|
241
251
|
|