@transportme/load-ptv-gtfs 1.4.24 → 1.4.26

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.
@@ -142,7 +142,7 @@ export default class TripLoader {
142
142
  departureTime: stop.departureTime,
143
143
  departureTimeMinutes: stop.departureTimeMinutes,
144
144
  stopConditions: { pickup: stop.pickup, dropoff: stop.dropoff },
145
- stopDistance: stop.distanceTravelled
145
+ stopDistance: parseFloat(stop.distanceTravelled)
146
146
  }
147
147
 
148
148
  if (bay.parentStopGTFSID) data.stopGTFSID = bay.parentStopGTFSID
@@ -20,87 +20,89 @@ export default async function setRouteStops(database, directionsMap, onMilestone
20
20
  } = {}) {
21
21
  let gtfsTimetables = database.getCollection(timetableColl)
22
22
  let routes = database.getCollection(routeColl)
23
-
24
- let allRoutes = await routes.distinct('routeGTFSID')
23
+
24
+ let totalRouteCount = await routes.countDocuments({})
25
+ let total = totalRouteCount
26
+ let count = 0
25
27
 
26
28
  let stopsByService = {}
27
29
 
28
- let count = 0
29
- let total = allRoutes.length
30
-
31
- await async.forEachLimit(allRoutes, 100, async routeGTFSID => {
32
- let routeData = await routes.findDocument({ routeGTFSID })
33
- let routeVariants = routeData.routePath.map(variant => ({ shapeID: variant.fullGTFSIDs[0], routeGTFSID }))
34
- let routeDirections = [[], []]
35
-
36
- for (let variant of routeVariants) {
37
- let timetable = await gtfsTimetables.findDocument(variant)
38
- if (!timetable) {
39
- console.log('No timetable match for shapeID', variant)
40
- continue
41
- }
30
+ for (let mode of Object.values(TRANSIT_MODES)) {
31
+ let allRoutes = await routes.distinct('routeGTFSID', { mode })
42
32
 
43
- routeDirections[timetable.gtfsDirection].push(timetable.stopTimings.map(stop => ({
44
- stopName: stop.stopName,
45
- stopNumber: stop.stopNumber,
46
- suburb: stop.suburb,
47
- stopGTFSID: stop.stopGTFSID
48
- })))
49
- }
50
-
51
- for (let gtfsDirection = 0; gtfsDirection < routeDirections.length; gtfsDirection++) {
52
- let routeDirection = routeDirections[gtfsDirection]
53
- if (!routeDirection.length) continue
54
-
55
- let directionStops = merge(routeDirection, (a, b) => a.stopName === b.stopName)
56
- let mostCommonDestinations = (await gtfsTimetables.aggregate([
57
- { $match: { routeGTFSID, gtfsDirection } },
58
- { $sortByCount: '$destination' }
59
- ]).toArray()).map(e => e._id)
60
-
61
- let lastStop = directionStops[directionStops.length - 1]
62
- let lastStopName = lastStop.stopName
63
-
64
- let directionName = lastStopName
65
- if (directionName.includes('School') || directionName.includes('College')) {
66
- directionName = mostCommonDestinations[0]
67
- }
33
+ await async.forEachLimit(allRoutes, 30, async routeGTFSID => {
34
+ let routeData = await routes.findDocument({ routeGTFSID }, { 'routePath.path': 0 })
35
+ let routeVariants = routeData.routePath.map(variant => ({ shapeID: variant.fullGTFSIDs[0], routeGTFSID }))
36
+ let routeDirections = [[], []]
37
+
38
+ for (let variant of routeVariants) {
39
+ let timetable = await gtfsTimetables.findDocument(variant, { gtfsDirection: 1, stopTimings: 1 })
40
+ if (!timetable) {
41
+ console.log('No timetable match for shapeID', variant)
42
+ continue
43
+ }
68
44
 
69
- if (!stopsByService[routeGTFSID]) stopsByService[routeGTFSID] = []
70
- stopsByService[routeGTFSID][gtfsDirection] = {
71
- directionName,
72
- gtfsDirection,
73
- stops: directionStops
45
+ routeDirections[timetable.gtfsDirection].push(timetable.stopTimings.map(stop => ({
46
+ stopName: stop.stopName,
47
+ stopNumber: stop.stopNumber,
48
+ suburb: stop.suburb,
49
+ stopGTFSID: stop.stopGTFSID
50
+ })))
74
51
  }
75
52
 
76
- if (routeData.mode === TRANSIT_MODES.metroTrain) {
77
- let currentDir = stopsByService[routeGTFSID][gtfsDirection].directionName
78
- let isUp = currentDir.includes('Flinders Street') || currentDir.includes('Town Hall')
79
-
80
- let directionName = stopsByService[routeGTFSID][gtfsDirection].directionName
81
-
82
- if (routeData.routeName === 'Stony Point') {
83
- isUp = currentDir.includes('Frankston')
84
- directionName = directionName.slice(0, -16)
85
- } else if (routeData.routeName === 'City Circle') {
86
- isUp = false
87
- let directionStops = stopsByService[routeGTFSID][gtfsDirection]
88
- let isClockwise = directionStops.stops[1].stopName === 'Southern Cross Railway Station'
89
- directionName = `City Circle (${isClockwise ? 'Clockwise' : 'Anti-Clockwise'})`
90
- } else {
91
- directionName = isUp ? 'City' : routeData.routeName
53
+ for (let gtfsDirection = 0; gtfsDirection < routeDirections.length; gtfsDirection++) {
54
+ let routeDirection = routeDirections[gtfsDirection]
55
+ if (!routeDirection.length) continue
56
+
57
+ let directionStops = merge(routeDirection, (a, b) => a.stopName === b.stopName)
58
+ let mostCommonDestinations = (await gtfsTimetables.aggregate([
59
+ { $match: { routeGTFSID, gtfsDirection } },
60
+ { $sortByCount: '$destination' }
61
+ ]).toArray()).map(e => e._id)
62
+
63
+ let lastStop = directionStops[directionStops.length - 1]
64
+ let lastStopName = lastStop.stopName
65
+
66
+ let directionName = lastStopName
67
+ if (directionName.includes('School') || directionName.includes('College')) {
68
+ directionName = mostCommonDestinations[0]
69
+ }
70
+
71
+ if (!stopsByService[routeGTFSID]) stopsByService[routeGTFSID] = []
72
+ stopsByService[routeGTFSID][gtfsDirection] = {
73
+ directionName,
74
+ gtfsDirection,
75
+ stops: directionStops
92
76
  }
93
77
 
94
- stopsByService[routeGTFSID][gtfsDirection].directionName = directionName
95
- stopsByService[routeGTFSID][gtfsDirection].trainDirection = isUp ? 'Up' : 'Down'
78
+ if (routeData.mode === TRANSIT_MODES.metroTrain) {
79
+ let currentDir = stopsByService[routeGTFSID][gtfsDirection].directionName
80
+ let isUp = currentDir.includes('Flinders Street') || currentDir.includes('Town Hall')
81
+
82
+ let directionName = stopsByService[routeGTFSID][gtfsDirection].directionName
83
+
84
+ if (routeData.routeName === 'Stony Point') {
85
+ isUp = currentDir.includes('Frankston')
86
+ directionName = directionName.slice(0, -16)
87
+ } else if (routeData.routeName === 'City Circle') {
88
+ isUp = false
89
+ let directionStops = stopsByService[routeGTFSID][gtfsDirection]
90
+ let isClockwise = directionStops.stops[1].stopName === 'Southern Cross Railway Station'
91
+ directionName = `City Circle (${isClockwise ? 'Clockwise' : 'Anti-Clockwise'})`
92
+ } else {
93
+ directionName = isUp ? 'City' : routeData.routeName
94
+ }
95
+
96
+ stopsByService[routeGTFSID][gtfsDirection].directionName = directionName
97
+ stopsByService[routeGTFSID][gtfsDirection].trainDirection = isUp ? 'Up' : 'Down'
98
+ }
96
99
  }
97
- }
98
100
 
99
- if (++count % 25 === 0) onMilestone(count, total)
100
- })
101
+ if (++count % 25 === 0) onMilestone(count, total)
102
+ })
103
+ }
101
104
 
102
105
  let bulkOperations = []
103
-
104
106
  Object.keys(stopsByService).forEach(routeGTFSID => {
105
107
  bulkOperations.push({
106
108
  updateOne: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@transportme/load-ptv-gtfs",
3
- "version": "1.4.24",
3
+ "version": "1.4.26",
4
4
  "description": "",
5
5
  "main": "index.mjs",
6
6
  "scripts": {