gtfs 4.3.1 → 4.4.0
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/CHANGELOG.md +13 -0
- package/lib/gtfs/shapes.js +7 -5
- package/lib/gtfs/stops.js +6 -3
- package/lib/import.js +7 -1
- package/lib/utils.js +12 -0
- package/package.json +4 -3
- package/test/mocha/advanced-query.js +8 -8
- package/test/mocha/export-gtfs.js +4 -2
- package/test/mocha/import-gtfs.js +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,19 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [4.4.0] - 2023-06-16
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
|
|
12
|
+
- Pad leading zeros of timestamp columns
|
|
13
|
+
|
|
14
|
+
## [4.3.2] - 2023-06-14
|
|
15
|
+
|
|
16
|
+
### Updated
|
|
17
|
+
|
|
18
|
+
- Dependency updates
|
|
19
|
+
- node-csv `relax_quotes` config
|
|
20
|
+
|
|
8
21
|
## [4.3.1] - 2023-06-06
|
|
9
22
|
|
|
10
23
|
### Added
|
package/lib/gtfs/shapes.js
CHANGED
|
@@ -22,10 +22,10 @@ function buildTripSubquery(query) {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
/*
|
|
25
|
-
* Returns array of shapes that match the query parameters. A `route_id`
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
25
|
+
* Returns array of shapes that match the query parameters. A `route_id` query
|
|
26
|
+
* parameter may be passed to find all shapes for a route. A `trip_id` query
|
|
27
|
+
* parameter may be passed to find all shapes for a trip. A `direction_id`
|
|
28
|
+
* query parameter may be passed to find all shapes for a direction.
|
|
29
29
|
*/
|
|
30
30
|
export function getShapes(query = {}, fields = [], orderBy = [], options = {}) {
|
|
31
31
|
const db = options.db ?? openDb();
|
|
@@ -68,7 +68,9 @@ export function getShapes(query = {}, fields = [], orderBy = [], options = {}) {
|
|
|
68
68
|
|
|
69
69
|
/*
|
|
70
70
|
* Returns geoJSON of the shapes that match the query parameters. A `route_id`
|
|
71
|
-
* query parameter may be passed to find all shapes for a route.
|
|
71
|
+
* query parameter may be passed to find all shapes for a route. A `trip_id`
|
|
72
|
+
* query parameter may be passed to find all shapes for a trip. A
|
|
73
|
+
* `direction_id` query parameter may be passed to find all shapes for a direction.
|
|
72
74
|
*/
|
|
73
75
|
export function getShapesAsGeoJSON(query = {}, options = {}) {
|
|
74
76
|
const agencies = getAgencies({}, [], [], options);
|
package/lib/gtfs/stops.js
CHANGED
|
@@ -29,7 +29,8 @@ function buildStoptimeSubquery(query) {
|
|
|
29
29
|
* Returns an array of stops that match the query parameters. A `route_id`
|
|
30
30
|
* query parameter may be passed to find all shapes for a route. A `trip_id`
|
|
31
31
|
* query parameter may be passed to find all shapes for a trip. A
|
|
32
|
-
* `direction_id` query parameter may be passed to find all shapes for a
|
|
32
|
+
* `direction_id` query parameter may be passed to find all shapes for a
|
|
33
|
+
* direction.
|
|
33
34
|
*/
|
|
34
35
|
export function getStops(query = {}, fields = [], orderBy = [], options = {}) {
|
|
35
36
|
const db = options.db ?? openDb();
|
|
@@ -73,8 +74,10 @@ export function getStops(query = {}, fields = [], orderBy = [], options = {}) {
|
|
|
73
74
|
}
|
|
74
75
|
|
|
75
76
|
/*
|
|
76
|
-
* Returns geoJSON with stops
|
|
77
|
-
*
|
|
77
|
+
* Returns geoJSON with stops. A `route_id` query parameter may be passed to
|
|
78
|
+
* find all shapes for a route. A `trip_id` query parameter may be passed to
|
|
79
|
+
* find all shapes for a trip. A `direction_id` query parameter may be passed
|
|
80
|
+
* to find all shapes for a direction.
|
|
78
81
|
*/
|
|
79
82
|
export function getStopsAsGeoJSON(query = {}, options = {}) {
|
|
80
83
|
const db = options.db ?? openDb();
|
package/lib/import.js
CHANGED
|
@@ -25,6 +25,7 @@ import {
|
|
|
25
25
|
setDefaultConfig,
|
|
26
26
|
validateConfigForImport,
|
|
27
27
|
convertLongTimeToDate,
|
|
28
|
+
padLeadingZeros,
|
|
28
29
|
} from './utils.js';
|
|
29
30
|
|
|
30
31
|
const downloadFiles = async (task) => {
|
|
@@ -434,6 +435,11 @@ const formatLine = (line, model, totalLineCount) => {
|
|
|
434
435
|
if (formattedLine[timestampColumnName]) {
|
|
435
436
|
formattedLine[`${timestampColumnName}stamp`] =
|
|
436
437
|
calculateSecondsFromMidnight(formattedLine[timestampColumnName]);
|
|
438
|
+
|
|
439
|
+
// Ensure leading zeros for time columns
|
|
440
|
+
formattedLine[timestampColumnName] = padLeadingZeros(
|
|
441
|
+
formattedLine[timestampColumnName]
|
|
442
|
+
);
|
|
437
443
|
}
|
|
438
444
|
}
|
|
439
445
|
|
|
@@ -530,7 +536,7 @@ const importFiles = (task) =>
|
|
|
530
536
|
const maxInsertVariables = 800;
|
|
531
537
|
const parser = parse({
|
|
532
538
|
columns: true,
|
|
533
|
-
|
|
539
|
+
relax_quotes: true,
|
|
534
540
|
trim: true,
|
|
535
541
|
skip_empty_lines: true,
|
|
536
542
|
...task.csvOptions,
|
package/lib/utils.js
CHANGED
|
@@ -52,6 +52,18 @@ export function calculateSecondsFromMidnight(time) {
|
|
|
52
52
|
return split[0] * 3600 + split[1] * 60 + split[2];
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
+
/*
|
|
56
|
+
* Adds leading zeros to HH:mm:ss timestamps
|
|
57
|
+
*/
|
|
58
|
+
export function padLeadingZeros(time) {
|
|
59
|
+
const split = time.split(':').map((d) => String(Number(d)).padStart(2, '0'));
|
|
60
|
+
if (split.length !== 3) {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return split.join(':');
|
|
65
|
+
}
|
|
66
|
+
|
|
55
67
|
export function formatSelectClause(fields) {
|
|
56
68
|
if (Array.isArray(fields)) {
|
|
57
69
|
const selectItem =
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gtfs",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.4.0",
|
|
4
4
|
"description": "Import GTFS transit data into SQLite and query routes, stops, times, fares and more",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"transit",
|
|
@@ -56,7 +56,8 @@
|
|
|
56
56
|
"Mike Brocks",
|
|
57
57
|
"Matt Moran",
|
|
58
58
|
"Daniel Sörlöv",
|
|
59
|
-
"Ali Zarghami <alizarghami@gmail.com>"
|
|
59
|
+
"Ali Zarghami <alizarghami@gmail.com>",
|
|
60
|
+
"David Abell"
|
|
60
61
|
],
|
|
61
62
|
"type": "module",
|
|
62
63
|
"main": "index.js",
|
|
@@ -90,7 +91,7 @@
|
|
|
90
91
|
"sqlstring-sqlite": "^0.1.1",
|
|
91
92
|
"strip-bom-stream": "^5.0.0",
|
|
92
93
|
"tmp-promise": "^3.0.3",
|
|
93
|
-
"untildify": "^
|
|
94
|
+
"untildify": "^5.0.0",
|
|
94
95
|
"yargs": "^17.7.2",
|
|
95
96
|
"yoctocolors": "^1.0.0"
|
|
96
97
|
},
|
|
@@ -57,14 +57,14 @@ describe('advancedQuery():', () => {
|
|
|
57
57
|
const results = advancedQuery('stop_times', advancedQueryOptions);
|
|
58
58
|
|
|
59
59
|
const expectedResults = [
|
|
60
|
-
{ trip_id: '329', arrival_time: '
|
|
61
|
-
{ trip_id: '329', arrival_time: '
|
|
62
|
-
{ trip_id: '329', arrival_time: '
|
|
63
|
-
{ trip_id: '329', arrival_time: '
|
|
64
|
-
{ trip_id: '329', arrival_time: '
|
|
65
|
-
{ trip_id: '329', arrival_time: '
|
|
66
|
-
{ trip_id: '329', arrival_time: '
|
|
67
|
-
{ trip_id: '329', arrival_time: '
|
|
60
|
+
{ trip_id: '329', arrival_time: '07:56:00' },
|
|
61
|
+
{ trip_id: '329', arrival_time: '08:03:00' },
|
|
62
|
+
{ trip_id: '329', arrival_time: '08:16:00' },
|
|
63
|
+
{ trip_id: '329', arrival_time: '08:27:00' },
|
|
64
|
+
{ trip_id: '329', arrival_time: '08:35:00' },
|
|
65
|
+
{ trip_id: '329', arrival_time: '08:44:00' },
|
|
66
|
+
{ trip_id: '329', arrival_time: '08:52:00' },
|
|
67
|
+
{ trip_id: '329', arrival_time: '09:09:00' },
|
|
68
68
|
];
|
|
69
69
|
|
|
70
70
|
should.exist(results);
|
|
@@ -65,8 +65,9 @@ describe('exportGtfs():', function () {
|
|
|
65
65
|
const parser = parse(
|
|
66
66
|
{
|
|
67
67
|
columns: true,
|
|
68
|
-
|
|
68
|
+
relax_quotes: true,
|
|
69
69
|
trim: true,
|
|
70
|
+
skip_empty_lines: true,
|
|
70
71
|
},
|
|
71
72
|
(error, data) => {
|
|
72
73
|
if (error) {
|
|
@@ -121,8 +122,9 @@ describe('exportGtfs():', function () {
|
|
|
121
122
|
const parser = parse(
|
|
122
123
|
{
|
|
123
124
|
columns: true,
|
|
124
|
-
|
|
125
|
+
relax_quotes: true,
|
|
125
126
|
trim: true,
|
|
127
|
+
skip_empty_lines: true,
|
|
126
128
|
},
|
|
127
129
|
(error, data) => {
|
|
128
130
|
if (error) {
|