@transportme/load-ptv-gtfs 1.3.6 → 1.3.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.
@@ -28,6 +28,7 @@ export default class TripLoader {
28
28
 
29
29
  #shapeIDMap = {}
30
30
  #directionIDMap = {}
31
+ #stopServicesMap = {}
31
32
 
32
33
  #tripsToLoad = []
33
34
 
@@ -172,9 +173,27 @@ export default class TripLoader {
172
173
  if (!this.#directionIDMap[tripData.routeGTFSID]) this.#directionIDMap[tripData.routeGTFSID] = {}
173
174
  this.#directionIDMap[tripData.routeGTFSID][rawTripData.getHeadsign()] = rawTripData.getGTFSDirection()
174
175
 
176
+ this.updateStopServices(processedData)
177
+
175
178
  this.#tripsToLoad.push(processedData)
176
179
  }
177
180
 
181
+ updateStopServices(trip) {
182
+ let { gtfsDirection, routeGTFSID, routeNumber } = trip
183
+ trip.stopTimings.forEach(stop => {
184
+ let { stopGTFSID } = stop
185
+ let serviceID = `${routeGTFSID}-${gtfsDirection}-${routeNumber}`
186
+ if (!this.#stopServicesMap[stopGTFSID]) this.#stopServicesMap[stopGTFSID] = { services: {}, screenServices: {} }
187
+ if (!this.#stopServicesMap[stopGTFSID].services[serviceID]) {
188
+ this.#stopServicesMap[stopGTFSID].services[serviceID] = { routeGTFSID, gtfsDirection, routeNumber }
189
+ }
190
+
191
+ if (stop.stopConditions.pickup === 0 && !this.#stopServicesMap[stopGTFSID].screenServices[serviceID]) {
192
+ this.#stopServicesMap[stopGTFSID].screenServices[serviceID] = { routeGTFSID, gtfsDirection, routeNumber }
193
+ }
194
+ })
195
+ }
196
+
178
197
  /**
179
198
  * Loads the trip data into the database.
180
199
  *
@@ -222,4 +241,16 @@ export default class TripLoader {
222
241
  getDirectionIDMap() {
223
242
  return this.#directionIDMap
224
243
  }
244
+
245
+ getStopServicesMap() {
246
+ let output = {}
247
+ for (let stopGTFSID of Object.keys(this.#stopServicesMap)) {
248
+ let stopServices = this.#stopServicesMap[stopGTFSID]
249
+ output[stopGTFSID] = {
250
+ services: Object.values(stopServices.services),
251
+ screenServices: Object.values(stopServices.screenServices)
252
+ }
253
+ }
254
+ return output
255
+ }
225
256
  }
@@ -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, directionsMap) {
11
+ export default async function setRouteStops(database, directionsMap, onMilestone = () => {}) {
12
12
  let gtfsTimetables = database.getCollection('gtfs timetables')
13
13
  let routes = database.getCollection('routes')
14
14
 
@@ -16,6 +16,7 @@ export default async function setRouteStops(database, directionsMap) {
16
16
 
17
17
  let stopsByService = {}
18
18
 
19
+ let count = 0
19
20
  await async.forEachLimit(allRoutes, 100, async routeGTFSID => {
20
21
  let routeData = await routes.findDocument({ routeGTFSID })
21
22
  let routeVariants = routeData.routePath.map(variant => ({ shapeID: variant.fullGTFSIDs[0], routeGTFSID }))
@@ -78,6 +79,8 @@ export default async function setRouteStops(database, directionsMap) {
78
79
  stopsByService[routeGTFSID][gtfsDirection].trainDirection = isUp ? 'Up' : 'Down'
79
80
  }
80
81
  }
82
+
83
+ if (++count % 25 === 0) onMilestone(count, total)
81
84
  })
82
85
 
83
86
  let bulkOperations = []
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@transportme/load-ptv-gtfs",
3
- "version": "1.3.6",
3
+ "version": "1.3.8",
4
4
  "description": "",
5
5
  "main": "index.mjs",
6
6
  "scripts": {
@@ -139,4 +139,50 @@ describe('The TripLoader class', () => {
139
139
  '2-ALM': { 'Alamein': 0, 'Camberwell': 1 }
140
140
  })
141
141
  })
142
+
143
+ it('Should return a mapping stop services', async () => {
144
+ let database = new LokiDatabaseConnection('test-db')
145
+ let stops = await database.createCollection('stops')
146
+ let routes = await database.createCollection('routes')
147
+ let trips = await database.createCollection('gtfs timetables')
148
+
149
+ let stopLoader = new StopsLoader(stopsFile, suburbs, TRANSIT_MODES.metroTrain, database)
150
+ await stopLoader.loadStops()
151
+
152
+ let routeLoader = new RouteLoader(routesFile, agencyFile, TRANSIT_MODES.metroTrain, database)
153
+ await routeLoader.loadRoutes()
154
+
155
+ let routeIDMap = routeLoader.getRouteIDMap()
156
+
157
+ let tripLoader = new TripLoader({
158
+ tripsFile, stopTimesFile,
159
+ calendarFile, calendarDatesFile
160
+ }, TRANSIT_MODES.metroTrain, database)
161
+
162
+ await tripLoader.loadTrips({ routeIDMap })
163
+
164
+ let stopServicesMap = tripLoader.getStopServicesMap()
165
+
166
+ expect(stopServicesMap['vic:rail:ALM'].services).to.deep.equal([{
167
+ routeGTFSID: '2-ALM',
168
+ gtfsDirection: 1,
169
+ routeNumber: null
170
+ }, {
171
+ routeGTFSID: '2-ALM',
172
+ gtfsDirection: 0,
173
+ routeNumber: null
174
+ }])
175
+
176
+ expect(stopServicesMap['vic:rail:ALM'].screenServices).to.deep.equal([{
177
+ routeGTFSID: '2-ALM',
178
+ gtfsDirection: 1,
179
+ routeNumber: null
180
+ }])
181
+
182
+ expect(stopServicesMap['vic:rail:CAM'].screenServices).to.deep.equal([{
183
+ routeGTFSID: '2-ALM',
184
+ gtfsDirection: 0,
185
+ routeNumber: null
186
+ }])
187
+ })
142
188
  })