@transportme/load-ptv-gtfs 1.0.8 → 1.0.9

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.
@@ -63,11 +63,19 @@ export default async function setRouteStops(database) {
63
63
 
64
64
  if (routeData.mode === TRANSIT_MODES.metroTrain) {
65
65
  let currentDir = stopsByService[routeGTFSID][gtfsDirection].directionName
66
- if (currentDir.includes('Flinders Street') || currentDir.includes('Town Hall')) {
67
- stopsByService[routeGTFSID][gtfsDirection].directionName = 'City'
66
+ let isUp = currentDir.includes('Flinders Street') || currentDir.includes('Town Hall')
67
+
68
+ let directionName = stopsByService[routeGTFSID][gtfsDirection].directionName
69
+
70
+ if (routeData.routeName === 'Stony Point') {
71
+ isUp = currentDir.includes('Frankston')
72
+ directionName = directionName.slice(0, -16)
68
73
  } else {
69
- stopsByService[routeGTFSID][gtfsDirection].directionName = currentDir.slice(0, -16)
74
+ directionName = isUp ? 'City' : routeData.routeName
70
75
  }
76
+
77
+ stopsByService[routeGTFSID][gtfsDirection].directionName = directionName
78
+ stopsByService[routeGTFSID][gtfsDirection].trainDirection = isUp ? 'Up' : 'Down'
71
79
  }
72
80
  }
73
81
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@transportme/load-ptv-gtfs",
3
- "version": "1.0.8",
3
+ "version": "1.0.9",
4
4
  "description": "",
5
5
  "main": "index.mjs",
6
6
  "scripts": {
@@ -0,0 +1,99 @@
1
+ import { expect } from 'chai'
2
+ import path from 'path'
3
+ import url from 'url'
4
+ import { TRANSIT_MODES } from '../lib/constants.mjs'
5
+ import { LokiDatabaseConnection } from '@transportme/database'
6
+ import StopsLoader from '../lib/loader/StopsLoader.mjs'
7
+ import RouteLoader from '../lib/loader/RouteLoader.mjs'
8
+ import TripLoader from '../lib/loader/TripLoader.mjs'
9
+ import ShapeLoader from '../lib/loader/ShapeLoader.mjs'
10
+ import setRouteStops from '../lib/post-processing/set-route-stops.mjs'
11
+ import suburbs from './sample-data/suburbs.json' with { type: 'json' }
12
+
13
+ const __filename = url.fileURLToPath(import.meta.url)
14
+ const __dirname = path.dirname(__filename)
15
+
16
+ const routesFile = path.join(__dirname, 'sample-data', 'routes', 'metro_lines.txt')
17
+ const agencyFile = path.join(__dirname, 'sample-data', 'routes', 'agency.txt')
18
+
19
+ const calendarFile = path.join(__dirname, 'sample-data', 'calendar', 'calendar.txt')
20
+ const calendarDatesFile = path.join(__dirname, 'sample-data', 'calendar', 'calendar_dates.txt')
21
+
22
+ const stopsFile = path.join(__dirname, 'sample-data', 'merge', 'stops.txt')
23
+ const stopTimesFile = path.join(__dirname, 'sample-data', 'merge', 'stop_times.txt')
24
+ const tripsFile = path.join(__dirname, 'sample-data', 'merge', 'trips.txt')
25
+ const shapeFile = path.join(__dirname, 'sample-data', 'merge', 'shapes.txt')
26
+
27
+ let database = new LokiDatabaseConnection('test-db')
28
+ let stops = await database.createCollection('stops')
29
+ let routes = await database.createCollection('routes')
30
+ let trips = await database.createCollection('gtfs timetables')
31
+
32
+ let stopLoader = new StopsLoader(stopsFile, suburbs, TRANSIT_MODES.metroTrain, database)
33
+ await stopLoader.loadStops()
34
+
35
+ let routeLoader = new RouteLoader(routesFile, agencyFile, TRANSIT_MODES.metroTrain, database)
36
+ await routeLoader.loadRoutes()
37
+
38
+ let routeIDMap = routeLoader.getRouteIDMap()
39
+
40
+ let tripLoader = new TripLoader({
41
+ tripsFile, stopTimesFile,
42
+ calendarFile, calendarDatesFile
43
+ }, TRANSIT_MODES.metroTrain, database)
44
+
45
+ await tripLoader.loadTrips({ routeIDMap })
46
+ let shapeIDMap = tripLoader.getShapeIDMap()
47
+
48
+ let shapeLoader = new ShapeLoader(shapeFile, database)
49
+
50
+ await shapeLoader.loadShapes({ shapeIDMap })
51
+
52
+ await setRouteStops(database)
53
+
54
+ describe('The GTFS Route stop merger', () => {
55
+ describe('When processing Metro routes', () => {
56
+ it('Should set Up trips to be City-bound', async () => {
57
+ let pakenhamRoute = await routes.findDocument({ routeGTFSID: '2-PKM' })
58
+ expect(pakenhamRoute).to.not.be.null
59
+
60
+ let city = pakenhamRoute.directions.find(dir => dir.directionName === 'City')
61
+ expect(city).to.not.be.undefined
62
+ expect(city.stops[0].stopName).to.equal('East Pakenham Railway Station')
63
+ expect(city.stops[city.stops.length - 2].stopName).to.equal('Southern Cross Railway Station')
64
+ expect(city.stops[city.stops.length - 1].stopName).to.equal('Flinders Street Railway Station')
65
+ })
66
+
67
+ it('Should set Down trips to the name of the route', async () => {
68
+ let pakenhamRoute = await routes.findDocument({ routeGTFSID: '2-PKM' })
69
+ expect(pakenhamRoute).to.not.be.null
70
+
71
+ let pakenham = pakenhamRoute.directions.find(dir => dir.directionName !== 'City')
72
+ expect(pakenham).to.not.be.undefined
73
+ expect(pakenham.directionName).to.equal('Pakenham')
74
+ expect(pakenham.stops[0].stopName).to.equal('Flinders Street Railway Station')
75
+ expect(pakenham.stops[pakenham.stops.length - 2].stopName).to.equal('Pakenham Railway Station')
76
+ expect(pakenham.stops[pakenham.stops.length - 1].stopName).to.equal('East Pakenham Railway Station')
77
+ })
78
+
79
+ it('Should set Stony Point to Frankston trips as Up', async () => {
80
+ let stonyPointRoute = await routes.findDocument({ routeGTFSID: '2-STY' })
81
+ expect(stonyPointRoute).to.not.be.null
82
+
83
+ let frankston = stonyPointRoute.directions.find(dir => dir.directionName === 'Frankston')
84
+ expect(frankston).to.not.be.undefined
85
+ expect(frankston.stops[0].stopName).to.equal('Stony Point Railway Station')
86
+ expect(frankston.stops[frankston.stops.length - 1].stopName).to.equal('Frankston Railway Station')
87
+ })
88
+
89
+ it('Should set Stony Point trips as Down', async () => {
90
+ let stonyPointRoute = await routes.findDocument({ routeGTFSID: '2-STY' })
91
+ expect(stonyPointRoute).to.not.be.null
92
+
93
+ let stonyPoint = stonyPointRoute.directions.find(dir => dir.directionName === 'Stony Point')
94
+ expect(stonyPoint).to.not.be.undefined
95
+ expect(stonyPoint.stops[0].stopName).to.equal('Frankston Railway Station')
96
+ expect(stonyPoint.stops[stonyPoint.stops.length - 1].stopName).to.equal('Stony Point Railway Station')
97
+ })
98
+ })
99
+ })