@transportme/load-ptv-gtfs 1.2.0 → 1.2.2
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/GTFSAgency.mjs +2 -0
- package/lib/gtfs-parser/GTFSStopTime.mjs +5 -5
- package/lib/loader/RouteLoader.mjs +4 -1
- package/lib/loader/TripLoader.mjs +3 -2
- package/lib/utils.mjs +12 -1
- package/package.json +1 -1
- package/test/gtfs-route-loader.test.mjs +18 -0
- package/test/new-metro-loader-test.test.mjs +33 -0
- package/test/sample-data/new-metro/stop_times.txt +4 -1
- package/test/sample-data/new-metro/trips.txt +1 -0
- package/test/sample-data/routes/bad_routes.txt +4 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { hhmmToMinutesPastMidnight } from '../utils.mjs'
|
|
1
|
+
import { hhmmToMinutesPastMidnight, minutesPastMidnightToHHMMWrap } from '../utils.mjs'
|
|
2
2
|
|
|
3
3
|
export class GTFSStopTime {
|
|
4
4
|
|
|
@@ -14,11 +14,11 @@ export class GTFSStopTime {
|
|
|
14
14
|
distanceTravelled
|
|
15
15
|
|
|
16
16
|
constructor({ arrivalTime, departureTime, stopID, stopSequence, pickup, dropoff, distance }) {
|
|
17
|
-
this.
|
|
18
|
-
this.
|
|
17
|
+
this.arrivalTimeMinutes = hhmmToMinutesPastMidnight(arrivalTime)
|
|
18
|
+
this.departureTimeMinutes = hhmmToMinutesPastMidnight(departureTime)
|
|
19
19
|
|
|
20
|
-
this.
|
|
21
|
-
this.
|
|
20
|
+
this.arrivalTime = minutesPastMidnightToHHMMWrap(this.arrivalTimeMinutes)
|
|
21
|
+
this.departureTime = minutesPastMidnightToHHMMWrap(this.departureTimeMinutes)
|
|
22
22
|
|
|
23
23
|
this.stopID = stopID
|
|
24
24
|
this.stopSequence = stopSequence
|
|
@@ -2,6 +2,7 @@ import GTFSRouteReader from '../gtfs-parser/readers/GTFSRouteReader.mjs'
|
|
|
2
2
|
import GTFSAgencyReader from '../gtfs-parser/readers/GTFSAgencyReader.mjs'
|
|
3
3
|
import { STOP_UTILS } from '@transportme/transportvic-utils'
|
|
4
4
|
import GTFSRoute from '../gtfs-parser/GTFSRoute.mjs'
|
|
5
|
+
import GTFSAgency from '../gtfs-parser/GTFSAgency.mjs'
|
|
5
6
|
|
|
6
7
|
const { sanitiseName } = STOP_UTILS
|
|
7
8
|
|
|
@@ -109,7 +110,9 @@ export default class RouteLoader {
|
|
|
109
110
|
}
|
|
110
111
|
|
|
111
112
|
getOperator(id) {
|
|
112
|
-
|
|
113
|
+
let operator = this.#operators[id]
|
|
114
|
+
if (operator) return operator
|
|
115
|
+
return GTFSAgency.UNKNOWN_AGENCY
|
|
113
116
|
}
|
|
114
117
|
|
|
115
118
|
getRouteIDMap() {
|
|
@@ -4,6 +4,7 @@ import GTFSStopTimesReader from '../gtfs-parser/readers/GTFSStopTimesReader.mjs'
|
|
|
4
4
|
import GTFSTripReader from '../gtfs-parser/readers/GTFSTripReader.mjs'
|
|
5
5
|
import async from 'async'
|
|
6
6
|
import { GTFSStopTime } from '../gtfs-parser/GTFSStopTime.mjs'
|
|
7
|
+
import { minutesPastMidnightToHHMM } from '../utils.mjs'
|
|
7
8
|
|
|
8
9
|
export default class TripLoader {
|
|
9
10
|
|
|
@@ -133,14 +134,14 @@ export default class TripLoader {
|
|
|
133
134
|
}
|
|
134
135
|
|
|
135
136
|
dbTrip.origin = stopTimings[0].stopName
|
|
136
|
-
dbTrip.departureTime = stopTimings[0].
|
|
137
|
+
dbTrip.departureTime = minutesPastMidnightToHHMM(stopTimings[0].departureTimeMinutes)
|
|
137
138
|
stopTimings[0].arrivalTime = null
|
|
138
139
|
stopTimings[0].arrivalTimeMinutes = null
|
|
139
140
|
stopTimings[0].stopConditions.dropoff = 1
|
|
140
141
|
|
|
141
142
|
let lastStop = stopTimings[stopTimings.length - 1]
|
|
142
143
|
dbTrip.destination = lastStop.stopName
|
|
143
|
-
dbTrip.destinationArrivalTime = lastStop.
|
|
144
|
+
dbTrip.destinationArrivalTime = minutesPastMidnightToHHMM(lastStop.arrivalTimeMinutes)
|
|
144
145
|
lastStop.departureTime = null
|
|
145
146
|
lastStop.departureTimeMinutes = null
|
|
146
147
|
lastStop.stopConditions.pickup = 1
|
package/lib/utils.mjs
CHANGED
|
@@ -10,7 +10,18 @@ export function toGTFSDate(date) {
|
|
|
10
10
|
return date.toFormat('yyyyMMdd')
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
export function minutesPastMidnightToHHMM(time) {
|
|
14
|
+
let hours = Math.floor(time / 60)
|
|
15
|
+
let min = time % 60
|
|
16
|
+
|
|
17
|
+
return `${hours < 10 ? '0' : ''}${hours}:${min < 10 ? '0' : ''}${min}`
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function minutesPastMidnightToHHMMWrap(time) {
|
|
21
|
+
return minutesPastMidnightToHHMM(time % 1440)
|
|
22
|
+
}
|
|
23
|
+
|
|
13
24
|
export function hhmmToMinutesPastMidnight(date) {
|
|
14
|
-
let [ hours, minutes ] = date.split(':')
|
|
25
|
+
let [ hours, minutes, seconds ] = date.split(':')
|
|
15
26
|
return parseInt(minutes) + parseInt(hours) * 60
|
|
16
27
|
}
|
package/package.json
CHANGED
|
@@ -7,6 +7,7 @@ import { TRANSIT_MODES } from '../lib/constants.mjs'
|
|
|
7
7
|
import path from 'path'
|
|
8
8
|
import url from 'url'
|
|
9
9
|
import { expect } from 'chai'
|
|
10
|
+
import GTFSAgency from '../lib/gtfs-parser/GTFSAgency.mjs'
|
|
10
11
|
|
|
11
12
|
const __filename = url.fileURLToPath(import.meta.url)
|
|
12
13
|
const __dirname = path.dirname(__filename)
|
|
@@ -18,6 +19,8 @@ const agencyFile = path.join(__dirname, 'sample-data', 'routes', 'agency.txt')
|
|
|
18
19
|
const wgtFile = path.join(__dirname, 'sample-data', 'routes', 'west_gipp_transit.txt')
|
|
19
20
|
const vlineFile = path.join(__dirname, 'sample-data', 'routes', 'vline.txt')
|
|
20
21
|
|
|
22
|
+
const badRoutesFile_NoAgency = path.join(__dirname, 'sample-data', 'routes', 'bad_routes.txt')
|
|
23
|
+
|
|
21
24
|
describe('The GTFS Agency Reader', () => {
|
|
22
25
|
it('Should read the agencies one line at a time', async () => {
|
|
23
26
|
let reader = new GTFSAgencyReader(agencyFile)
|
|
@@ -187,4 +190,19 @@ describe('The GTFS Routes Loader', () => {
|
|
|
187
190
|
expect(traralgon.routeName).to.equal('Traralgon - Melbourne Via Pakenham, Moe & Morwell')
|
|
188
191
|
expect(traralgon.operators).to.have.members(['V/Line'])
|
|
189
192
|
})
|
|
193
|
+
|
|
194
|
+
it('Should handle invalid agency references', async () => {
|
|
195
|
+
let database = new LokiDatabaseConnection('test-db')
|
|
196
|
+
let routes = await database.createCollection('routes')
|
|
197
|
+
|
|
198
|
+
let loader = new RouteLoader(badRoutesFile_NoAgency, agencyFile, TRANSIT_MODES.bus, database)
|
|
199
|
+
await loader.loadRoutes()
|
|
200
|
+
|
|
201
|
+
let skybus = await routes.findDocument({
|
|
202
|
+
routeGTFSID: '11-SKY'
|
|
203
|
+
})
|
|
204
|
+
|
|
205
|
+
expect(skybus).to.not.be.null
|
|
206
|
+
expect(skybus.operators).to.deep.equal([GTFSAgency.UNKNOWN_AGENCY.name])
|
|
207
|
+
})
|
|
190
208
|
})
|
|
@@ -164,5 +164,38 @@ describe('The GTFS Loaders with the new Metro data', () => {
|
|
|
164
164
|
expect(trip.stopTimings[3].stopName).to.equal('Parliament Railway Station')
|
|
165
165
|
expect(trip.stopTimings[3].platform).to.equal('RRB')
|
|
166
166
|
})
|
|
167
|
+
|
|
168
|
+
it('Should wrap times past midnight back to 00:00 NEXT DAY in the trip times', async () => {
|
|
169
|
+
let database = new LokiDatabaseConnection('test-db')
|
|
170
|
+
let stops = await database.createCollection('stops')
|
|
171
|
+
let routes = await database.createCollection('routes')
|
|
172
|
+
let trips = await database.createCollection('gtfs timetables')
|
|
173
|
+
|
|
174
|
+
let stopLoader = new StopsLoader(stopsFile, suburbs, TRANSIT_MODES.metroTrain, database)
|
|
175
|
+
await stopLoader.loadStops()
|
|
176
|
+
|
|
177
|
+
let routeLoader = new RouteLoader(routesFile, agencyFile, TRANSIT_MODES.metroTrain, database)
|
|
178
|
+
await routeLoader.loadRoutes()
|
|
179
|
+
|
|
180
|
+
let routeIDMap = routeLoader.getRouteIDMap()
|
|
181
|
+
|
|
182
|
+
let tripLoader = new TripLoader({
|
|
183
|
+
tripsFile, stopTimesFile,
|
|
184
|
+
calendarFile, calendarDatesFile
|
|
185
|
+
}, TRANSIT_MODES.metroTrain, database)
|
|
186
|
+
|
|
187
|
+
await tripLoader.loadTrips({ routeIDMap })
|
|
188
|
+
|
|
189
|
+
let trip = await trips.findDocument({ runID: 'C999' })
|
|
190
|
+
|
|
191
|
+
expect(trip).to.not.be.null
|
|
192
|
+
expect(trip.departureTime).to.equal('23:59')
|
|
193
|
+
expect(trip.destinationArrivalTime).to.equal('24:10')
|
|
194
|
+
|
|
195
|
+
expect(trip.stopTimings[0].departureTime).to.equal('23:59')
|
|
196
|
+
expect(trip.stopTimings[1].departureTime).to.equal('00:05')
|
|
197
|
+
expect(trip.stopTimings[1].arrivalTime).to.equal('00:05')
|
|
198
|
+
expect(trip.stopTimings[2].arrivalTime).to.equal('00:10')
|
|
199
|
+
})
|
|
167
200
|
})
|
|
168
201
|
})
|
|
@@ -58,4 +58,7 @@ trip_id,arrival_time,departure_time,stop_id,stop_sequence,stop_headsign,pickup_t
|
|
|
58
58
|
"02-PKM--12-T5-C005","06:37:00","06:37:00","12175","25","","0","0","50023.30"
|
|
59
59
|
"02-PKM--12-T5-C005","06:40:00","06:40:00","26502","26","","0","0","52360.00"
|
|
60
60
|
"02-PKM--12-T5-C005","06:46:00","06:46:00","12173","27","","0","0","56761.80"
|
|
61
|
-
"02-PKM--12-T5-C005","06:49:00","06:49:00","26507","28","","0","0","58561.26"
|
|
61
|
+
"02-PKM--12-T5-C005","06:49:00","06:49:00","26507","28","","0","0","58561.26"
|
|
62
|
+
"02-PKM--12-T5-C999","23:59:00","23:59:00","11218","1","","0","0","0.00"
|
|
63
|
+
"02-PKM--12-T5-C999","24:05:00","24:05:00","12258","2","","0","0","2223.76"
|
|
64
|
+
"02-PKM--12-T5-C999","24:10:00","24:10:00","26507","28","","0","0","58561.26"
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
route_id,service_id,trip_id,shape_id,trip_headsign,direction_id,block_id
|
|
2
2
|
"aus:vic:vic-02-PKM:","T5","02-PKM--12-T5-C000","2-PKM-vpt-12.20.R","Flinders Street via City Loop","1","3347"
|
|
3
3
|
"aus:vic:vic-02-PKM:","T5","02-PKM--12-T5-C005","2-PKM-vpt-12.17.H","East Pakenham","0","3347"
|
|
4
|
+
"aus:vic:vic-02-PKM:","T5","02-PKM--12-T5-C999","2-PKM-vpt-12.17.H","East Pakenham","0","3347"
|
|
4
5
|
"aus:vic:vic-02-LIL:","T5+w3","02-LIL--13-T5_w3-BL000","2-LIL-vpt-13.133.R","Parliament","1",""
|
|
5
6
|
"aus:vic:vic-02-LIL:","T5+w3","02-LIL--13-T5_w3-BL001","2-LIL-vpt-13.134.H","Burnley","0",""
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
route_id,agency_id,route_short_name,route_long_name,route_type,route_color,route_text_color
|
|
2
|
+
"11-SK4-mjp-1","","","Frankston - Melbourne Airport","3","ED1C24","FFFFFF"
|
|
3
|
+
"11-Ska-mjp-1","","","Melbourne City - Avalon Airport","3","ED1C24","FFFFFF"
|
|
4
|
+
"11-SKY-mjp-1","","","City - Melbourne Airport","3","ED1C24","FFFFFF"
|