@transportme/load-ptv-gtfs 1.1.6 → 1.1.8
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.
|
@@ -26,6 +26,7 @@ export default class TripLoader {
|
|
|
26
26
|
#stopCache = {}
|
|
27
27
|
|
|
28
28
|
#shapeIDMap = {}
|
|
29
|
+
#directionIDMap = {}
|
|
29
30
|
|
|
30
31
|
#tripsToLoad = []
|
|
31
32
|
|
|
@@ -164,7 +165,9 @@ export default class TripLoader {
|
|
|
164
165
|
if (!processedData) return
|
|
165
166
|
|
|
166
167
|
this.#shapeIDMap[tripData.shapeID] = tripData.routeGTFSID
|
|
167
|
-
|
|
168
|
+
if (!this.#directionIDMap[tripData.routeGTFSID]) this.#directionIDMap[tripData.routeGTFSID] = {}
|
|
169
|
+
this.#directionIDMap[tripData.routeGTFSID][rawTripData.getHeadsign()] = rawTripData.getGTFSDirection()
|
|
170
|
+
|
|
168
171
|
this.#tripsToLoad.push(processedData)
|
|
169
172
|
}
|
|
170
173
|
|
|
@@ -211,4 +214,8 @@ export default class TripLoader {
|
|
|
211
214
|
getShapeIDMap() {
|
|
212
215
|
return this.#shapeIDMap
|
|
213
216
|
}
|
|
217
|
+
|
|
218
|
+
getDirectionIDMap() {
|
|
219
|
+
return this.#directionIDMap
|
|
220
|
+
}
|
|
214
221
|
}
|
|
@@ -8,7 +8,7 @@ import { TRANSIT_MODES } from '../constants.mjs'
|
|
|
8
8
|
*
|
|
9
9
|
* @param {DatabaseConnection} database The database connection to use
|
|
10
10
|
*/
|
|
11
|
-
export default async function setRouteStops(database) {
|
|
11
|
+
export default async function setRouteStops(database, directionsMap) {
|
|
12
12
|
let gtfsTimetables = database.getCollection('gtfs timetables')
|
|
13
13
|
let routes = database.getCollection('routes')
|
|
14
14
|
|
|
@@ -87,7 +87,8 @@ export default async function setRouteStops(database) {
|
|
|
87
87
|
updateOne: {
|
|
88
88
|
filter: { routeGTFSID },
|
|
89
89
|
update: { $set: {
|
|
90
|
-
directions: stopsByService[routeGTFSID].filter(Boolean) // Apparently some routes dont have GTFS Dir 0
|
|
90
|
+
directions: stopsByService[routeGTFSID].filter(Boolean), // Apparently some routes dont have GTFS Dir 0
|
|
91
|
+
ptvDirections: directionsMap[routeGTFSID]
|
|
91
92
|
} }
|
|
92
93
|
}
|
|
93
94
|
})
|
package/package.json
CHANGED
|
@@ -109,4 +109,31 @@ describe('The TripLoader class', () => {
|
|
|
109
109
|
|
|
110
110
|
expect(shapeIDMap['2-ALM-vpt-1.1.R']).to.equal('2-ALM')
|
|
111
111
|
})
|
|
112
|
+
|
|
113
|
+
it('Should return a mapping of Route + GTFS Direction ID to PTV Direction Names', async () => {
|
|
114
|
+
let database = new LokiDatabaseConnection('test-db')
|
|
115
|
+
let stops = await database.createCollection('stops')
|
|
116
|
+
let routes = await database.createCollection('routes')
|
|
117
|
+
let trips = await database.createCollection('gtfs timetables')
|
|
118
|
+
|
|
119
|
+
let stopLoader = new StopsLoader(stopsFile, suburbs, TRANSIT_MODES.metroTrain, database)
|
|
120
|
+
await stopLoader.loadStops()
|
|
121
|
+
|
|
122
|
+
let routeLoader = new RouteLoader(routesFile, agencyFile, TRANSIT_MODES.metroTrain, database)
|
|
123
|
+
await routeLoader.loadRoutes()
|
|
124
|
+
|
|
125
|
+
let routeIDMap = routeLoader.getRouteIDMap()
|
|
126
|
+
|
|
127
|
+
let tripLoader = new TripLoader({
|
|
128
|
+
tripsFile, stopTimesFile,
|
|
129
|
+
calendarFile, calendarDatesFile
|
|
130
|
+
}, TRANSIT_MODES.metroTrain, database)
|
|
131
|
+
|
|
132
|
+
await tripLoader.loadTrips({ routeIDMap })
|
|
133
|
+
let directionIDMap = tripLoader.getDirectionIDMap()
|
|
134
|
+
|
|
135
|
+
expect(directionIDMap).to.deep.equal({
|
|
136
|
+
'2-ALM': { 'Alamein': 0, 'Camberwell': 1 }
|
|
137
|
+
})
|
|
138
|
+
})
|
|
112
139
|
})
|
|
@@ -44,12 +44,13 @@ let tripLoader = new TripLoader({
|
|
|
44
44
|
|
|
45
45
|
await tripLoader.loadTrips({ routeIDMap })
|
|
46
46
|
let shapeIDMap = tripLoader.getShapeIDMap()
|
|
47
|
+
let directionIDMap = tripLoader.getDirectionIDMap()
|
|
47
48
|
|
|
48
49
|
let shapeLoader = new ShapeLoader(shapeFile, database)
|
|
49
50
|
|
|
50
51
|
await shapeLoader.loadShapes({ shapeIDMap })
|
|
51
52
|
|
|
52
|
-
await setRouteStops(database)
|
|
53
|
+
await setRouteStops(database, directionIDMap)
|
|
53
54
|
|
|
54
55
|
describe('The GTFS Route stop merger', () => {
|
|
55
56
|
describe('When processing Metro routes', () => {
|
|
@@ -95,5 +96,11 @@ describe('The GTFS Route stop merger', () => {
|
|
|
95
96
|
expect(stonyPoint.stops[0].stopName).to.equal('Frankston Railway Station')
|
|
96
97
|
expect(stonyPoint.stops[stonyPoint.stops.length - 1].stopName).to.equal('Stony Point Railway Station')
|
|
97
98
|
})
|
|
99
|
+
|
|
100
|
+
it('Should mark the PTV Route direction', async () => {
|
|
101
|
+
let stonyPointRoute = await routes.findDocument({ routeGTFSID: '2-STY' })
|
|
102
|
+
expect(stonyPointRoute.ptvDirections['Stony Point']).to.equal(0)
|
|
103
|
+
expect(stonyPointRoute.ptvDirections['Frankston']).to.equal(1)
|
|
104
|
+
})
|
|
98
105
|
})
|
|
99
106
|
})
|