@transportme/load-ptv-gtfs 1.4.0 → 1.4.2
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/lib/gtfs-parser/readers/line-reader.mjs +7 -1
- package/lib/post-processing/set-route-stops.mjs +5 -0
- package/package.json +1 -1
- package/test/line-reader.test.mjs +26 -0
- package/test/merge-stops-full.test.mjs +12 -0
- package/test/sample-data/merge/shapes.txt +3 -1
- package/test/sample-data/merge/stop_times.txt +7 -1
- package/test/sample-data/merge/trips.txt +2 -1
- package/test/sample-data/mtm-rail/stops.txt +4 -0
- package/test/sample-data/routes/metro_lines.txt +2 -1
|
@@ -58,7 +58,13 @@ export default class CSVLineReader {
|
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
#setHeaders(line) {
|
|
61
|
-
let parts
|
|
61
|
+
let parts
|
|
62
|
+
if (line.includes('"')) {
|
|
63
|
+
parts = line.match(/"([^"]*)"/g).map(f => f.slice(1, -1))
|
|
64
|
+
} else {
|
|
65
|
+
parts = line.split(',')
|
|
66
|
+
}
|
|
67
|
+
|
|
62
68
|
return this.#headers.reduce((acc, header, i) => {
|
|
63
69
|
acc[header] = parts[i]
|
|
64
70
|
return acc
|
|
@@ -73,6 +73,11 @@ export default async function setRouteStops(database, directionsMap, onMilestone
|
|
|
73
73
|
if (routeData.routeName === 'Stony Point') {
|
|
74
74
|
isUp = currentDir.includes('Frankston')
|
|
75
75
|
directionName = directionName.slice(0, -16)
|
|
76
|
+
} else if (routeData.routeName === 'City Circle') {
|
|
77
|
+
isUp = false
|
|
78
|
+
let directionStops = stopsByService[routeGTFSID][gtfsDirection]
|
|
79
|
+
let isClockwise = directionStops.stops[1].stopName === 'Southern Cross Railway Station'
|
|
80
|
+
directionName = `City Circle (${isClockwise ? 'Clockwise' : 'Anti-Clockwise'})`
|
|
76
81
|
} else {
|
|
77
82
|
directionName = isUp ? 'City' : routeData.routeName
|
|
78
83
|
}
|
package/package.json
CHANGED
|
@@ -9,6 +9,8 @@ const __dirname = path.dirname(__filename)
|
|
|
9
9
|
const stopsFile = path.join(__dirname, 'sample-data', 'gtfs-splitting', 'line_reader_test.txt')
|
|
10
10
|
const oneLineFile = path.join(__dirname, 'sample-data', 'one_line.csv')
|
|
11
11
|
|
|
12
|
+
const noQuotesFile = path.join(__dirname, 'sample-data', 'mtm-rail', 'stops.txt')
|
|
13
|
+
|
|
12
14
|
describe('The CSVLineReader class', () => {
|
|
13
15
|
it('Should open a CSV file and identify the headers', async () => {
|
|
14
16
|
let reader = new CSVLineReader(stopsFile)
|
|
@@ -21,6 +23,30 @@ describe('The CSVLineReader class', () => {
|
|
|
21
23
|
await reader.close()
|
|
22
24
|
})
|
|
23
25
|
|
|
26
|
+
it('Can handle files that are not quoted', async () => {
|
|
27
|
+
let reader = new CSVLineReader(noQuotesFile)
|
|
28
|
+
await reader.open()
|
|
29
|
+
|
|
30
|
+
let line = await reader.nextLine()
|
|
31
|
+
expect(line).to.deep.equal({
|
|
32
|
+
stop_id: '77945',
|
|
33
|
+
stop_code: '',
|
|
34
|
+
stop_name: 'Alamein_Up',
|
|
35
|
+
stop_desc: '',
|
|
36
|
+
stop_lat: '-37.868383',
|
|
37
|
+
stop_lon: '145.079837',
|
|
38
|
+
zone_id: '',
|
|
39
|
+
stop_url: '',
|
|
40
|
+
location_type: '0',
|
|
41
|
+
parent_station: '',
|
|
42
|
+
stop_timezone: '',
|
|
43
|
+
wheelchair_boarding: '',
|
|
44
|
+
platform_code: '',
|
|
45
|
+
tts_stop_name: ''
|
|
46
|
+
})
|
|
47
|
+
await reader.close()
|
|
48
|
+
})
|
|
49
|
+
|
|
24
50
|
it('Should return the first line of the CSV, with the fields mapped to their headers', async () => {
|
|
25
51
|
let reader = new CSVLineReader(stopsFile)
|
|
26
52
|
await reader.open()
|
|
@@ -97,6 +97,18 @@ describe('The GTFS Route stop merger', () => {
|
|
|
97
97
|
expect(stonyPoint.stops[stonyPoint.stops.length - 1].stopName).to.equal('Stony Point Railway Station')
|
|
98
98
|
})
|
|
99
99
|
|
|
100
|
+
it('Should set City Circle trips as Down', async () => {
|
|
101
|
+
let cityCircleRoute = await routes.findDocument({ routeGTFSID: '2-CCL' })
|
|
102
|
+
expect(cityCircleRoute).to.not.be.null
|
|
103
|
+
|
|
104
|
+
let direction = cityCircleRoute.directions.find(dir => dir.directionName === 'City Circle (Clockwise)')
|
|
105
|
+
expect(direction).to.not.be.undefined
|
|
106
|
+
expect(direction.trainDirection).to.equal('Down')
|
|
107
|
+
expect(direction.stops[0].stopName).to.equal('Flinders Street Railway Station')
|
|
108
|
+
expect(direction.stops[direction.stops.length - 2].stopName).to.equal('Parliament Railway Station')
|
|
109
|
+
expect(direction.stops[direction.stops.length - 1].stopName).to.equal('Flinders Street Railway Station')
|
|
110
|
+
})
|
|
111
|
+
|
|
100
112
|
it('Should mark the PTV Route direction', async () => {
|
|
101
113
|
let stonyPointRoute = await routes.findDocument({ routeGTFSID: '2-STY' })
|
|
102
114
|
expect(stonyPointRoute.ptvDirections['Stony Point']).to.equal(0)
|
|
@@ -1219,4 +1219,6 @@ shape_id,shape_pt_lat,shape_pt_lon,shape_pt_sequence,shape_dist_traveled
|
|
|
1219
1219
|
"2-STY-vpt-1.2.H","-38.3735310845842","145.218832701718","146","30453.97"
|
|
1220
1220
|
"2-STY-vpt-1.2.H","-38.3738969985651","145.219785272927","147","30546.45"
|
|
1221
1221
|
"2-STY-vpt-1.2.H","-38.3742189306907","145.221402857812","148","30691.93"
|
|
1222
|
-
"2-STY-vpt-1.2.H","-38.3742345364979","145.221837462187","149","30729.86"
|
|
1222
|
+
"2-STY-vpt-1.2.H","-38.3742345364979","145.221837462187","149","30729.86"
|
|
1223
|
+
"2-CCL-vpt-38.5.H","-37.81853876","144.96484870","1","0.00"
|
|
1224
|
+
"2-CCL-vpt-38.5.H","-37.81922050","144.96266539","2","206.22"
|
|
@@ -94,4 +94,10 @@ trip_id,arrival_time,departure_time,stop_id,stop_sequence,stop_headsign,pickup_t
|
|
|
94
94
|
"02-STY--12-T5-8501","14:33:00","14:33:00","19830","7","","0","0","24765.17"
|
|
95
95
|
"02-STY--12-T5-8501","14:36:00","14:36:00","19829","8","","0","0","27053.40"
|
|
96
96
|
"02-STY--12-T5-8501","14:39:00","14:39:00","19828","9","","0","0","28905.48"
|
|
97
|
-
"02-STY--12-T5-8501","14:43:00","14:43:00","19827","10","","0","0","30729.86"
|
|
97
|
+
"02-STY--12-T5-8501","14:43:00","14:43:00","19827","10","","0","0","30729.86"
|
|
98
|
+
"02-CCL--38-T5_cw-0837","23:51:00","23:51:00","19854","1","","0","0","0.00"
|
|
99
|
+
"02-CCL--38-T5_cw-0837","23:54:00","23:54:00","22180","2","","0","0","1363.56"
|
|
100
|
+
"02-CCL--38-T5_cw-0837","23:56:00","23:56:00","19841","3","","0","0","2443.56"
|
|
101
|
+
"02-CCL--38-T5_cw-0837","23:58:00","23:58:00","19842","4","","0","0","3052.86"
|
|
102
|
+
"02-CCL--38-T5_cw-0837","24:00:00","24:00:00","19843","5","","0","0","4168.05"
|
|
103
|
+
"02-CCL--38-T5_cw-0837","24:03:00","24:03:00","19854","6","","0","0","5603.97"
|
|
@@ -3,4 +3,5 @@ route_id,service_id,trip_id,shape_id,trip_headsign,direction_id,block_id
|
|
|
3
3
|
"aus:vic:vic-02-PKM:","T2_2","02-PKM--12-T5-C001","2-PKM-vpt-1.3.H","East Pakenham","0","10867"
|
|
4
4
|
"aus:vic:vic-02-PKM:","T2_2","02-PKM--12-T5-C002","2-PKM-vpt-1.12.R","Flinders Street","1",""
|
|
5
5
|
"aus:vic:vic-02-STY:","T2_2","02-STY--12-T5-8500","2-STY-vpt-1.1.R","Frankston","1",""
|
|
6
|
-
"aus:vic:vic-02-STY:","T2_2","02-STY--12-T5-8501","2-STY-vpt-1.2.H","Stony Point","0",""
|
|
6
|
+
"aus:vic:vic-02-STY:","T2_2","02-STY--12-T5-8501","2-STY-vpt-1.2.H","Stony Point","0",""
|
|
7
|
+
"aus:vic:vic-02-CCL:","T2_2","02-CCL--38-T5_cw-0837","2-CCL-vpt-38.5.H","Flinders Street via City Loop","0",""
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
stop_id,stop_code,stop_name,stop_desc,stop_lat,stop_lon,zone_id,stop_url,location_type,parent_station,stop_timezone,wheelchair_boarding,platform_code,tts_stop_name
|
|
2
|
+
77945,,Alamein_Up,,-37.868383,145.079837,,,0,,,,,
|
|
3
|
+
77949,,Ashburton_Up,,-37.862461,145.081537,,,0,,,,,
|
|
4
|
+
77972,,Burwood_Up,,-37.851461,145.081497,,,0,,,,,
|
|
@@ -4,4 +4,5 @@ route_id,agency_id,route_short_name,route_long_name,route_type,route_color,route
|
|
|
4
4
|
"aus:vic:vic-02-RCE:","3","Flemington Racecourse","City","2","95979A","000000"
|
|
5
5
|
"aus:vic:vic-02-STY:","3","Stony Point","Stony Point - Frankston","2","028430","FFFFFF"
|
|
6
6
|
"aus:vic:vic-02-PKM:","3","Pakenham","Pakenham - City","2","279FD5","000000"
|
|
7
|
-
"aus:vic:vic-02-PKM:","3","Pakenham","Pakenham - City","2","279FD5","000000"
|
|
7
|
+
"aus:vic:vic-02-PKM:","3","Pakenham","Pakenham - City","2","279FD5","000000"
|
|
8
|
+
"aus:vic:vic-02-CCL:","","City Circle","","2","0072CE","FFFFFF"
|