@transportme/load-ptv-gtfs 1.3.2 → 1.3.4
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.
|
@@ -48,7 +48,7 @@ export default class GTFSTrip {
|
|
|
48
48
|
* @returns {GTFSTrip} A trip instance representing the data being passed in
|
|
49
49
|
*/
|
|
50
50
|
static create(data, mode) {
|
|
51
|
-
let types = [ SmartrakTrip,
|
|
51
|
+
let types = [ SmartrakTrip, MetroTrip, GTFSTrip ]
|
|
52
52
|
for (let type of types) {
|
|
53
53
|
if (type.canProcess(data, mode)) return new type(data)
|
|
54
54
|
}
|
|
@@ -148,12 +148,12 @@ export class MetroTrip extends GTFSTrip {
|
|
|
148
148
|
constructor(data) {
|
|
149
149
|
super(data)
|
|
150
150
|
|
|
151
|
-
let runID = data.id.match(/^02-\w{3}-.*-(\w{1,2}\d{3})$/)
|
|
151
|
+
let runID = data.id.match(/^02-\w{3}-.*-(\w{1,2}\d{2,3})$/)
|
|
152
152
|
this.#runID = runID[1]
|
|
153
153
|
}
|
|
154
154
|
|
|
155
155
|
static canProcess(data, mode) {
|
|
156
|
-
return mode === TRANSIT_MODES.metroTrain && data.id.match(/^02-\w{3}-.*-(\w{1,2}\d{3})$/)
|
|
156
|
+
return mode === TRANSIT_MODES.metroTrain && data.id.match(/^02-\w{3}-.*-(\w{1,2}\d{2,3})$/)
|
|
157
157
|
}
|
|
158
158
|
|
|
159
159
|
getTrainDirection() {
|
|
@@ -163,11 +163,12 @@ export class MetroTrip extends GTFSTrip {
|
|
|
163
163
|
|
|
164
164
|
getTripData() {
|
|
165
165
|
let runID = this.getRunID()
|
|
166
|
+
let tripID = this.getTripID()
|
|
166
167
|
|
|
167
168
|
return {
|
|
168
169
|
...super.getTripData(),
|
|
169
170
|
runID,
|
|
170
|
-
isRailReplacementBus: runID.length === 5 && runID[0] === 'B',
|
|
171
|
+
isRailReplacementBus: (runID.length === 5 && runID[0] === 'B') || !!tripID.match(/^02-\w{3}-R-/),
|
|
171
172
|
direction: this.getTrainDirection()
|
|
172
173
|
}
|
|
173
174
|
}
|
|
@@ -76,7 +76,7 @@ export default class StopsLoader {
|
|
|
76
76
|
|
|
77
77
|
updateStopName(stop) {
|
|
78
78
|
stop.cleanNames = stop.bays
|
|
79
|
-
.filter(bay => bay.stopType === STOP_TYPE[0])
|
|
79
|
+
.filter(bay => bay.stopType === STOP_TYPE[0] || bay.stopType === STOP_TYPE[1])
|
|
80
80
|
.map(bay => sanitiseName(bay.fullStopName))
|
|
81
81
|
.filter((e, i, a) => a.indexOf(e) === i)
|
|
82
82
|
|
|
@@ -93,17 +93,17 @@ export default class StopsLoader {
|
|
|
93
93
|
|
|
94
94
|
updateStopSuburb(stop) {
|
|
95
95
|
stop.cleanSuburbs = stop.bays
|
|
96
|
-
.filter(bay => bay.stopType === STOP_TYPE[0])
|
|
96
|
+
.filter(bay => bay.stopType === STOP_TYPE[0] || bay.stopType === STOP_TYPE[1])
|
|
97
97
|
.map(bay => sanitiseName(bay.suburb))
|
|
98
98
|
.filter((e, i, a) => a.indexOf(e) === i)
|
|
99
99
|
|
|
100
100
|
stop.suburb = stop.bays
|
|
101
|
-
.filter(bay => bay.stopType === STOP_TYPE[0])
|
|
101
|
+
.filter(bay => bay.stopType === STOP_TYPE[0] || bay.stopType === STOP_TYPE[1])
|
|
102
102
|
.map(bay => bay.suburb)
|
|
103
103
|
.filter((e, i, a) => a.indexOf(e) === i)
|
|
104
104
|
.sort()
|
|
105
105
|
|
|
106
|
-
|
|
106
|
+
stop.codedSuburbs = stop.cleanSuburbs
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
updateStopLocation(stop) {
|
package/package.json
CHANGED
|
@@ -342,4 +342,40 @@ describe('The GTFS Stops Loader', () => {
|
|
|
342
342
|
// TODO: Find out what the Connex stop is for
|
|
343
343
|
expect(stopData.cleanNames).to.deep.equal(['clifton-hill-railway-station', 'connex'])
|
|
344
344
|
})
|
|
345
|
+
|
|
346
|
+
it('Should use stop and station names and suburbs', async () => {
|
|
347
|
+
let database = new LokiDatabaseConnection('test-db')
|
|
348
|
+
let stops = await database.createCollection('stops')
|
|
349
|
+
|
|
350
|
+
let data = [{
|
|
351
|
+
"stop_id": "vic:rail:THL",
|
|
352
|
+
"stop_name": "Town Hall Railway Station (Melbourne)",
|
|
353
|
+
"stop_lat": "-37.815926",
|
|
354
|
+
"stop_lon": "144.967134",
|
|
355
|
+
"parent_station": "",
|
|
356
|
+
"location_type": "1",
|
|
357
|
+
"platform_code": ""
|
|
358
|
+
},
|
|
359
|
+
{
|
|
360
|
+
"stop_id": "vic:rail:TSC",
|
|
361
|
+
"stop_name": "Town Hall Railway Station (Melbourne)",
|
|
362
|
+
"stop_lat": "-37.815926",
|
|
363
|
+
"stop_lon": "144.967134",
|
|
364
|
+
"parent_station": "",
|
|
365
|
+
"location_type": "1",
|
|
366
|
+
"platform_code": ""
|
|
367
|
+
}]
|
|
368
|
+
|
|
369
|
+
let stopLoader = new StopsLoader('', suburbs, TRANSIT_MODES.metroTrain, database)
|
|
370
|
+
let reader = new GTFSStopsReader('', suburbs)
|
|
371
|
+
|
|
372
|
+
for (let stop of data) await stopLoader.loadStop(reader.processEntity(stop))
|
|
373
|
+
|
|
374
|
+
expect(await stops.countDocuments({})).to.equal(1)
|
|
375
|
+
let stopData = await stops.findDocument({})
|
|
376
|
+
expect(stopData.stopName).to.equal('Town Hall Railway Station')
|
|
377
|
+
expect(stopData.cleanNames).to.deep.equal(['town-hall-railway-station'])
|
|
378
|
+
expect(stopData.suburb).to.deep.equal(['Melbourne'])
|
|
379
|
+
expect(stopData.cleanSuburbs).to.deep.equal(['melbourne'])
|
|
380
|
+
})
|
|
345
381
|
})
|
package/test/gtfs-trips.test.mjs
CHANGED
|
@@ -11,21 +11,20 @@ const __dirname = path.dirname(__filename)
|
|
|
11
11
|
|
|
12
12
|
const tripsFile = path.join(__dirname, 'sample-data', 'trips', 'trips.txt')
|
|
13
13
|
const busTripsFile = path.join(__dirname, 'sample-data', 'trips', 'bus_trips.txt')
|
|
14
|
+
const calendar = new GTFSCalendar({
|
|
15
|
+
id: 'T1',
|
|
16
|
+
startDay: '20241122',
|
|
17
|
+
endDay: '20241129',
|
|
18
|
+
daysOfWeek: ["0","0","0","0","1","1","0"]
|
|
19
|
+
})
|
|
14
20
|
|
|
15
21
|
describe('The GTFSTrip class', () => {
|
|
16
22
|
it('Should process the skeleton trip data and populate the operation days', () => {
|
|
17
|
-
let calendar = new GTFSCalendar({
|
|
18
|
-
id: 'T1',
|
|
19
|
-
startDay: '20241122',
|
|
20
|
-
endDay: '20241129',
|
|
21
|
-
daysOfWeek: ["0","0","0","0","1","1","0"]
|
|
22
|
-
})
|
|
23
|
-
|
|
24
23
|
// route_id,service_id,trip_id,shape_id,trip_headsign,direction_id,block_id
|
|
25
24
|
// "6-452-mjp-1","T0_16","1.T0.6-452-mjp-1.1.H","6-452-mjp-1.1.H","Eynesbury","0",""
|
|
26
25
|
let trip = new GTFSTrip({
|
|
27
26
|
routeGTFSID: '6-452',
|
|
28
|
-
calendar
|
|
27
|
+
calendar,
|
|
29
28
|
id: '1.T0.6-452-mjp-1.1.H',
|
|
30
29
|
shapeID: '6-452-mjp-1.1.H',
|
|
31
30
|
headsign: 'Eynesbury',
|
|
@@ -7,6 +7,8 @@ import { expect } from 'chai'
|
|
|
7
7
|
import suburbs from './sample-data/suburbs.json' with { type: 'json' }
|
|
8
8
|
import RouteLoader from '../lib/loader/RouteLoader.mjs'
|
|
9
9
|
import TripLoader from '../lib/loader/TripLoader.mjs'
|
|
10
|
+
import GTFSCalendar from '../lib/gtfs-parser/GTFSCalendar.mjs'
|
|
11
|
+
import { MetroTrip } from '../lib/gtfs-parser/GTFSTrip.mjs'
|
|
10
12
|
|
|
11
13
|
const __filename = url.fileURLToPath(import.meta.url)
|
|
12
14
|
const __dirname = path.dirname(__filename)
|
|
@@ -198,4 +200,45 @@ describe('The GTFS Loaders with the new Metro data', () => {
|
|
|
198
200
|
expect(trip.stopTimings[2].arrivalTime).to.equal('00:10')
|
|
199
201
|
})
|
|
200
202
|
})
|
|
203
|
+
|
|
204
|
+
describe('The MetroTrip subclass', () => {
|
|
205
|
+
it('Should detect rail buses', () => {
|
|
206
|
+
let calendar = new GTFSCalendar({
|
|
207
|
+
id: 'T1',
|
|
208
|
+
startDay: '20241122',
|
|
209
|
+
endDay: '20241129',
|
|
210
|
+
daysOfWeek: ["0","0","0","0","1","1","0"]
|
|
211
|
+
})
|
|
212
|
+
|
|
213
|
+
expect(new MetroTrip({
|
|
214
|
+
routeGTFSID: '2-PKM',
|
|
215
|
+
calendar,
|
|
216
|
+
id: '02-PKM--54-T6-C962',
|
|
217
|
+
shapeID: '2-PKM-vpt-54.70.R',
|
|
218
|
+
headsign: 'South Yarra',
|
|
219
|
+
direction: '0',
|
|
220
|
+
block: ''
|
|
221
|
+
}).getTripData().isRailReplacementBus).to.be.false
|
|
222
|
+
|
|
223
|
+
expect(new MetroTrip({
|
|
224
|
+
routeGTFSID: '2-PKM',
|
|
225
|
+
calendar,
|
|
226
|
+
id: '02-PKM-R-6-T5_bp-BF400',
|
|
227
|
+
shapeID: '2-PKM-R-vpt-6.7.R',
|
|
228
|
+
headsign: 'South Yarra',
|
|
229
|
+
direction: '0',
|
|
230
|
+
block: ''
|
|
231
|
+
}).getTripData().isRailReplacementBus).to.be.true
|
|
232
|
+
|
|
233
|
+
expect(new MetroTrip({
|
|
234
|
+
routeGTFSID: '2-PKM',
|
|
235
|
+
calendar,
|
|
236
|
+
id: '02-PKM-R-6-T5_bp-BF22',
|
|
237
|
+
shapeID: '2-PKM-R-vpt-6.7.R',
|
|
238
|
+
headsign: 'South Yarra',
|
|
239
|
+
direction: '0',
|
|
240
|
+
block: ''
|
|
241
|
+
}).getTripData().isRailReplacementBus).to.be.true
|
|
242
|
+
})
|
|
243
|
+
})
|
|
201
244
|
})
|