@transportme/load-ptv-gtfs 1.3.2 → 1.3.3

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, MetroRRBTrip, MetroTrip, GTFSTrip ]
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@transportme/load-ptv-gtfs",
3
- "version": "1.3.2",
3
+ "version": "1.3.3",
4
4
  "description": "",
5
5
  "main": "index.mjs",
6
6
  "scripts": {
@@ -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: 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
  })