@transportme/load-ptv-gtfs 1.4.34 → 1.4.36
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.
|
@@ -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.
|
|
@@ -18,17 +21,31 @@ export default class GTFSCalendarReader extends GTFSReader {
|
|
|
18
21
|
this.#calendarDateFile = calendarDateFile
|
|
19
22
|
}
|
|
20
23
|
|
|
24
|
+
#checkMissingFile(e) {
|
|
25
|
+
if (!e.stack.includes('ENOENT')) throw e
|
|
26
|
+
}
|
|
27
|
+
|
|
21
28
|
async open() {
|
|
22
|
-
|
|
29
|
+
try {
|
|
30
|
+
await super.open()
|
|
31
|
+
} catch (e) {
|
|
32
|
+
this.#checkMissingFile(e)
|
|
33
|
+
this.#hasCalendar = false
|
|
34
|
+
}
|
|
23
35
|
|
|
24
36
|
if (!this.#calendarDateFile) return
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
37
|
+
try {
|
|
38
|
+
let calendarDateReader = new GTFSCalendarDateReader(this.#calendarDateFile)
|
|
39
|
+
await calendarDateReader.open()
|
|
40
|
+
while (calendarDateReader.available()) {
|
|
41
|
+
let calendarDate = await calendarDateReader.getNextEntity()
|
|
42
|
+
if (!this.#calendarDates[calendarDate.id]) {
|
|
43
|
+
this.#calendarDates[calendarDate.id] = []
|
|
44
|
+
this.#unprocessedCalendarDates.add(calendarDate.id)
|
|
45
|
+
}
|
|
46
|
+
this.#calendarDates[calendarDate.id].push(calendarDate)
|
|
47
|
+
}
|
|
48
|
+
} catch (e) { this.#checkMissingFile(e) }
|
|
32
49
|
}
|
|
33
50
|
|
|
34
51
|
/**
|
|
@@ -59,6 +76,30 @@ export default class GTFSCalendarReader extends GTFSReader {
|
|
|
59
76
|
endDay: data.end_date
|
|
60
77
|
}
|
|
61
78
|
|
|
79
|
+
this.#unprocessedCalendarDates.delete(data.service_id)
|
|
80
|
+
|
|
62
81
|
return new GTFSCalendar(calendarData, this.#calendarDates[data.service_id])
|
|
63
82
|
}
|
|
83
|
+
|
|
84
|
+
available() {
|
|
85
|
+
const underlyingAvailable = this.#hasCalendar ? super.available() : false
|
|
86
|
+
if (underlyingAvailable) return true
|
|
87
|
+
return this.#unprocessedCalendarDates.size > 0
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
getNextEntity() {
|
|
91
|
+
if (this.#hasCalendar && super.available()) return super.getNextEntity()
|
|
92
|
+
const calendarDate = Array.from(this.#unprocessedCalendarDates.values())[0]
|
|
93
|
+
const calendarData = this.#calendarDates[calendarDate]
|
|
94
|
+
|
|
95
|
+
const calendar = new GTFSCalendar({
|
|
96
|
+
id: calendarDate,
|
|
97
|
+
daysOfWeek: Array(7).fill(false),
|
|
98
|
+
startDay: calendarData[0].rawDate,
|
|
99
|
+
endDay: calendarData[0].rawDate
|
|
100
|
+
}, calendarData)
|
|
101
|
+
|
|
102
|
+
this.#unprocessedCalendarDates.delete(calendarDate)
|
|
103
|
+
return calendar
|
|
104
|
+
}
|
|
64
105
|
}
|
|
@@ -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(',')
|