@transportme/load-ptv-gtfs 1.3.7 → 1.3.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.
package/index.mjs CHANGED
@@ -13,7 +13,6 @@ import { GTFSStopTime } from './lib/gtfs-parser/GTFSStopTime.mjs'
13
13
  import GTFSTrip from './lib/gtfs-parser/GTFSTrip.mjs'
14
14
 
15
15
  import setRouteStops from './lib/post-processing/set-route-stops.mjs'
16
- import setStopServices from './lib/post-processing/set-stop-services.mjs'
17
16
 
18
17
  import GTFSAgencyReader from './lib/gtfs-parser/readers/GTFSAgencyReader.mjs'
19
18
  import GTFSCalendarDateReader from './lib/gtfs-parser/readers/GTFSCalendarDatesReader.mjs'
@@ -41,5 +40,5 @@ export {
41
40
  RouteLoader, ShapeLoader,
42
41
  StopsLoader, TripLoader,
43
42
  GTFSTypes, GTFSReaders,
44
- setRouteStops, setStopServices
43
+ setRouteStops
45
44
  }
@@ -120,10 +120,8 @@ export default class TripLoader {
120
120
  stopDistance: stop.distanceTravelled
121
121
  }
122
122
 
123
- if (bay.platform) {
124
- if (bay.parentStopGTFSID) data.stopGTFSID = bay.parentStopGTFSID
125
- data.platform = bay.platform
126
- }
123
+ if (bay.parentStopGTFSID) data.stopGTFSID = bay.parentStopGTFSID
124
+ if (bay.platform) data.platform = bay.platform
127
125
 
128
126
  return data
129
127
  })
@@ -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.7",
3
+ "version": "1.3.9",
4
4
  "description": "",
5
5
  "main": "index.mjs",
6
6
  "scripts": {
@@ -1,71 +0,0 @@
1
- import DatabaseConnection from '@transportme/database/lib/DatabaseConnection.mjs'
2
- import async from 'async'
3
-
4
- const AGGREGATION_GROUP = {
5
- $group: {
6
- _id: {
7
- routeGTFSID: "$routeGTFSID",
8
- gtfsDirection: "$gtfsDirection",
9
- routeNumber: "$routeNumber"
10
- }
11
- }
12
- }
13
-
14
- function compareService(a, b) {
15
- return a.routeGTFSID.localeCompare(b.routeGTFSID) || a.gtfsDirection - b.gtfsDirection
16
- }
17
-
18
- /**
19
- * Loads service data onto all stops in the database.
20
- *
21
- * @param {DatabaseConnection} database The database connection to use
22
- * @param {function} [onMilestone] A function triggered for every 500 stops processed
23
- */
24
- export default async function setStopServices(database, onMilestone = () => {}) {
25
- let gtfsTimetables = database.getCollection('gtfs timetables')
26
- let stops = database.getCollection('stops')
27
-
28
- let stopIDs = await stops.distinct('_id')
29
-
30
- let total = stopIDs.length
31
-
32
- let count = 0
33
- await async.forEachLimit(stopIDs, 100, async id => {
34
- let stop = await stops.findDocument({ _id: id })
35
-
36
- await async.forEach(stop.bays, async bay => {
37
- let screenServices = await gtfsTimetables.aggregate([
38
- {
39
- $match: {
40
- mode: bay.mode,
41
- stopTimings: {
42
- $elemMatch: { stopGTFSID: bay.stopGTFSID, 'stopConditions.pickup': 0 }
43
- }
44
- }
45
- },
46
- AGGREGATION_GROUP
47
- ]).toArray()
48
-
49
- let services = await gtfsTimetables.aggregate([
50
- {
51
- $match: {
52
- mode: bay.mode,
53
- 'stopTimings.stopGTFSID': bay.stopGTFSID
54
- }
55
- },
56
- AGGREGATION_GROUP
57
- ]).toArray()
58
-
59
- bay.services = services.map(e => e._id).sort(compareService)
60
- bay.screenServices = screenServices.map(e => e._id).sort(compareService)
61
- })
62
-
63
- await stops.updateDocument({ _id: id }, {
64
- $set: {
65
- bays: stop.bays
66
- }
67
- })
68
-
69
- if (++count % 500 === 0) onMilestone(count, total)
70
- })
71
- }
@@ -1,69 +0,0 @@
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 setStopServices from '../lib/post-processing/set-stop-services.mjs'
10
- import suburbs from './sample-data/suburbs.json' with { type: 'json' }
11
-
12
- const __filename = url.fileURLToPath(import.meta.url)
13
- const __dirname = path.dirname(__filename)
14
-
15
- const routesFile = path.join(__dirname, 'sample-data', 'routes', 'metro_lines.txt')
16
- const agencyFile = path.join(__dirname, 'sample-data', 'routes', 'agency.txt')
17
-
18
- const calendarFile = path.join(__dirname, 'sample-data', 'calendar', 'calendar.txt')
19
- const calendarDatesFile = path.join(__dirname, 'sample-data', 'calendar', 'calendar_dates.txt')
20
-
21
- const stopsFile = path.join(__dirname, 'sample-data', 'trips', 'stops.txt')
22
- const stopTimesFile = path.join(__dirname, 'sample-data', 'trips', 'stop_times.txt')
23
- const tripsFile = path.join(__dirname, 'sample-data', 'trips', 'trips.txt')
24
-
25
- describe('The set stop services function', () => {
26
- it('Should set stop and screen services on each bay', async () => {
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
- await tripLoader.loadTrips({
45
- routeIDMap
46
- })
47
-
48
- await setStopServices(database)
49
-
50
- let alamein = await stops.findDocument({ 'bays.stopGTFSID': 'vic:rail:ALM' })
51
- let alameinPlatform = alamein.bays.find(bay => bay.stopGTFSID === 'vic:rail:ALM')
52
- expect(alameinPlatform).to.not.be.null
53
- expect(alameinPlatform.services).to.deep.equal([{
54
- routeGTFSID: "2-ALM",
55
- gtfsDirection: 0,
56
- routeNumber: null
57
- }, {
58
- routeGTFSID: "2-ALM",
59
- gtfsDirection: 1,
60
- routeNumber: null
61
- }])
62
-
63
- expect(alameinPlatform.screenServices, "Only trips from Alamein to Camberwell should have matched").to.deep.equal([{
64
- routeGTFSID: "2-ALM",
65
- gtfsDirection: 1,
66
- routeNumber: null
67
- }])
68
- })
69
- })