@transportme/load-ptv-gtfs 1.2.0 → 1.2.1
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/GTFSStopTime.mjs +5 -5
- package/lib/loader/TripLoader.mjs +3 -2
- package/lib/utils.mjs +12 -1
- package/package.json +1 -1
- 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
|
@@ -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
|
|
@@ -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
|
@@ -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",""
|