gtfs 4.0.2 → 4.1.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 +20 -0
- package/README.md +270 -104
- package/lib/db.js +1 -2
- package/lib/gtfs-realtime/service-alerts.js +1 -1
- package/lib/gtfs.js +22 -0
- package/lib/ods/deadhead-times.js +32 -0
- package/lib/ods/deadheads.js +32 -0
- package/lib/ods/ops-locations.js +32 -0
- package/lib/ods/run-events.js +32 -0
- package/lib/ods/runs-pieces.js +32 -0
- package/models/models.js +11 -0
- package/models/ods/deadhead-times.js +60 -0
- package/models/ods/deadheads.js +51 -0
- package/models/ods/ops-locations.js +44 -0
- package/models/ods/run-events.js +65 -0
- package/models/ods/runs-pieces.js +58 -0
- package/package.json +8 -8
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,26 @@ 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.1.0] - 2023-02-25
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- Support for Operational Data Standard (ODS) Files
|
|
13
|
+
|
|
14
|
+
### Updated
|
|
15
|
+
|
|
16
|
+
- Dependency updates
|
|
17
|
+
|
|
18
|
+
## [4.0.3] - 2023-02-04
|
|
19
|
+
|
|
20
|
+
### Changed
|
|
21
|
+
|
|
22
|
+
- Updates to sqlite journal mode
|
|
23
|
+
|
|
24
|
+
### Updated
|
|
25
|
+
|
|
26
|
+
- Dependency updates
|
|
27
|
+
|
|
8
28
|
## [4.0.2] - 2023-01-15
|
|
9
29
|
|
|
10
30
|
### Changed
|
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
<br /><br />
|
|
12
12
|
<a href="https://www.npmjs.com/package/gtfs" rel="nofollow"><img src="https://img.shields.io/npm/v/gtfs.svg?style=flat" style="max-width: 100%;"></a>
|
|
13
13
|
<a href="https://www.npmjs.com/package/gtfs" rel="nofollow"><img src="https://img.shields.io/npm/dm/gtfs.svg?style=flat" style="max-width: 100%;"></a>
|
|
14
|
-
<a href="https://github.com/BlinkTagInc/node-gtfs/actions?query=workflow%3A%22Node+CI%22"><img src="https://img.shields.io/github/workflow/status/BlinkTagInc/node-gtfs/
|
|
14
|
+
<a href="https://github.com/BlinkTagInc/node-gtfs/actions?query=workflow%3A%22Node+CI%22"><img src="https://img.shields.io/github/actions/workflow/status/BlinkTagInc/node-gtfs/nodejs.yml?branch=master" style="max-width: 100%;"></a>
|
|
15
15
|
<img src="https://img.shields.io/badge/License-MIT-yellow.svg">
|
|
16
16
|
<br /><br />
|
|
17
17
|
Import and Export GTFS transit data into SQLite. Query or change routes, stops, times, fares and more.
|
|
@@ -493,15 +493,29 @@ await exportGtfs(config);
|
|
|
493
493
|
|
|
494
494
|
## Query Methods
|
|
495
495
|
|
|
496
|
-
This library includes many methods you can use in your project to query GTFS data.
|
|
496
|
+
This library includes many methods you can use in your project to query GTFS data. In addition to standard static GTFS, `node-gtfs` supports the following extensions to GTFS:
|
|
497
497
|
|
|
498
|
-
|
|
498
|
+
- [GTFS-Realtime](https://gtfs.org/realtime/) - Realtime alerts, vehicle positions and predictions
|
|
499
|
+
- [GTFS-Ride](https://gtfsride.org) - Passenger counts
|
|
500
|
+
- [Operational Data Standard (ODS)](https://docs.calitp.org/operational-data-standard/) - Deadheads and personnel info
|
|
501
|
+
- [GTFS-Timetables](https://gtfstohtml.com) - Information for creating human-readable timetables
|
|
499
502
|
|
|
500
|
-
|
|
503
|
+
There are also methods for retrieving stops and shapes in geoJSON format.
|
|
501
504
|
|
|
502
|
-
|
|
505
|
+
Most query methods accept three optional arguments: `query`, `fields`, `sortBy` and `options`.
|
|
503
506
|
|
|
504
|
-
|
|
507
|
+
For more advanced queries, you can use `advancedQuery` or raw SQL queries using query method from [better-sqlite3](#raw-sqlite-query).
|
|
508
|
+
|
|
509
|
+
### Setup
|
|
510
|
+
|
|
511
|
+
To use any of the query methods, first open the database before making any queries:
|
|
512
|
+
|
|
513
|
+
```js
|
|
514
|
+
import { openDb } from 'gtfs';
|
|
515
|
+
const db = openDb(config);
|
|
516
|
+
```
|
|
517
|
+
|
|
518
|
+
### Examples
|
|
505
519
|
|
|
506
520
|
For example, to get a list of all routes with just `route_id`, `route_short_name` and `route_color` sorted by `route_short_name`:
|
|
507
521
|
|
|
@@ -558,21 +572,9 @@ const stops = getStops(
|
|
|
558
572
|
);
|
|
559
573
|
```
|
|
560
574
|
|
|
561
|
-
###
|
|
562
|
-
|
|
563
|
-
Include this library.
|
|
564
|
-
|
|
565
|
-
```js
|
|
566
|
-
import { openDb } from 'gtfs';
|
|
567
|
-
```
|
|
568
|
-
|
|
569
|
-
Open database before making any queries
|
|
570
|
-
|
|
571
|
-
```js
|
|
572
|
-
const db = openDb(config);
|
|
573
|
-
```
|
|
575
|
+
### Static GTFS Files
|
|
574
576
|
|
|
575
|
-
|
|
577
|
+
#### getAgencies(query, fields, sortBy, options)
|
|
576
578
|
|
|
577
579
|
Returns an array of agencies that match query parameters. [Details on agency.txt](https://gtfs.org/schedule/reference/#agencytxt)
|
|
578
580
|
|
|
@@ -588,7 +590,7 @@ const agencies = getAgencies({
|
|
|
588
590
|
});
|
|
589
591
|
```
|
|
590
592
|
|
|
591
|
-
|
|
593
|
+
#### getAreas(query, fields, sortBy, options)
|
|
592
594
|
|
|
593
595
|
Returns an array of areas that match query parameters. [Details on areas.txt](https://gtfs.org/schedule/reference/#areastxt)
|
|
594
596
|
|
|
@@ -604,7 +606,7 @@ const areas = getAreas({
|
|
|
604
606
|
});
|
|
605
607
|
```
|
|
606
608
|
|
|
607
|
-
|
|
609
|
+
#### getAttributions(query, fields, sortBy, options)
|
|
608
610
|
|
|
609
611
|
Returns an array of attributions that match query parameters. [Details on attributions.txt](https://gtfs.org/schedule/reference/#attributionstxt)
|
|
610
612
|
|
|
@@ -620,7 +622,7 @@ const attributions = getAttributions({
|
|
|
620
622
|
});
|
|
621
623
|
```
|
|
622
624
|
|
|
623
|
-
|
|
625
|
+
#### getRoutes(query, fields, sortBy, options)
|
|
624
626
|
|
|
625
627
|
Returns an array of routes that match query parameters. [Details on routes.txt](https://gtfs.org/schedule/reference/#routestxt)
|
|
626
628
|
|
|
@@ -648,7 +650,7 @@ const routes = getRoutes(
|
|
|
648
650
|
);
|
|
649
651
|
```
|
|
650
652
|
|
|
651
|
-
|
|
653
|
+
#### getStops(query, fields, sortBy, options)
|
|
652
654
|
|
|
653
655
|
Returns an array of stops that match query parameters. [Details on stops.txt](https://gtfs.org/schedule/reference/#stopstxt)
|
|
654
656
|
|
|
@@ -688,7 +690,7 @@ const stops = getStops({
|
|
|
688
690
|
});
|
|
689
691
|
```
|
|
690
692
|
|
|
691
|
-
|
|
693
|
+
#### getStopsAsGeoJSON(query, options)
|
|
692
694
|
|
|
693
695
|
Returns geoJSON object of stops that match query parameters. All valid queries for `getStops()` work for `getStopsAsGeoJSON()`.
|
|
694
696
|
|
|
@@ -704,7 +706,7 @@ const stopsGeojson = getStopsAsGeoJSON({
|
|
|
704
706
|
});
|
|
705
707
|
```
|
|
706
708
|
|
|
707
|
-
|
|
709
|
+
#### getStoptimes(query, fields, sortBy, options)
|
|
708
710
|
|
|
709
711
|
Returns an array of stop_times that match query parameters. [Details on stop_times.txt](https://gtfs.org/schedule/reference/#stop_timestxt)
|
|
710
712
|
|
|
@@ -735,7 +737,7 @@ const stoptimes = getStoptimes({
|
|
|
735
737
|
});
|
|
736
738
|
```
|
|
737
739
|
|
|
738
|
-
|
|
740
|
+
#### getTrips(query, fields, sortBy, options)
|
|
739
741
|
|
|
740
742
|
Returns an array of trips that match query parameters. [Details on trips.txt](https://gtfs.org/schedule/reference/#tripstxt)
|
|
741
743
|
|
|
@@ -765,7 +767,7 @@ const trips = getTrips({
|
|
|
765
767
|
});
|
|
766
768
|
```
|
|
767
769
|
|
|
768
|
-
|
|
770
|
+
#### getShapes(query, fields, sortBy, options)
|
|
769
771
|
|
|
770
772
|
Returns an array of shapes that match query parameters. [Details on shapes.txt](https://gtfs.org/schedule/reference/#shapestxt)
|
|
771
773
|
|
|
@@ -800,7 +802,7 @@ const shapes = getShapes({
|
|
|
800
802
|
});
|
|
801
803
|
```
|
|
802
804
|
|
|
803
|
-
|
|
805
|
+
#### getShapesAsGeoJSON(query, options)
|
|
804
806
|
|
|
805
807
|
Returns a geoJSON object of shapes that match query parameters. All valid queries for `getShapes()` work for `getShapesAsGeoJSON()`.
|
|
806
808
|
|
|
@@ -831,7 +833,7 @@ const shapesGeojson = getShapesAsGeoJSON({
|
|
|
831
833
|
});
|
|
832
834
|
```
|
|
833
835
|
|
|
834
|
-
|
|
836
|
+
#### getCalendars(query, fields, sortBy, options)
|
|
835
837
|
|
|
836
838
|
Returns an array of calendars that match query parameters. [Details on calendar.txt](https://gtfs.org/schedule/reference/#calendartxt)
|
|
837
839
|
|
|
@@ -847,7 +849,7 @@ const calendars = getCalendars({
|
|
|
847
849
|
});
|
|
848
850
|
```
|
|
849
851
|
|
|
850
|
-
|
|
852
|
+
#### getCalendarDates(query, fields, sortBy, options)
|
|
851
853
|
|
|
852
854
|
Returns an array of calendar_dates that match query parameters. [Details on calendar_dates.txt](https://gtfs.org/schedule/reference/#calendar_datestxt)
|
|
853
855
|
|
|
@@ -863,7 +865,7 @@ const calendarDates = getCalendarDates({
|
|
|
863
865
|
});
|
|
864
866
|
```
|
|
865
867
|
|
|
866
|
-
|
|
868
|
+
#### getFareAttributes(query, fields, sortBy, options)
|
|
867
869
|
|
|
868
870
|
Returns an array of fare_attributes that match query parameters. [Details on fare_attributes.txt](https://gtfs.org/schedule/reference/#fare_attributestxt)
|
|
869
871
|
|
|
@@ -879,7 +881,7 @@ const fareAttributes = getFareAttributes({
|
|
|
879
881
|
});
|
|
880
882
|
```
|
|
881
883
|
|
|
882
|
-
|
|
884
|
+
#### getFareLegRules(query, fields, sortBy, options)
|
|
883
885
|
|
|
884
886
|
Returns an array of fare_leg_rules that match query parameters. [Details on fare_leg_rules.txt](https://gtfs.org/schedule/reference/#fare_leg_rulestxt)
|
|
885
887
|
|
|
@@ -895,7 +897,7 @@ const fareLegRules = getFareLegRules({
|
|
|
895
897
|
});
|
|
896
898
|
```
|
|
897
899
|
|
|
898
|
-
|
|
900
|
+
#### getFareProducts(query, fields, sortBy, options)
|
|
899
901
|
|
|
900
902
|
Returns an array of fare_products that match query parameters. [Details on fare_products.txt](https://gtfs.org/schedule/reference/#fare_productstxt)
|
|
901
903
|
|
|
@@ -911,7 +913,7 @@ const fareProducts = getFareProducts({
|
|
|
911
913
|
});
|
|
912
914
|
```
|
|
913
915
|
|
|
914
|
-
|
|
916
|
+
#### getFareRules(query, fields, sortBy, options)
|
|
915
917
|
|
|
916
918
|
Returns an array of fare_rules that match query parameters. [Details on fare_rules.txt](https://gtfs.org/schedule/reference/#fare_rulestxt)
|
|
917
919
|
|
|
@@ -927,7 +929,7 @@ const fareRules = getFareRules({
|
|
|
927
929
|
});
|
|
928
930
|
```
|
|
929
931
|
|
|
930
|
-
|
|
932
|
+
#### getFareTransferRules(query, fields, sortBy, options)
|
|
931
933
|
|
|
932
934
|
Returns an array of fare_transfer_rules that match query parameters. [Details on fare_transfer_rules.txt](https://gtfs.org/schedule/reference/#fare_transfer_rulestxt)
|
|
933
935
|
|
|
@@ -943,7 +945,7 @@ const fareTransferRules = getFareTransferRules({
|
|
|
943
945
|
});
|
|
944
946
|
```
|
|
945
947
|
|
|
946
|
-
|
|
948
|
+
#### getFeedInfo(query, fields, sortBy, options)
|
|
947
949
|
|
|
948
950
|
Returns an array of feed_info that match query parameters. [Details on feed_info.txt](https://gtfs.org/schedule/reference/#feed_infotxt)
|
|
949
951
|
|
|
@@ -954,7 +956,7 @@ import { getFeedInfo } from 'gtfs';
|
|
|
954
956
|
const feedInfo = getFeedInfo();
|
|
955
957
|
```
|
|
956
958
|
|
|
957
|
-
|
|
959
|
+
#### getFrequencies(query, fields, sortBy, options)
|
|
958
960
|
|
|
959
961
|
Returns an array of frequencies that match query parameters. [Details on frequencies.txt](https://gtfs.org/schedule/reference/#frequenciestxt)
|
|
960
962
|
|
|
@@ -970,7 +972,7 @@ const frequencies = getFrequencies({
|
|
|
970
972
|
});
|
|
971
973
|
```
|
|
972
974
|
|
|
973
|
-
|
|
975
|
+
#### getLevels(query, fields, sortBy, options)
|
|
974
976
|
|
|
975
977
|
Returns an array of levels that match query parameters. [Details on levels.txt](https://gtfs.org/schedule/reference/#levelstxt)
|
|
976
978
|
|
|
@@ -981,7 +983,7 @@ import { getLevels } from 'gtfs';
|
|
|
981
983
|
const levels = getLevels();
|
|
982
984
|
```
|
|
983
985
|
|
|
984
|
-
|
|
986
|
+
#### getPathways(query, fields, sortBy, options)
|
|
985
987
|
|
|
986
988
|
Returns an array of pathways that match query parameters. [Details on pathways.txt](https://gtfs.org/schedule/reference/#pathwaystxt)
|
|
987
989
|
|
|
@@ -992,7 +994,7 @@ import { getPathways } from 'gtfs';
|
|
|
992
994
|
const pathways = getPathways();
|
|
993
995
|
```
|
|
994
996
|
|
|
995
|
-
|
|
997
|
+
#### getTransfers(query, fields, sortBy, options)
|
|
996
998
|
|
|
997
999
|
Returns an array of transfers that match query parameters. [Details on transfers.txt](https://gtfs.org/schedule/reference/#transferstxt)
|
|
998
1000
|
|
|
@@ -1008,7 +1010,7 @@ const transfers = getTransfers({
|
|
|
1008
1010
|
});
|
|
1009
1011
|
```
|
|
1010
1012
|
|
|
1011
|
-
|
|
1013
|
+
#### getTranslations(query, fields, sortBy, options)
|
|
1012
1014
|
|
|
1013
1015
|
Returns an array of translations that match query parameters. [Details on translations.txt](https://gtfs.org/schedule/reference/#translationstxt)
|
|
1014
1016
|
|
|
@@ -1019,7 +1021,7 @@ import { getTranslations } from 'gtfs';
|
|
|
1019
1021
|
const translations = getTranslations();
|
|
1020
1022
|
```
|
|
1021
1023
|
|
|
1022
|
-
|
|
1024
|
+
#### getStopAreas(query, fields, sortBy, options)
|
|
1023
1025
|
|
|
1024
1026
|
Returns an array of stop_areas that match query parameters. [Details on stop_areas.txt](https://gtfs.org/schedule/reference/#stop_areastxt)
|
|
1025
1027
|
|
|
@@ -1030,45 +1032,9 @@ import { getStopAreas } from 'gtfs';
|
|
|
1030
1032
|
const stopAreas = getStopAreas();
|
|
1031
1033
|
```
|
|
1032
1034
|
|
|
1033
|
-
###
|
|
1034
|
-
|
|
1035
|
-
Returns an array of directions that match query parameters. This is for the non-standard `directions.txt` file. [Details on directions.txt](https://trilliumtransit.com/gtfs/reference/#directions)
|
|
1036
|
-
|
|
1037
|
-
```js
|
|
1038
|
-
import { getDirections } from 'gtfs';
|
|
1039
|
-
|
|
1040
|
-
// Get all directions
|
|
1041
|
-
const directions = getDirections();
|
|
1042
|
-
|
|
1043
|
-
// Get directions for a specific route
|
|
1044
|
-
const directions = getDirections({
|
|
1045
|
-
route_id: '1234',
|
|
1046
|
-
});
|
|
1047
|
-
|
|
1048
|
-
// Get directions for a specific route and direction
|
|
1049
|
-
const directions = getDirections({
|
|
1050
|
-
route_id: '1234',
|
|
1051
|
-
direction_id: 1,
|
|
1052
|
-
});
|
|
1053
|
-
```
|
|
1054
|
-
|
|
1055
|
-
### getStopAttributes(query, fields, sortBy, options)
|
|
1056
|
-
|
|
1057
|
-
Returns an array of stop_attributes that match query parameters. This is for the non-standard `stop_attributes.txt` file. [Details on stop_attributes.txt](https://trilliumtransit.com/gtfs/reference/#stop_attributes)
|
|
1058
|
-
|
|
1059
|
-
```js
|
|
1060
|
-
import { getStopAttributes } from 'gtfs';
|
|
1061
|
-
|
|
1062
|
-
// Get all stop attributes
|
|
1063
|
-
const stopAttributes = getStopAttributes();
|
|
1064
|
-
|
|
1065
|
-
// Get stop attributes for specific stop
|
|
1066
|
-
const stopAttributes = getStopAttributes({
|
|
1067
|
-
stop_id: '1234',
|
|
1068
|
-
});
|
|
1069
|
-
```
|
|
1035
|
+
### GTFS-Timetables files
|
|
1070
1036
|
|
|
1071
|
-
|
|
1037
|
+
#### getTimetables(query, fields, sortBy, options)
|
|
1072
1038
|
|
|
1073
1039
|
Returns an array of timetables that match query parameters. This is for the non-standard `timetables.txt` file used in GTFS-to-HTML. [Details on timetables.txt](https://gtfstohtml.com/docs/timetables)
|
|
1074
1040
|
|
|
@@ -1084,7 +1050,7 @@ const timetables = getTimetables({
|
|
|
1084
1050
|
});
|
|
1085
1051
|
```
|
|
1086
1052
|
|
|
1087
|
-
|
|
1053
|
+
#### getTimetableStopOrders(query, fields, sortBy, options)
|
|
1088
1054
|
|
|
1089
1055
|
Returns an array of timetable_stop_orders that match query parameters. This is for the non-standard `timetable_stop_order.txt` file used in GTFS-to-HTML. [Details on timetable_stop_order.txt](https://gtfstohtml.com/docs/timetable-stop-order)
|
|
1090
1056
|
|
|
@@ -1100,7 +1066,7 @@ const timetableStopOrders = getTimetableStopOrders({
|
|
|
1100
1066
|
});
|
|
1101
1067
|
```
|
|
1102
1068
|
|
|
1103
|
-
|
|
1069
|
+
#### getTimetablePages(query, fields, sortBy, options)
|
|
1104
1070
|
|
|
1105
1071
|
Returns an array of timetable_pages that match query parameters. This is for the non-standard `timetable_pages.txt` file used in GTFS-to-HTML. [Details on timetable_pages.txt](https://gtfstohtml.com/docs/timetable-pages)
|
|
1106
1072
|
|
|
@@ -1116,7 +1082,7 @@ const timetablePages = getTimetablePages({
|
|
|
1116
1082
|
});
|
|
1117
1083
|
```
|
|
1118
1084
|
|
|
1119
|
-
|
|
1085
|
+
#### getTimetableNotes(query, fields, sortBy, options)
|
|
1120
1086
|
|
|
1121
1087
|
Returns an array of timetable_notes that match query parameters. This is for the non-standard `timetable_notes.txt` file used in GTFS-to-HTML. [Details on timetable_notes.txt](https://gtfstohtml.com/docs/timetable-notes)
|
|
1122
1088
|
|
|
@@ -1132,7 +1098,7 @@ const timetableNotes = getTimetableNotes({
|
|
|
1132
1098
|
});
|
|
1133
1099
|
```
|
|
1134
1100
|
|
|
1135
|
-
|
|
1101
|
+
#### getTimetableNotesReferences(query, fields, sortBy, options)
|
|
1136
1102
|
|
|
1137
1103
|
Returns an array of timetable_notes_references that match query parameters. This is for the non-standard `timetable_notes_references.txt` file used in GTFS-to-HTML. [Details on timetable_notes_references.txt](https://gtfstohtml.com/docs/timetable-notes-references)
|
|
1138
1104
|
|
|
@@ -1148,20 +1114,13 @@ const timetableNotesReferences = getTimetableNotesReferences({
|
|
|
1148
1114
|
});
|
|
1149
1115
|
```
|
|
1150
1116
|
|
|
1151
|
-
###
|
|
1152
|
-
|
|
1153
|
-
Returns an array of trips_dated_vehicle_journey that match query parameters. This is for the non-standard `trips_dated_vehicle_journey.txt` file. [Details on trips_dated_vehicle_journey.txt](https://www.trafiklab.se/api/trafiklab-apis/gtfs-regional/extra-files/)
|
|
1154
|
-
|
|
1155
|
-
```js
|
|
1156
|
-
import { getTripsDatedVehicleJourneys } from 'gtfs';
|
|
1117
|
+
### GTFS-Realtime
|
|
1157
1118
|
|
|
1158
|
-
|
|
1159
|
-
const tripsDatedVehicleJourneys = getTripsDatedVehicleJourneys();
|
|
1160
|
-
```
|
|
1119
|
+
In order to use GTFS-Realtime query methods, you must first configure GTFS Realtime import in node-gtfs
|
|
1161
1120
|
|
|
1162
|
-
|
|
1121
|
+
#### getServiceAlerts(query, fields, sortBy, options)
|
|
1163
1122
|
|
|
1164
|
-
Returns an array of GTFS Realtime service alerts that match query parameters.
|
|
1123
|
+
Returns an array of GTFS Realtime service alerts that match query parameters. [Details on Service Alerts](https://gtfs.org/realtime/feed-entities/service-alerts/)
|
|
1165
1124
|
|
|
1166
1125
|
```js
|
|
1167
1126
|
import { getServiceAlerts } from 'gtfs';
|
|
@@ -1170,9 +1129,9 @@ import { getServiceAlerts } from 'gtfs';
|
|
|
1170
1129
|
const serviceAlerts = getServiceAlerts();
|
|
1171
1130
|
```
|
|
1172
1131
|
|
|
1173
|
-
|
|
1132
|
+
#### getTripUpdates(query, fields, sortBy, options)
|
|
1174
1133
|
|
|
1175
|
-
Returns an array of GTFS Realtime trip updates that match query parameters.
|
|
1134
|
+
Returns an array of GTFS Realtime trip updates that match query parameters. [Details on Trip Updates](https://gtfs.org/realtime/feed-entities/trip-updates/)
|
|
1176
1135
|
|
|
1177
1136
|
```js
|
|
1178
1137
|
import { getTripUpdates } from 'gtfs';
|
|
@@ -1181,9 +1140,9 @@ import { getTripUpdates } from 'gtfs';
|
|
|
1181
1140
|
const tripUpdates = getTripUpdates();
|
|
1182
1141
|
```
|
|
1183
1142
|
|
|
1184
|
-
|
|
1143
|
+
#### getStopTimesUpdates(query, fields, sortBy, options)
|
|
1185
1144
|
|
|
1186
|
-
Returns an array of GTFS Realtime stop time updates that match query parameters.
|
|
1145
|
+
Returns an array of GTFS Realtime stop time updates that match query parameters. [Details on Stop Time Updates](https://gtfs.org/realtime/feed-entities/trip-updates/#stoptimeupdate)
|
|
1187
1146
|
|
|
1188
1147
|
```js
|
|
1189
1148
|
import { getStopTimesUpdates } from 'gtfs';
|
|
@@ -1192,9 +1151,9 @@ import { getStopTimesUpdates } from 'gtfs';
|
|
|
1192
1151
|
const stopTimesUpdates = getStopTimesUpdates();
|
|
1193
1152
|
```
|
|
1194
1153
|
|
|
1195
|
-
|
|
1154
|
+
#### getVehiclePositions(query, fields, sortBy, options)
|
|
1196
1155
|
|
|
1197
|
-
Returns an array of GTFS Realtime vehicle positions that match query parameters.
|
|
1156
|
+
Returns an array of GTFS Realtime vehicle positions that match query parameters. [Details on Vehicle Positions](https://gtfs.org/realtime/feed-entities/vehicle-positions/)
|
|
1198
1157
|
|
|
1199
1158
|
```js
|
|
1200
1159
|
import { getVehiclePositions } from 'gtfs';
|
|
@@ -1203,7 +1162,214 @@ import { getVehiclePositions } from 'gtfs';
|
|
|
1203
1162
|
const vehiclePositions = getVehiclePositions();
|
|
1204
1163
|
```
|
|
1205
1164
|
|
|
1206
|
-
###
|
|
1165
|
+
### GTFS-Ride Files
|
|
1166
|
+
|
|
1167
|
+
#### getBoardAlights(query, fields, sortBy, options)
|
|
1168
|
+
|
|
1169
|
+
Returns an array of board_alight that match query parameters. [Details on board_alight.txt](http://gtfsride.org/specification#board_alighttxt)
|
|
1170
|
+
|
|
1171
|
+
```js
|
|
1172
|
+
import { getBoardAlights } from 'gtfs';
|
|
1173
|
+
|
|
1174
|
+
// Get all board_alight
|
|
1175
|
+
const boardAlights = getBoardAlights();
|
|
1176
|
+
|
|
1177
|
+
// Get board_alight for a specific trip
|
|
1178
|
+
const boardAlights = getBoardAlights({
|
|
1179
|
+
trip_id: '123',
|
|
1180
|
+
});
|
|
1181
|
+
```
|
|
1182
|
+
|
|
1183
|
+
#### getRideFeedInfos(query, fields, sortBy, options)
|
|
1184
|
+
|
|
1185
|
+
Returns an array of ride_feed_info that match query parameters. [Details on ride_feed_info.txt](http://gtfsride.org/specification#ride_feed_infotxt)
|
|
1186
|
+
|
|
1187
|
+
```js
|
|
1188
|
+
import { getRideFeedInfos } from 'gtfs';
|
|
1189
|
+
|
|
1190
|
+
// Get all ride_feed_info
|
|
1191
|
+
const rideFeedInfos = getRideFeedInfos();
|
|
1192
|
+
```
|
|
1193
|
+
|
|
1194
|
+
#### getRiderTrips(query, fields, sortBy, options)
|
|
1195
|
+
|
|
1196
|
+
Returns an array of rider_trip that match query parameters. [Details on rider_trip.txt](http://gtfsride.org/specification#rider_triptxt)
|
|
1197
|
+
|
|
1198
|
+
```js
|
|
1199
|
+
import { getRiderTrips } from 'gtfs';
|
|
1200
|
+
|
|
1201
|
+
// Get all rider_trip
|
|
1202
|
+
const riderTrips = getRiderTrips();
|
|
1203
|
+
|
|
1204
|
+
// Get rider_trip for a specific trip
|
|
1205
|
+
const riderTrips = getRiderTrips({
|
|
1206
|
+
trip_id: '123',
|
|
1207
|
+
});
|
|
1208
|
+
```
|
|
1209
|
+
|
|
1210
|
+
#### getRiderships(query, fields, sortBy, options)
|
|
1211
|
+
|
|
1212
|
+
Returns an array of ridership that match query parameters. [Details on ridership.txt](http://gtfsride.org/specification#ridershiptxt)
|
|
1213
|
+
|
|
1214
|
+
```js
|
|
1215
|
+
import { getRiderships } from 'gtfs';
|
|
1216
|
+
|
|
1217
|
+
// Get all ridership
|
|
1218
|
+
const riderships = getRiderships();
|
|
1219
|
+
|
|
1220
|
+
// Get ridership for a specific route
|
|
1221
|
+
const riderships = getRiderships({
|
|
1222
|
+
route_id: '123',
|
|
1223
|
+
});
|
|
1224
|
+
```
|
|
1225
|
+
|
|
1226
|
+
#### getTripCapacities(query, fields, sortBy, options)
|
|
1227
|
+
|
|
1228
|
+
Returns an array of trip_capacity that match query parameters. [Details on trip_capacity.txt](http://gtfsride.org/specification#trip_capacitytxt)
|
|
1229
|
+
|
|
1230
|
+
```js
|
|
1231
|
+
import { getTripCapacities } from 'gtfs';
|
|
1232
|
+
|
|
1233
|
+
// Get all trip_capacity
|
|
1234
|
+
const tripCapacities = getTripCapacities();
|
|
1235
|
+
|
|
1236
|
+
// Get trip_capacity for a specific trip
|
|
1237
|
+
const tripCapacities = getTripCapacities({
|
|
1238
|
+
trip_id: '123',
|
|
1239
|
+
});
|
|
1240
|
+
```
|
|
1241
|
+
|
|
1242
|
+
### Operational Data Standard (ODS) Files
|
|
1243
|
+
|
|
1244
|
+
#### getDeadheads(query, fields, sortBy, options)
|
|
1245
|
+
|
|
1246
|
+
Returns an array of deadheads that match query parameters. [Details on deadheads.txt](https://docs.calitp.org/operational-data-standard/spec/#deadheadstxt)
|
|
1247
|
+
|
|
1248
|
+
```js
|
|
1249
|
+
import { getDeadheads } from 'gtfs';
|
|
1250
|
+
|
|
1251
|
+
// Get all deadheads
|
|
1252
|
+
const deadheads = getDeadheads();
|
|
1253
|
+
|
|
1254
|
+
// Get deadheads for a specific block
|
|
1255
|
+
const deadheads = getDeadheads({
|
|
1256
|
+
block_id: '123',
|
|
1257
|
+
});
|
|
1258
|
+
```
|
|
1259
|
+
|
|
1260
|
+
#### getDeadheadTimes(query, fields, sortBy, options)
|
|
1261
|
+
|
|
1262
|
+
Returns an array of deadhead_times that match query parameters. [Details on deadhead_times.txt](https://docs.calitp.org/operational-data-standard/spec/#deadhead_timestxt)
|
|
1263
|
+
|
|
1264
|
+
```js
|
|
1265
|
+
import { getDeadheadTimes } from 'gtfs';
|
|
1266
|
+
|
|
1267
|
+
// Get all deadhead_times
|
|
1268
|
+
const deadheadTimes = getDeadheadTimes();
|
|
1269
|
+
|
|
1270
|
+
// Get deadhead_times for a specific deadhead
|
|
1271
|
+
const deadheadTimes = getDeadheadTimes({
|
|
1272
|
+
deadhead_id: '123',
|
|
1273
|
+
});
|
|
1274
|
+
```
|
|
1275
|
+
|
|
1276
|
+
#### getOpsLocations(query, fields, sortBy, options)
|
|
1277
|
+
|
|
1278
|
+
Returns an array of ops_locations that match query parameters. [Details on ops_locations.txt](https://docs.calitp.org/operational-data-standard/spec/#ops_locationstxt)
|
|
1279
|
+
|
|
1280
|
+
```js
|
|
1281
|
+
import { getOpsLocations } from 'gtfs';
|
|
1282
|
+
|
|
1283
|
+
// Get all ops_locations
|
|
1284
|
+
const opsLocations = getOpsLocations();
|
|
1285
|
+
|
|
1286
|
+
// Get a specific ops_locations
|
|
1287
|
+
const opsLocations = getOpsLocations({
|
|
1288
|
+
ops_location_id: '123',
|
|
1289
|
+
});
|
|
1290
|
+
```
|
|
1291
|
+
|
|
1292
|
+
#### getRunsPieces(query, fields, sortBy, options)
|
|
1293
|
+
|
|
1294
|
+
Returns an array of runs_pieces that match query parameters. [Details on runs_pieces.txt](https://docs.calitp.org/operational-data-standard/spec/#runs_piecestxt)
|
|
1295
|
+
|
|
1296
|
+
```js
|
|
1297
|
+
import { getRunsPieces } from 'gtfs';
|
|
1298
|
+
|
|
1299
|
+
// Get all runs_pieces
|
|
1300
|
+
const runsPieces = getRunsPieces();
|
|
1301
|
+
```
|
|
1302
|
+
|
|
1303
|
+
#### getRunEvents(query, fields, sortBy, options)
|
|
1304
|
+
|
|
1305
|
+
Returns an array of run_events that match query parameters. [Details on run_events.txt](https://docs.calitp.org/operational-data-standard/spec/#run_eventstxt)
|
|
1306
|
+
|
|
1307
|
+
```js
|
|
1308
|
+
import { getRunEvents } from 'gtfs';
|
|
1309
|
+
|
|
1310
|
+
// Get all run_events
|
|
1311
|
+
const runEvents = runEvents();
|
|
1312
|
+
|
|
1313
|
+
// Get a run_events for a specific piece
|
|
1314
|
+
const runEvents = runEvents({
|
|
1315
|
+
piece_id: '123',
|
|
1316
|
+
});
|
|
1317
|
+
```
|
|
1318
|
+
|
|
1319
|
+
### Non-standard GTFS Files
|
|
1320
|
+
|
|
1321
|
+
#### getDirections(query, fields, sortBy, options)
|
|
1322
|
+
|
|
1323
|
+
Returns an array of directions that match query parameters. This is for the non-standard `directions.txt` file. [Details on directions.txt](https://trilliumtransit.com/gtfs/reference/#directions)
|
|
1324
|
+
|
|
1325
|
+
```js
|
|
1326
|
+
import { getDirections } from 'gtfs';
|
|
1327
|
+
|
|
1328
|
+
// Get all directions
|
|
1329
|
+
const directions = getDirections();
|
|
1330
|
+
|
|
1331
|
+
// Get directions for a specific route
|
|
1332
|
+
const directions = getDirections({
|
|
1333
|
+
route_id: '1234',
|
|
1334
|
+
});
|
|
1335
|
+
|
|
1336
|
+
// Get directions for a specific route and direction
|
|
1337
|
+
const directions = getDirections({
|
|
1338
|
+
route_id: '1234',
|
|
1339
|
+
direction_id: 1,
|
|
1340
|
+
});
|
|
1341
|
+
```
|
|
1342
|
+
|
|
1343
|
+
#### getStopAttributes(query, fields, sortBy, options)
|
|
1344
|
+
|
|
1345
|
+
Returns an array of stop_attributes that match query parameters. This is for the non-standard `stop_attributes.txt` file. [Details on stop_attributes.txt](https://trilliumtransit.com/gtfs/reference/#stop_attributes)
|
|
1346
|
+
|
|
1347
|
+
```js
|
|
1348
|
+
import { getStopAttributes } from 'gtfs';
|
|
1349
|
+
|
|
1350
|
+
// Get all stop attributes
|
|
1351
|
+
const stopAttributes = getStopAttributes();
|
|
1352
|
+
|
|
1353
|
+
// Get stop attributes for specific stop
|
|
1354
|
+
const stopAttributes = getStopAttributes({
|
|
1355
|
+
stop_id: '1234',
|
|
1356
|
+
});
|
|
1357
|
+
```
|
|
1358
|
+
|
|
1359
|
+
#### getTripsDatedVehicleJourneys(query, fields, sortBy, options)
|
|
1360
|
+
|
|
1361
|
+
Returns an array of trips_dated_vehicle_journey that match query parameters. This is for the non-standard `trips_dated_vehicle_journey.txt` file. [Details on trips_dated_vehicle_journey.txt](https://www.trafiklab.se/api/trafiklab-apis/gtfs-regional/extra-files/)
|
|
1362
|
+
|
|
1363
|
+
```js
|
|
1364
|
+
import { getTripsDatedVehicleJourneys } from 'gtfs';
|
|
1365
|
+
|
|
1366
|
+
// Get all trips_dated_vehicle_journey
|
|
1367
|
+
const tripsDatedVehicleJourneys = getTripsDatedVehicleJourneys();
|
|
1368
|
+
```
|
|
1369
|
+
|
|
1370
|
+
### Advanced Query Methods
|
|
1371
|
+
|
|
1372
|
+
#### advancedQuery(table, advancedQueryOptions)
|
|
1207
1373
|
|
|
1208
1374
|
Queries the database with support for table joins and custom tables and returns an array of data.
|
|
1209
1375
|
|
|
@@ -1228,7 +1394,7 @@ const advancedQueryOptions = {
|
|
|
1228
1394
|
const stoptimes = advancedQuery('stop_times', advancedQueryOptions);
|
|
1229
1395
|
```
|
|
1230
1396
|
|
|
1231
|
-
|
|
1397
|
+
#### Raw SQLite Query
|
|
1232
1398
|
|
|
1233
1399
|
Use the `openDb` function to get the db object, and then use any query method from [better-sqlite3](https://github.com/WiseLibs/better-sqlite3) to query GTFS data.
|
|
1234
1400
|
|
package/lib/db.js
CHANGED
|
@@ -37,9 +37,8 @@ export function openDb(config) {
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
export function setupDb(db) {
|
|
40
|
-
db.pragma('journal_mode =
|
|
40
|
+
db.pragma('journal_mode = OFF');
|
|
41
41
|
db.pragma('synchronous = OFF');
|
|
42
|
-
db.pragma('locking_mode = EXCLUSIVE');
|
|
43
42
|
db.pragma('temp_store = MEMORY');
|
|
44
43
|
}
|
|
45
44
|
|
|
@@ -11,7 +11,7 @@ import serviceAlerts from '../../models/gtfs-realtime/service-alerts.js';
|
|
|
11
11
|
import serviceAlertTargets from '../../models/gtfs-realtime/service-alert-targets.js';
|
|
12
12
|
|
|
13
13
|
/*
|
|
14
|
-
* Returns an array of all
|
|
14
|
+
* Returns an array of all service alerts that match the query parameters.
|
|
15
15
|
*/
|
|
16
16
|
export function getServiceAlerts(
|
|
17
17
|
query = {},
|
package/lib/gtfs.js
CHANGED
|
@@ -51,6 +51,13 @@ import { getTripUpdates } from './gtfs-realtime/trip-updates.js';
|
|
|
51
51
|
import { getVehiclePositions } from './gtfs-realtime/vehicle-positions.js';
|
|
52
52
|
import { getServiceAlerts } from './gtfs-realtime/service-alerts.js';
|
|
53
53
|
|
|
54
|
+
// ODS Filenames
|
|
55
|
+
import { getDeadheads } from './ods/deadheads.js';
|
|
56
|
+
import { getDeadheadTimes } from './ods/deadhead-times.js';
|
|
57
|
+
import { getOpsLocations } from './ods/ops-locations.js';
|
|
58
|
+
import { getRunEvents } from './ods/run-events.js';
|
|
59
|
+
import { getRunsPieces } from './ods/runs-pieces.js';
|
|
60
|
+
|
|
54
61
|
// Expose database connection
|
|
55
62
|
import { openDb, closeDb } from './db.js';
|
|
56
63
|
|
|
@@ -186,6 +193,21 @@ export { _getVehiclePositions as getVehiclePositions };
|
|
|
186
193
|
const _getServiceAlerts = getServiceAlerts;
|
|
187
194
|
export { _getServiceAlerts as getServiceAlerts };
|
|
188
195
|
|
|
196
|
+
const _getDeadheads = getDeadheads;
|
|
197
|
+
export { _getDeadheads as getDeadheads };
|
|
198
|
+
|
|
199
|
+
const _getDeadheadTimes = getDeadheadTimes;
|
|
200
|
+
export { _getDeadheadTimes as getDeadheadTimes };
|
|
201
|
+
|
|
202
|
+
const _getOpsLocations = getOpsLocations;
|
|
203
|
+
export { _getOpsLocations as getOpsLocations };
|
|
204
|
+
|
|
205
|
+
const _getRunEvents = getRunEvents;
|
|
206
|
+
export { _getRunEvents as getRunEvents };
|
|
207
|
+
|
|
208
|
+
const _getRunsPieces = getRunsPieces;
|
|
209
|
+
export { _getRunsPieces as getRunsPieces };
|
|
210
|
+
|
|
189
211
|
const _openDb = openDb;
|
|
190
212
|
export { _openDb as openDb };
|
|
191
213
|
const _closeDb = closeDb;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import sqlString from 'sqlstring-sqlite';
|
|
2
|
+
|
|
3
|
+
import { openDb } from '../db.js';
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
formatOrderByClause,
|
|
7
|
+
formatSelectClause,
|
|
8
|
+
formatWhereClauses,
|
|
9
|
+
} from '../utils.js';
|
|
10
|
+
import deadheadTimes from '../../models/ods/deadhead-times.js';
|
|
11
|
+
|
|
12
|
+
/*
|
|
13
|
+
* Returns an array of all deadhead_times that match the query parameters.
|
|
14
|
+
*/
|
|
15
|
+
export function getDeadheadTimes(
|
|
16
|
+
query = {},
|
|
17
|
+
fields = [],
|
|
18
|
+
orderBy = [],
|
|
19
|
+
options = {}
|
|
20
|
+
) {
|
|
21
|
+
const db = options.db ?? openDb();
|
|
22
|
+
const tableName = sqlString.escapeId(deadheadTimes.filenameBase);
|
|
23
|
+
const selectClause = formatSelectClause(fields);
|
|
24
|
+
const whereClause = formatWhereClauses(query);
|
|
25
|
+
const orderByClause = formatOrderByClause(orderBy);
|
|
26
|
+
|
|
27
|
+
return db
|
|
28
|
+
.prepare(
|
|
29
|
+
`${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`
|
|
30
|
+
)
|
|
31
|
+
.all();
|
|
32
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import sqlString from 'sqlstring-sqlite';
|
|
2
|
+
|
|
3
|
+
import { openDb } from '../db.js';
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
formatOrderByClause,
|
|
7
|
+
formatSelectClause,
|
|
8
|
+
formatWhereClauses,
|
|
9
|
+
} from '../utils.js';
|
|
10
|
+
import deadheads from '../../models/ods/deadheads.js';
|
|
11
|
+
|
|
12
|
+
/*
|
|
13
|
+
* Returns an array of all deadheads that match the query parameters.
|
|
14
|
+
*/
|
|
15
|
+
export function getDeadheads(
|
|
16
|
+
query = {},
|
|
17
|
+
fields = [],
|
|
18
|
+
orderBy = [],
|
|
19
|
+
options = {}
|
|
20
|
+
) {
|
|
21
|
+
const db = options.db ?? openDb();
|
|
22
|
+
const tableName = sqlString.escapeId(deadheads.filenameBase);
|
|
23
|
+
const selectClause = formatSelectClause(fields);
|
|
24
|
+
const whereClause = formatWhereClauses(query);
|
|
25
|
+
const orderByClause = formatOrderByClause(orderBy);
|
|
26
|
+
|
|
27
|
+
return db
|
|
28
|
+
.prepare(
|
|
29
|
+
`${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`
|
|
30
|
+
)
|
|
31
|
+
.all();
|
|
32
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import sqlString from 'sqlstring-sqlite';
|
|
2
|
+
|
|
3
|
+
import { openDb } from '../db.js';
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
formatOrderByClause,
|
|
7
|
+
formatSelectClause,
|
|
8
|
+
formatWhereClauses,
|
|
9
|
+
} from '../utils.js';
|
|
10
|
+
import opsLocations from '../../models/ods/ops-locations.js';
|
|
11
|
+
|
|
12
|
+
/*
|
|
13
|
+
* Returns an array of all ops_locations that match the query parameters.
|
|
14
|
+
*/
|
|
15
|
+
export function getOpsLocations(
|
|
16
|
+
query = {},
|
|
17
|
+
fields = [],
|
|
18
|
+
orderBy = [],
|
|
19
|
+
options = {}
|
|
20
|
+
) {
|
|
21
|
+
const db = options.db ?? openDb();
|
|
22
|
+
const tableName = sqlString.escapeId(opsLocations.filenameBase);
|
|
23
|
+
const selectClause = formatSelectClause(fields);
|
|
24
|
+
const whereClause = formatWhereClauses(query);
|
|
25
|
+
const orderByClause = formatOrderByClause(orderBy);
|
|
26
|
+
|
|
27
|
+
return db
|
|
28
|
+
.prepare(
|
|
29
|
+
`${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`
|
|
30
|
+
)
|
|
31
|
+
.all();
|
|
32
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import sqlString from 'sqlstring-sqlite';
|
|
2
|
+
|
|
3
|
+
import { openDb } from '../db.js';
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
formatOrderByClause,
|
|
7
|
+
formatSelectClause,
|
|
8
|
+
formatWhereClauses,
|
|
9
|
+
} from '../utils.js';
|
|
10
|
+
import runEvents from '../../models/ods/run-events.js';
|
|
11
|
+
|
|
12
|
+
/*
|
|
13
|
+
* Returns an array of all run_events that match the query parameters.
|
|
14
|
+
*/
|
|
15
|
+
export function getRunEvents(
|
|
16
|
+
query = {},
|
|
17
|
+
fields = [],
|
|
18
|
+
orderBy = [],
|
|
19
|
+
options = {}
|
|
20
|
+
) {
|
|
21
|
+
const db = options.db ?? openDb();
|
|
22
|
+
const tableName = sqlString.escapeId(runEvents.filenameBase);
|
|
23
|
+
const selectClause = formatSelectClause(fields);
|
|
24
|
+
const whereClause = formatWhereClauses(query);
|
|
25
|
+
const orderByClause = formatOrderByClause(orderBy);
|
|
26
|
+
|
|
27
|
+
return db
|
|
28
|
+
.prepare(
|
|
29
|
+
`${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`
|
|
30
|
+
)
|
|
31
|
+
.all();
|
|
32
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import sqlString from 'sqlstring-sqlite';
|
|
2
|
+
|
|
3
|
+
import { openDb } from '../db.js';
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
formatOrderByClause,
|
|
7
|
+
formatSelectClause,
|
|
8
|
+
formatWhereClauses,
|
|
9
|
+
} from '../utils.js';
|
|
10
|
+
import runsPieces from '../../models/ods/runs-pieces.js';
|
|
11
|
+
|
|
12
|
+
/*
|
|
13
|
+
* Returns an array of all runs_pieces that match the query parameters.
|
|
14
|
+
*/
|
|
15
|
+
export function getRunsPieces(
|
|
16
|
+
query = {},
|
|
17
|
+
fields = [],
|
|
18
|
+
orderBy = [],
|
|
19
|
+
options = {}
|
|
20
|
+
) {
|
|
21
|
+
const db = options.db ?? openDb();
|
|
22
|
+
const tableName = sqlString.escapeId(runsPieces.filenameBase);
|
|
23
|
+
const selectClause = formatSelectClause(fields);
|
|
24
|
+
const whereClause = formatWhereClauses(query);
|
|
25
|
+
const orderByClause = formatOrderByClause(orderBy);
|
|
26
|
+
|
|
27
|
+
return db
|
|
28
|
+
.prepare(
|
|
29
|
+
`${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`
|
|
30
|
+
)
|
|
31
|
+
.all();
|
|
32
|
+
}
|
package/models/models.js
CHANGED
|
@@ -42,6 +42,12 @@ import vehiclePositions from './gtfs-realtime/vehicle-positions.js';
|
|
|
42
42
|
import serviceAlerts from './gtfs-realtime/service-alerts.js';
|
|
43
43
|
import serviceAlertTargets from './gtfs-realtime/service-alert-targets.js';
|
|
44
44
|
|
|
45
|
+
import deadheadTimes from './ods/deadhead-times.js';
|
|
46
|
+
import deadheads from './ods/deadheads.js';
|
|
47
|
+
import opsLocations from './ods/ops-locations.js';
|
|
48
|
+
import runEvents from './ods/run-events.js';
|
|
49
|
+
import runsPieces from './ods/runs-pieces.js';
|
|
50
|
+
|
|
45
51
|
const models = [
|
|
46
52
|
agency,
|
|
47
53
|
areas,
|
|
@@ -83,6 +89,11 @@ const models = [
|
|
|
83
89
|
vehiclePositions,
|
|
84
90
|
serviceAlerts,
|
|
85
91
|
serviceAlertTargets,
|
|
92
|
+
deadheadTimes,
|
|
93
|
+
deadheads,
|
|
94
|
+
opsLocations,
|
|
95
|
+
runEvents,
|
|
96
|
+
runsPieces,
|
|
86
97
|
];
|
|
87
98
|
|
|
88
99
|
export default models;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
const model = {
|
|
2
|
+
filenameBase: 'deadhead_times',
|
|
3
|
+
nonstandard: true,
|
|
4
|
+
extension: 'ods',
|
|
5
|
+
schema: [
|
|
6
|
+
{
|
|
7
|
+
name: 'id',
|
|
8
|
+
type: 'integer',
|
|
9
|
+
primary: true,
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
name: 'deadhead_id',
|
|
13
|
+
type: 'varchar(255)',
|
|
14
|
+
required: true,
|
|
15
|
+
index: true,
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
name: 'arrival_time',
|
|
19
|
+
type: 'varchar(255)',
|
|
20
|
+
required: true,
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
name: 'arrival_timestamp',
|
|
24
|
+
type: 'integer',
|
|
25
|
+
index: true,
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
name: 'departure_time',
|
|
29
|
+
type: 'varchar(255)',
|
|
30
|
+
required: true,
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
name: 'departure_timestamp',
|
|
34
|
+
type: 'integer',
|
|
35
|
+
index: true,
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
name: 'ops_location_id',
|
|
39
|
+
type: 'varchar(255)',
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
name: 'stop_id',
|
|
43
|
+
type: 'varchar(255)',
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
name: 'location_sequence',
|
|
47
|
+
type: 'integer',
|
|
48
|
+
required: true,
|
|
49
|
+
min: 0,
|
|
50
|
+
index: true,
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
name: 'shape_dist_traveled',
|
|
54
|
+
type: 'real',
|
|
55
|
+
min: 0,
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export default model;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
const model = {
|
|
2
|
+
filenameBase: 'deadheads',
|
|
3
|
+
nonstandard: true,
|
|
4
|
+
extension: 'ods',
|
|
5
|
+
schema: [
|
|
6
|
+
{
|
|
7
|
+
name: 'deadhead_id',
|
|
8
|
+
type: 'varchar(255)',
|
|
9
|
+
primary: true,
|
|
10
|
+
required: true,
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
name: 'service_id',
|
|
14
|
+
type: 'varchar(255)',
|
|
15
|
+
required: true,
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
name: 'block_id',
|
|
19
|
+
type: 'varchar(255)',
|
|
20
|
+
required: true,
|
|
21
|
+
index: true,
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
name: 'shape_id',
|
|
25
|
+
type: 'varchar(255)',
|
|
26
|
+
index: true,
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
name: 'to_trip_id',
|
|
30
|
+
type: 'varchar(255)',
|
|
31
|
+
index: true,
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
name: 'from_trip_id',
|
|
35
|
+
type: 'varchar(255)',
|
|
36
|
+
index: true,
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
name: 'to_deadhead_id',
|
|
40
|
+
type: 'varchar(255)',
|
|
41
|
+
index: true,
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
name: 'from_deadhead_id',
|
|
45
|
+
type: 'varchar(255)',
|
|
46
|
+
index: true,
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export default model;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
const model = {
|
|
2
|
+
filenameBase: 'ops_locations',
|
|
3
|
+
nonstandard: true,
|
|
4
|
+
extension: 'ods',
|
|
5
|
+
schema: [
|
|
6
|
+
{
|
|
7
|
+
name: 'ops_location_id',
|
|
8
|
+
type: 'varchar(255)',
|
|
9
|
+
primary: true,
|
|
10
|
+
required: true,
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
name: 'ops_location_code',
|
|
14
|
+
type: 'varchar(255)',
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
name: 'ops_location_name',
|
|
18
|
+
type: 'varchar(255)',
|
|
19
|
+
required: true,
|
|
20
|
+
nocase: true,
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
name: 'ops_location_desc',
|
|
24
|
+
type: 'varchar(255)',
|
|
25
|
+
nocase: true,
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
name: 'ops_location_lat',
|
|
29
|
+
type: 'real',
|
|
30
|
+
required: true,
|
|
31
|
+
min: -90,
|
|
32
|
+
max: 90,
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
name: 'ops_location_lon',
|
|
36
|
+
type: 'real',
|
|
37
|
+
required: true,
|
|
38
|
+
min: -180,
|
|
39
|
+
max: 180,
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export default model;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
const model = {
|
|
2
|
+
filenameBase: 'run_event',
|
|
3
|
+
nonstandard: true,
|
|
4
|
+
extension: 'ods',
|
|
5
|
+
schema: [
|
|
6
|
+
{
|
|
7
|
+
name: 'run_event_id',
|
|
8
|
+
type: 'varchar(255)',
|
|
9
|
+
primary: true,
|
|
10
|
+
required: true,
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
name: 'piece_id',
|
|
14
|
+
type: 'varchar(255)',
|
|
15
|
+
required: true,
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
name: 'event_type',
|
|
19
|
+
type: 'integer',
|
|
20
|
+
required: true,
|
|
21
|
+
min: 0,
|
|
22
|
+
index: true,
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
name: 'event_name',
|
|
26
|
+
type: 'varchar(255)',
|
|
27
|
+
nocase: true,
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
name: 'event_time',
|
|
31
|
+
type: 'varchar(255)',
|
|
32
|
+
required: true,
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
name: 'event_duration',
|
|
36
|
+
type: 'integer',
|
|
37
|
+
required: true,
|
|
38
|
+
min: 0,
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
name: 'event_from_location_type',
|
|
42
|
+
type: 'integer',
|
|
43
|
+
min: 0,
|
|
44
|
+
max: 1,
|
|
45
|
+
index: true,
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
name: 'event_from_location_id',
|
|
49
|
+
type: 'varchar(255)',
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
name: 'event_to_location_type',
|
|
53
|
+
type: 'integer',
|
|
54
|
+
min: 0,
|
|
55
|
+
max: 1,
|
|
56
|
+
index: true,
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
name: 'event_to_location_id',
|
|
60
|
+
type: 'varchar(255)',
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export default model;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
const model = {
|
|
2
|
+
filenameBase: 'runs_pieces',
|
|
3
|
+
nonstandard: true,
|
|
4
|
+
extension: 'ods',
|
|
5
|
+
schema: [
|
|
6
|
+
{
|
|
7
|
+
name: 'run_id',
|
|
8
|
+
type: 'varchar(255)',
|
|
9
|
+
required: true,
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
name: 'piece_id',
|
|
13
|
+
type: 'varchar(255)',
|
|
14
|
+
primary: true,
|
|
15
|
+
required: true,
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
name: 'start_type',
|
|
19
|
+
type: 'integer',
|
|
20
|
+
required: true,
|
|
21
|
+
min: 0,
|
|
22
|
+
max: 2,
|
|
23
|
+
index: true,
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
name: 'start_trip_id',
|
|
27
|
+
type: 'varchar(255)',
|
|
28
|
+
required: true,
|
|
29
|
+
index: true,
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
name: 'start_trip_position',
|
|
33
|
+
type: 'integer',
|
|
34
|
+
min: 0,
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
name: 'end_type',
|
|
38
|
+
type: 'integer',
|
|
39
|
+
required: true,
|
|
40
|
+
min: 0,
|
|
41
|
+
max: 2,
|
|
42
|
+
index: true,
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
name: 'end_trip_id',
|
|
46
|
+
type: 'varchar(255)',
|
|
47
|
+
required: true,
|
|
48
|
+
index: true,
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
name: 'end_trip_position',
|
|
52
|
+
type: 'integer',
|
|
53
|
+
min: 0,
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export default model;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gtfs",
|
|
3
|
-
"version": "4.0
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"description": "Import GTFS transit data into SQLite and query routes, stops, times, fares and more",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"transit",
|
|
@@ -74,10 +74,10 @@
|
|
|
74
74
|
},
|
|
75
75
|
"dependencies": {
|
|
76
76
|
"@turf/helpers": "^6.5.0",
|
|
77
|
-
"better-sqlite3": "^8.0
|
|
78
|
-
"csv-parse": "^5.3.
|
|
79
|
-
"csv-stringify": "^6.2.
|
|
80
|
-
"gtfs-realtime-bindings": "^
|
|
77
|
+
"better-sqlite3": "^8.1.0",
|
|
78
|
+
"csv-parse": "^5.3.5",
|
|
79
|
+
"csv-stringify": "^6.2.4",
|
|
80
|
+
"gtfs-realtime-bindings": "^1.1.1",
|
|
81
81
|
"lodash-es": "^4.17.21",
|
|
82
82
|
"long": "^5.2.1",
|
|
83
83
|
"node-fetch": "^3.3.0",
|
|
@@ -91,18 +91,18 @@
|
|
|
91
91
|
"tmp-promise": "^3.0.3",
|
|
92
92
|
"untildify": "^4.0.0",
|
|
93
93
|
"unzipper": "^0.10.11",
|
|
94
|
-
"yargs": "^17.
|
|
94
|
+
"yargs": "^17.7.1",
|
|
95
95
|
"yoctocolors": "^1.0.0"
|
|
96
96
|
},
|
|
97
97
|
"devDependencies": {
|
|
98
98
|
"@types/better-sqlite3": "^7.6.3",
|
|
99
99
|
"dtslint": "^4.2.1",
|
|
100
|
-
"eslint": "^8.
|
|
100
|
+
"eslint": "^8.34.0",
|
|
101
101
|
"eslint-config-prettier": "^8.6.0",
|
|
102
102
|
"eslint-config-xo": "^0.43.1",
|
|
103
103
|
"husky": "^8.0.3",
|
|
104
104
|
"mocha": "^10.2.0",
|
|
105
|
-
"prettier": "^2.8.
|
|
105
|
+
"prettier": "^2.8.4",
|
|
106
106
|
"pretty-quick": "^3.1.3",
|
|
107
107
|
"should": "^13.2.3"
|
|
108
108
|
},
|