datamodels-gtfs 0.1.0__tar.gz
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.
- datamodels_gtfs-0.1.0/.gitignore +8 -0
- datamodels_gtfs-0.1.0/CHANGELOG.md +29 -0
- datamodels_gtfs-0.1.0/LICENSE +21 -0
- datamodels_gtfs-0.1.0/PKG-INFO +278 -0
- datamodels_gtfs-0.1.0/README.md +255 -0
- datamodels_gtfs-0.1.0/pyproject.toml +59 -0
- datamodels_gtfs-0.1.0/scripts/update_proto.py +44 -0
- datamodels_gtfs-0.1.0/scripts/update_schemas.py +83 -0
- datamodels_gtfs-0.1.0/src/datamodels_gtfs/__init__.py +3 -0
- datamodels_gtfs-0.1.0/src/datamodels_gtfs/__main__.py +5 -0
- datamodels_gtfs-0.1.0/src/datamodels_gtfs/cli.py +291 -0
- datamodels_gtfs-0.1.0/src/datamodels_gtfs/feed.py +160 -0
- datamodels_gtfs-0.1.0/src/datamodels_gtfs/ids.py +33 -0
- datamodels_gtfs-0.1.0/src/datamodels_gtfs/lang.py +27 -0
- datamodels_gtfs-0.1.0/src/datamodels_gtfs/ngsi.py +63 -0
- datamodels_gtfs-0.1.0/src/datamodels_gtfs/problems.py +65 -0
- datamodels_gtfs-0.1.0/src/datamodels_gtfs/realtime/LICENSE-gtfs-realtime.txt +201 -0
- datamodels_gtfs-0.1.0/src/datamodels_gtfs/realtime/__init__.py +86 -0
- datamodels_gtfs-0.1.0/src/datamodels_gtfs/realtime/check.py +264 -0
- datamodels_gtfs-0.1.0/src/datamodels_gtfs/realtime/context.py +115 -0
- datamodels_gtfs-0.1.0/src/datamodels_gtfs/realtime/descriptors.py +126 -0
- datamodels_gtfs-0.1.0/src/datamodels_gtfs/realtime/gtfs-realtime.desc +0 -0
- datamodels_gtfs-0.1.0/src/datamodels_gtfs/realtime/gtfs-realtime.proto +1268 -0
- datamodels_gtfs-0.1.0/src/datamodels_gtfs/realtime/proto.py +41 -0
- datamodels_gtfs-0.1.0/src/datamodels_gtfs/realtime/servicealert.py +219 -0
- datamodels_gtfs-0.1.0/src/datamodels_gtfs/realtime/timetable.py +178 -0
- datamodels_gtfs-0.1.0/src/datamodels_gtfs/realtime/tripupdate.py +352 -0
- datamodels_gtfs-0.1.0/src/datamodels_gtfs/realtime/vehicleposition.py +158 -0
- datamodels_gtfs-0.1.0/src/datamodels_gtfs/static/__init__.py +55 -0
- datamodels_gtfs-0.1.0/src/datamodels_gtfs/static/agency.py +71 -0
- datamodels_gtfs-0.1.0/src/datamodels_gtfs/static/attribution.py +101 -0
- datamodels_gtfs-0.1.0/src/datamodels_gtfs/static/calendar.py +69 -0
- datamodels_gtfs-0.1.0/src/datamodels_gtfs/static/calendardate.py +39 -0
- datamodels_gtfs-0.1.0/src/datamodels_gtfs/static/context.py +338 -0
- datamodels_gtfs-0.1.0/src/datamodels_gtfs/static/fareattribute.py +100 -0
- datamodels_gtfs-0.1.0/src/datamodels_gtfs/static/farerule.py +64 -0
- datamodels_gtfs-0.1.0/src/datamodels_gtfs/static/feedinfo.py +71 -0
- datamodels_gtfs-0.1.0/src/datamodels_gtfs/static/frequency.py +70 -0
- datamodels_gtfs-0.1.0/src/datamodels_gtfs/static/route.py +107 -0
- datamodels_gtfs-0.1.0/src/datamodels_gtfs/static/shape.py +105 -0
- datamodels_gtfs-0.1.0/src/datamodels_gtfs/static/stop.py +136 -0
- datamodels_gtfs-0.1.0/src/datamodels_gtfs/static/stoptime.py +243 -0
- datamodels_gtfs-0.1.0/src/datamodels_gtfs/static/transfer.py +128 -0
- datamodels_gtfs-0.1.0/src/datamodels_gtfs/static/trip.py +113 -0
- datamodels_gtfs-0.1.0/src/datamodels_gtfs/translations.py +174 -0
- datamodels_gtfs-0.1.0/src/datamodels_gtfs/validate.py +176 -0
- datamodels_gtfs-0.1.0/tests/__init__.py +0 -0
- datamodels_gtfs-0.1.0/tests/conftest.py +45 -0
- datamodels_gtfs-0.1.0/tests/fixtures/README.md +42 -0
- datamodels_gtfs-0.1.0/tests/fixtures/realtime/servicealert-example.json +27 -0
- datamodels_gtfs-0.1.0/tests/fixtures/realtime/toei-train-alert.pb +0 -0
- datamodels_gtfs-0.1.0/tests/fixtures/realtime/toei-train-static/calendar.txt +2 -0
- datamodels_gtfs-0.1.0/tests/fixtures/realtime/toei-train-static/calendar_dates.txt +6 -0
- datamodels_gtfs-0.1.0/tests/fixtures/realtime/toei-train-static/routes.txt +4 -0
- datamodels_gtfs-0.1.0/tests/fixtures/realtime/toei-train-static/stop_times.txt +60 -0
- datamodels_gtfs-0.1.0/tests/fixtures/realtime/toei-train-static/stops.txt +60 -0
- datamodels_gtfs-0.1.0/tests/fixtures/realtime/toei-train-static/trips.txt +4 -0
- datamodels_gtfs-0.1.0/tests/fixtures/realtime/toei-train-trip-update.pb +0 -0
- datamodels_gtfs-0.1.0/tests/fixtures/realtime/toei-train-vehicle.pb +0 -0
- datamodels_gtfs-0.1.0/tests/fixtures/realtime/tripupdate-example.json +23 -0
- datamodels_gtfs-0.1.0/tests/fixtures/realtime/vehicleposition-example.json +21 -0
- datamodels_gtfs-0.1.0/tests/fixtures/toei-bus/agency.txt +2 -0
- datamodels_gtfs-0.1.0/tests/fixtures/toei-bus/attributions.txt +3 -0
- datamodels_gtfs-0.1.0/tests/fixtures/toei-bus/calendar.txt +61 -0
- datamodels_gtfs-0.1.0/tests/fixtures/toei-bus/calendar_dates.txt +325 -0
- datamodels_gtfs-0.1.0/tests/fixtures/toei-bus/fare_attributes.txt +44 -0
- datamodels_gtfs-0.1.0/tests/fixtures/toei-bus/fare_rules.txt +4 -0
- datamodels_gtfs-0.1.0/tests/fixtures/toei-bus/feed_info.txt +2 -0
- datamodels_gtfs-0.1.0/tests/fixtures/toei-bus/routes.txt +4 -0
- datamodels_gtfs-0.1.0/tests/fixtures/toei-bus/shapes.txt +170 -0
- datamodels_gtfs-0.1.0/tests/fixtures/toei-bus/stop_times.txt +65 -0
- datamodels_gtfs-0.1.0/tests/fixtures/toei-bus/stops.txt +72 -0
- datamodels_gtfs-0.1.0/tests/fixtures/toei-bus/translations.txt +118 -0
- datamodels_gtfs-0.1.0/tests/fixtures/toei-bus/trips.txt +7 -0
- datamodels_gtfs-0.1.0/tests/fixtures/toei-train/agency.txt +2 -0
- datamodels_gtfs-0.1.0/tests/fixtures/toei-train/calendar.txt +5 -0
- datamodels_gtfs-0.1.0/tests/fixtures/toei-train/calendar_dates.txt +16 -0
- datamodels_gtfs-0.1.0/tests/fixtures/toei-train/fare_attributes.txt +12 -0
- datamodels_gtfs-0.1.0/tests/fixtures/toei-train/fare_rules.txt +31 -0
- datamodels_gtfs-0.1.0/tests/fixtures/toei-train/feed_info.txt +2 -0
- datamodels_gtfs-0.1.0/tests/fixtures/toei-train/routes.txt +7 -0
- datamodels_gtfs-0.1.0/tests/fixtures/toei-train/stop_times.txt +227 -0
- datamodels_gtfs-0.1.0/tests/fixtures/toei-train/stops.txt +150 -0
- datamodels_gtfs-0.1.0/tests/fixtures/toei-train/translations.txt +311 -0
- datamodels_gtfs-0.1.0/tests/fixtures/toei-train/trips.txt +13 -0
- datamodels_gtfs-0.1.0/tests/schemas/common/Geometry/v1.0.0.json +180 -0
- datamodels_gtfs-0.1.0/tests/schemas/transit/Agency/v1.json +145 -0
- datamodels_gtfs-0.1.0/tests/schemas/transit/Attribution/v1.json +215 -0
- datamodels_gtfs-0.1.0/tests/schemas/transit/Calendar/v1.json +138 -0
- datamodels_gtfs-0.1.0/tests/schemas/transit/CalendarDate/v1.json +78 -0
- datamodels_gtfs-0.1.0/tests/schemas/transit/FareAttribute/v1.json +129 -0
- datamodels_gtfs-0.1.0/tests/schemas/transit/FareRule/v1.json +93 -0
- datamodels_gtfs-0.1.0/tests/schemas/transit/FeedInfo/v1.json +152 -0
- datamodels_gtfs-0.1.0/tests/schemas/transit/Frequency/v1.json +98 -0
- datamodels_gtfs-0.1.0/tests/schemas/transit/Route/v1.json +251 -0
- datamodels_gtfs-0.1.0/tests/schemas/transit/ServiceAlert/v1.json +291 -0
- datamodels_gtfs-0.1.0/tests/schemas/transit/Shape/v1.json +83 -0
- datamodels_gtfs-0.1.0/tests/schemas/transit/Stop/v1.json +307 -0
- datamodels_gtfs-0.1.0/tests/schemas/transit/StopTime/v1.json +211 -0
- datamodels_gtfs-0.1.0/tests/schemas/transit/Transfer/v1.json +184 -0
- datamodels_gtfs-0.1.0/tests/schemas/transit/Trip/v1.json +221 -0
- datamodels_gtfs-0.1.0/tests/schemas/transit/TripUpdate/v1.json +531 -0
- datamodels_gtfs-0.1.0/tests/schemas/transit/VehiclePosition/v1.json +259 -0
- datamodels_gtfs-0.1.0/tests/test_agency.py +212 -0
- datamodels_gtfs-0.1.0/tests/test_attribution.py +124 -0
- datamodels_gtfs-0.1.0/tests/test_calendar_trip.py +341 -0
- datamodels_gtfs-0.1.0/tests/test_check.py +290 -0
- datamodels_gtfs-0.1.0/tests/test_fares.py +158 -0
- datamodels_gtfs-0.1.0/tests/test_robustness.py +294 -0
- datamodels_gtfs-0.1.0/tests/test_servicealert.py +206 -0
- datamodels_gtfs-0.1.0/tests/test_shape.py +123 -0
- datamodels_gtfs-0.1.0/tests/test_static.py +351 -0
- datamodels_gtfs-0.1.0/tests/test_stoptime.py +234 -0
- datamodels_gtfs-0.1.0/tests/test_transfer.py +178 -0
- datamodels_gtfs-0.1.0/tests/test_tripupdate.py +416 -0
- datamodels_gtfs-0.1.0/tests/test_typed_dates.py +55 -0
- datamodels_gtfs-0.1.0/tests/test_validate_refs.py +67 -0
- datamodels_gtfs-0.1.0/tests/test_vehicleposition.py +313 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to `datamodels-gtfs`. The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and the version numbers follow [Semantic Versioning](https://semver.org/). Before 1.0.0, a minor version may change the command line and the entities written.
|
|
4
|
+
|
|
5
|
+
## [Unreleased]
|
|
6
|
+
|
|
7
|
+
## [0.1.0] - 2026-12-05
|
|
8
|
+
|
|
9
|
+
The first release: every GTFS-JP static type and every GTFS Realtime type of the datamodels.jp `transit` subject, written as NGSI-LD, and `check` for the GTFS-JP v4.0 Part 2 rules that a JSON Schema cannot check (#1).
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- `datamodels-gtfs static`: a GTFS-JP feed (zip or folder) to Agency, FeedInfo, Stop, Route, Shape, Calendar, CalendarDate, Trip, StopTime, Frequency, Transfer, FareAttribute, FareRule and Attribution entities, as NGSI-LD key-values or normalized JSON lines (#2–#9).
|
|
14
|
+
- Entity ids are `urn:ngsi-ld:<Type>:<feedKey>:<ids>`, where the feed key is the publisher's corporate number, a hyphen and a feed name (`--feed-key`).
|
|
15
|
+
- translations.txt becomes LanguageProperty values.
|
|
16
|
+
- Problems are reported in English or Japanese (`--lang`), with the file, line and column; `--problems-json` also writes them as JSON.
|
|
17
|
+
- `--strict` checks at the GTFS-JP level: the international defaults (an empty location_type, route colours, the only agency) are errors instead of being filled in.
|
|
18
|
+
- `datamodels-gtfs realtime`: a GTFS Realtime feed to VehiclePosition, TripUpdate and ServiceAlert entities (#10–#12). With `--static`, ids are checked against the GTFS-JP feed, service days come from its calendar, and stop times are compared with its timetable.
|
|
19
|
+
- `datamodels-gtfs check`: saved GTFS Realtime snapshots against the GTFS-JP v4.0 Part 2 rules (#14, #15):
|
|
20
|
+
- `stale`: header.timestamp more than 10 minutes older than the fetch time;
|
|
21
|
+
- `uncertain-passed` and `inconsistent-delay` at stop events;
|
|
22
|
+
- `alert-old`: an alert that ended more than a week before the feed time;
|
|
23
|
+
- `trip-dropped`: a trip that leaves the feed before 1 minute after its arrival at the last stop.
|
|
24
|
+
- `datamodels-gtfs validate`: entities against the published datamodels.jp schemas (the `validate` extra).
|
|
25
|
+
- Properties whose schema format is date or date-time are typed (`Date`, `DateTime`) in normalized form (#13).
|
|
26
|
+
- The GTFS Realtime proto from google/transit (Apache-2.0) is vendored with a descriptor built from it, so no code generation is needed; `protobuf` 4.21 or later is the one dependency.
|
|
27
|
+
|
|
28
|
+
[Unreleased]: https://github.com/geolonia/datamodels-gtfs/compare/v0.1.0...HEAD
|
|
29
|
+
[0.1.0]: https://github.com/geolonia/datamodels-gtfs/releases/tag/v0.1.0
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Geolonia Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: datamodels-gtfs
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Convert GTFS-JP feeds and GTFS Realtime to datamodels.jp transit entities (NGSI-LD), and check GTFS-JP Part 2 rules
|
|
5
|
+
Project-URL: Homepage, https://github.com/geolonia/datamodels-gtfs
|
|
6
|
+
Project-URL: Issues, https://github.com/geolonia/datamodels-gtfs/issues
|
|
7
|
+
Author: Geolonia
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
License-File: src/datamodels_gtfs/realtime/LICENSE-gtfs-realtime.txt
|
|
11
|
+
Keywords: GTFS,GTFS Realtime,GTFS-JP,NGSI-LD,datamodels.jp,transit
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Environment :: Console
|
|
14
|
+
Classifier: Natural Language :: English
|
|
15
|
+
Classifier: Natural Language :: Japanese
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Topic :: Scientific/Engineering :: GIS
|
|
18
|
+
Requires-Python: >=3.10
|
|
19
|
+
Requires-Dist: protobuf>=4.21
|
|
20
|
+
Provides-Extra: validate
|
|
21
|
+
Requires-Dist: jsonschema[format-nongpl]>=4.18; extra == 'validate'
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
|
|
24
|
+
# datamodels-gtfs
|
|
25
|
+
|
|
26
|
+
Convert GTFS-JP feeds into the entities of the [datamodels.jp](https://datamodels.jp) `transit`
|
|
27
|
+
subject (NGSI-LD, key-values or normalized), and GTFS Realtime feeds into TripUpdate,
|
|
28
|
+
VehiclePosition and ServiceAlert entities. `check` tests saved GTFS Realtime snapshots against the
|
|
29
|
+
GTFS-JP v4.0 Part 2 rules that a JSON Schema cannot check.
|
|
30
|
+
|
|
31
|
+
GTFS-JP のフィードを [datamodels.jp](https://datamodels.jp) の `transit` 分野のエンティティ
|
|
32
|
+
(NGSI-LD、キー・バリュー形式と正規化形式)に、GTFS Realtime のフィードを TripUpdate、
|
|
33
|
+
VehiclePosition、ServiceAlert のエンティティに変換するツールです。`check` は、保存した GTFS Realtime の
|
|
34
|
+
スナップショットを、JSON Schema では確かめられない GTFS-JP 第4.0版 第2部の規則で検査します。
|
|
35
|
+
|
|
36
|
+
> **Status: 0.1.0, the first release.** It converts every GTFS-JP static type and every GTFS Realtime
|
|
37
|
+
> type of the catalog's `transit` subject. Before 1.0.0, a minor version may change the command line
|
|
38
|
+
> and the entities written; see [CHANGELOG.md](https://github.com/geolonia/datamodels-gtfs/blob/main/CHANGELOG.md).
|
|
39
|
+
>
|
|
40
|
+
> **最初のリリース(0.1.0)です。** カタログの `transit` 分野にある GTFS-JP の静的フィードと GTFS Realtime の
|
|
41
|
+
> 型をすべて変換します。1.0.0 より前は、マイナーバージョンでコマンドラインや出力するエンティティが変わることが
|
|
42
|
+
> あります。[CHANGELOG.md](https://github.com/geolonia/datamodels-gtfs/blob/main/CHANGELOG.md) を見てください。
|
|
43
|
+
|
|
44
|
+
## Install / インストール
|
|
45
|
+
|
|
46
|
+
Python 3.10 or later. The one dependency is `protobuf`, for GTFS Realtime; the static conversion does
|
|
47
|
+
not load it. Validation needs `jsonschema` (the `validate` extra).
|
|
48
|
+
|
|
49
|
+
Python 3.10 以降。依存するパッケージは GTFS Realtime 用の `protobuf` だけで、静的なフィードの変換では
|
|
50
|
+
読み込みません。検証には `jsonschema`(`validate` の追加機能)を使います。
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
pip install "datamodels-gtfs[validate]"
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
As a command only, in its own environment / コマンドとしてだけ、専用の環境に入れるとき:
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
uv tool install "datamodels-gtfs[validate]"
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Use / 使い方
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
datamodels-gtfs static ToeiBus-GTFS.zip --feed-key 8000020130001-toeibus -o entities.jsonl
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
datamodels-gtfs realtime trip_update.pb --static Toei-Train-GTFS.zip --feed-key 8000020130001-toeitrain -o trips.jsonl
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
datamodels-gtfs validate entities.jsonl
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
- `static FEED` reads a GTFS zip file or folder and writes one entity per line (JSON Lines).
|
|
77
|
+
`--normalized` writes the normalized form, with dates and date-times typed as the catalog's
|
|
78
|
+
examples (`{"@type": "Date", "@value": "2026-04-01"}`); `--type Agency` limits the types.
|
|
79
|
+
- `--feed-key` goes into every id: `urn:ngsi-ld:<Type>:<feedKey>:<GTFS id>`. Use the publisher's
|
|
80
|
+
13-digit corporate number (法人番号), a hyphen and a feed name
|
|
81
|
+
([geolonia/datamodels#358](https://github.com/geolonia/datamodels/issues/358)).
|
|
82
|
+
- Names are LanguageProperty values: the field's text in the feed language, plus its readings
|
|
83
|
+
(`ja-Hrkt`) and translations from `translations.txt`. Dates become `YYYY-MM-DD` and times `HH:MM:SS` (still times of the service day, so
|
|
84
|
+
`25:30:00` stays as it is); a reference
|
|
85
|
+
to a row that does not exist is reported, and the Relationship is still written.
|
|
86
|
+
- Where GTFS-JP requires a value that the international GTFS reference lets you leave empty (an
|
|
87
|
+
empty `location_type`, one route colour without the other, an empty `routes.agency_id` in a feed
|
|
88
|
+
with one agency), the international default is filled in with a `default-filled` warning.
|
|
89
|
+
`--strict` checks at the GTFS-JP level instead: nothing is filled, and each one is a
|
|
90
|
+
`required-missing` error.
|
|
91
|
+
- Rules that span the rows of a trip are checked too: times at the first and last stop, and times
|
|
92
|
+
and `shape_dist_traveled` along the trip. `stop_times.txt` is read row by row, so memory stays
|
|
93
|
+
small (the 1.1 million stop times of the Toei bus feed take about 20 seconds and 90 MB). If the
|
|
94
|
+
rows of a trip are not together in the file, the checks along a trip only see each run of rows,
|
|
95
|
+
and one warning says so.
|
|
96
|
+
- Each `shape_id` of `shapes.txt` becomes one Shape: its points, in `shape_pt_sequence` order, make a
|
|
97
|
+
LineString, and their `shape_dist_traveled` values the array `shapePtDistTraveled`, written only
|
|
98
|
+
when every point has one and they increase. The points are kept in memory until the file is read
|
|
99
|
+
(the 748 shapes of the Toei bus feed take under a second).
|
|
100
|
+
- `transfers.txt` has no id column, so a Transfer's id ends in a hash of its six key columns, as
|
|
101
|
+
the catalog says; the id stays the same when rows are reordered. Besides the stops, trips and
|
|
102
|
+
minimum time that each `transfer_type` needs, the tool checks that a trip belongs to the route
|
|
103
|
+
on the same side and that types 4 and 5 name platforms, not stations.
|
|
104
|
+
- Fares (Fares V1): `price` is whole yen (`210.00` is read as 210); an empty `transfers` means
|
|
105
|
+
unlimited transfers and is left out. A FareRule's id ends in a hash of its five columns, like a
|
|
106
|
+
Transfer's; its zones are checked against the `zone_id` values of `stops.txt`. A missing
|
|
107
|
+
`fare_attributes.txt` is a warning: GTFS-JP requires it unless the fares are too complex for it.
|
|
108
|
+
- An Attribution without `attribution_id` gets an id from a hash of its other columns, as the
|
|
109
|
+
catalog says. At least one of the three roles must be 1, and at most one of agency, route and
|
|
110
|
+
trip may be given (the others are reported and left out).
|
|
111
|
+
- Problems go to standard error with file, line and column, in English or Japanese (`--lang`, or
|
|
112
|
+
from `LANG`); `--problems-json` also writes them as JSON. Exit codes: 0 when there are no errors
|
|
113
|
+
(warnings only), 1 when the feed has errors (the entities are still written), 2 when the tool
|
|
114
|
+
cannot run (no such feed, a bad `--feed-key`, a file that cannot be read); then nothing is written.
|
|
115
|
+
- `realtime FEED.pb` reads one GTFS Realtime feed (a fetch saved to a file) and writes a TripUpdate
|
|
116
|
+
per run of a trip (`urn:ngsi-ld:TripUpdate:<feedKey>:<trip_id>:<service day>`, and `:<start time>`
|
|
117
|
+
for a trip in frequencies.txt), a VehiclePosition per vehicle
|
|
118
|
+
(`urn:ngsi-ld:VehiclePosition:<feedKey>:<vehicle.id>`; without `vehicle.id`, the TripUpdate key
|
|
119
|
+
`<trip_id>:<service day>`, with the start time for a trip in frequencies.txt) and a ServiceAlert
|
|
120
|
+
per alert (`urn:ngsi-ld:ServiceAlert:<feedKey>:<FeedEntity.id>`), following the catalog and the
|
|
121
|
+
decisions of geolonia/datamodels#375: times as ISO 8601 with `+09:00`, enumerations by name, and in
|
|
122
|
+
`--normalized` form `observedAt` on the measured values; alert texts are values per language.
|
|
123
|
+
`--static` names the GTFS-JP feed it belongs to: trips, routes and stops are checked against it,
|
|
124
|
+
the service day of a trip (or vehicle) without `start_date` comes from its calendar and timetable,
|
|
125
|
+
and when a stop gives only `time` or only `delay` (GTFS-JP requires both), the other is worked out
|
|
126
|
+
from the scheduled time in stop_times.txt (`scheduled_time` for NEW and REPLACEMENT trips), with a
|
|
127
|
+
warning. Where there is no scheduled time for that stop, nothing is worked out and the missing
|
|
128
|
+
value is an error.
|
|
129
|
+
A run is told apart by its start time only for a trip in frequencies.txt, which needs `--static`:
|
|
130
|
+
without it, a vehicle or trip update with a `start_time` but no `vehicle.id` (for a VehiclePosition)
|
|
131
|
+
is reported and skipped. Problems name the feed entity and the field.
|
|
132
|
+
- `check FEED.pb…` reads saved snapshots of a GTFS Realtime feed and writes only problems, with the
|
|
133
|
+
exit codes of `realtime`. Each snapshot gets the problems of `realtime` (with `--static`, such as
|
|
134
|
+
trips missing from the static feed) and these GTFS-JP rules: `uncertainty` is 0 at a stop whose
|
|
135
|
+
time is before the feed time (`uncertain-passed`); where a stop event gives both, `time` is the
|
|
136
|
+
scheduled time + `delay` (`inconsistent-delay`; the scheduled time comes from `--static`, or from
|
|
137
|
+
`scheduled_time` for NEW and REPLACEMENT trips); `header.timestamp` is no older than 10 minutes
|
|
138
|
+
when fetched, as GTFS-JP renews it even without changes (`stale`; a feed made more than 30 s after
|
|
139
|
+
it was fetched means a clock is wrong, a warning). The 30 s refresh of the content cannot be seen
|
|
140
|
+
in a snapshot. An alert whose every active period ended more than a week before the feed time is
|
|
141
|
+
reported (`alert-old`; one still going on, or without an end, is never old). Over consecutive
|
|
142
|
+
snapshots of the trip update feed (in time order; empty snapshots, and those with only vehicles or
|
|
143
|
+
alerts, are left out of this), a trip that leaves the feed before 1 minute after its arrival at the last stop is
|
|
144
|
+
reported (`trip-dropped`, with `--static`): the arrival is the update's own time at the last stop,
|
|
145
|
+
or the timetable's plus the last delay. Snapshots 5 minutes apart only show trips that left well
|
|
146
|
+
before that minute. The rules look at the values the feed sends, not at values worked out from them.
|
|
147
|
+
The fetch time is the file's modification time, or `--fetched-at` for a single snapshot. A
|
|
148
|
+
snapshot that cannot be read stops the run with exit code 2.
|
|
149
|
+
- `validate` checks each entity against `https://datamodels.jp/schema/transit/<Type>/v1.json`:
|
|
150
|
+
exit 1 when an entity does not match, 2 when the input or a schema cannot be read.
|
|
151
|
+
|
|
152
|
+
日本語:
|
|
153
|
+
|
|
154
|
+
- `static FEED` は GTFS の zip ファイルかフォルダを読み、1 行に 1 エンティティ(JSON Lines)を書きます。
|
|
155
|
+
`--normalized` で正規化形式にし、日付と日時はカタログの例のとおり型付きで書きます
|
|
156
|
+
(`{"@type": "Date", "@value": "2026-04-01"}`)。`--type Agency` で型を絞ります。
|
|
157
|
+
- `--feed-key` はすべての id に入ります(`urn:ngsi-ld:<型>:<feedKey>:<GTFS の ID>`)。提供する組織の
|
|
158
|
+
法人番号(13 桁)、ハイフン、フィードの名前を勧めます。
|
|
159
|
+
- 名前は LanguageProperty です。フィードの言語の値に、`translations.txt` の読み(`ja-Hrkt`)と
|
|
160
|
+
翻訳を加えます。日付は `YYYY-MM-DD`、時刻は `HH:MM:SS` にします(運行日の時刻のままなので、`25:30:00` もそのままです)。無い行への参照は報告し、Relationship はそのまま書きます。
|
|
161
|
+
- GTFS-JP では必須で、国際仕様では空にできる値(空の `location_type`、片方だけの路線の色、事業者が
|
|
162
|
+
1 つのフィードでの空の `routes.agency_id`)は、国際仕様の既定値を補い、`default-filled` の警告を
|
|
163
|
+
出します。`--strict` を付けると GTFS-JP の水準で検査し、値を補わずに `required-missing` のエラーにします。
|
|
164
|
+
- 便の行にまたがる規則も確かめます。始発と終着の時刻、便に沿った時刻と `shape_dist_traveled` です。
|
|
165
|
+
`stop_times.txt` は 1 行ずつ読むので、メモリはあまり使いません(都営バスの 110 万件の停車時刻で
|
|
166
|
+
約 20 秒、90 MB)。便の行がファイルの中でまとまっていないときは、便に沿った検査は続いた行の中だけで行い、
|
|
167
|
+
そのことを 1 回だけ警告します。
|
|
168
|
+
- `shapes.txt` は `shape_id` ごとに 1 つの Shape にします。点を `shape_pt_sequence` の順に並べて
|
|
169
|
+
LineString にし、`shape_dist_traveled` の値を配列 `shapePtDistTraveled` にします。配列は、すべての点に
|
|
170
|
+
値があり、増えていくときだけ書きます。点はファイルを読み終えるまでメモリに置きます(都営バスの 748 の形状で
|
|
171
|
+
1 秒かかりません)。
|
|
172
|
+
- `transfers.txt` には id の列が無いので、Transfer の id の末尾は、カタログのとおりキーの 6 列から作るハッシュです。
|
|
173
|
+
行を並べ替えても id は変わりません。`transfer_type` ごとに必要な停留所、便、最小乗継時間のほか、同じ側の便が
|
|
174
|
+
その路線に属すること、4 と 5 が駅ではなく乗り場を指すことも確かめます。
|
|
175
|
+
- 運賃(Fares V1):`price` は円単位の整数です(`210.00` は 210 と読みます)。空の `transfers` は乗り換えが
|
|
176
|
+
何回でもできることで、属性を省きます。FareRule の id の末尾は、Transfer と同じく 5 列から作るハッシュです。
|
|
177
|
+
ゾーンは `stops.txt` の `zone_id` と照らし合わせます。`fare_attributes.txt` が無いときは警告です。運賃が
|
|
178
|
+
複雑で表せない場合を除き、GTFS-JP では必須です。
|
|
179
|
+
- `attribution_id` の無い Attribution の id は、カタログのとおりほかの列から作るハッシュです。3 つの役割の
|
|
180
|
+
少なくとも 1 つは 1 で、事業者、路線、便は 1 つまでです(ほかは報告して書きません)。
|
|
181
|
+
- 問題は標準エラーに、ファイル、行、列とともに英語か日本語で出ます(`--lang`、または `LANG`
|
|
182
|
+
から)。`--problems-json` で JSON にも書きます。終了コードは、エラーが無ければ(警告だけなら)0、
|
|
183
|
+
フィードにエラーがあれば 1(エンティティは書きます)、ツールが動けないとき(フィードが無い、
|
|
184
|
+
`--feed-key` が正しくない、読めないファイルがある)は 2 で、このときは何も書きません。
|
|
185
|
+
- `realtime FEED.pb` は GTFS Realtime のフィード(取得してファイルに保存したもの)を読み、便の運行ごとに
|
|
186
|
+
TripUpdate(`urn:ngsi-ld:TripUpdate:<feedKey>:<trip_id>:<運行日>`、frequencies.txt の便は
|
|
187
|
+
`:<始発時刻>` を続けます)を、車両ごとに VehiclePosition(`urn:ngsi-ld:VehiclePosition:<feedKey>:<vehicle.id>`。
|
|
188
|
+
`vehicle.id` が無いときは TripUpdate と同じ `<trip_id>:<運行日>` で、frequencies.txt の便は始発時刻を続けます)
|
|
189
|
+
を、お知らせごとに ServiceAlert(`urn:ngsi-ld:ServiceAlert:<feedKey>:<FeedEntity.id>`)を書きます。
|
|
190
|
+
カタログと geolonia/datamodels#375 の決定に従い、時刻は `+09:00` 付きの ISO 8601、列挙値は名前で書き、
|
|
191
|
+
`--normalized` では測った値に `observedAt` を付けます。お知らせの文は言語ごとの値にします。`--static` で
|
|
192
|
+
対応する GTFS-JP フィードを指定すると、便、路線、停留所を照らし合わせ、`start_date` の無い便(や車両)の
|
|
193
|
+
運行日をカレンダーと時刻表から決め、停留所に `time` か `delay` の片方しか無いとき(GTFS-JP では両方必須)は、
|
|
194
|
+
stop_times.txt の予定時刻(NEW と REPLACEMENT の便では `scheduled_time`)からもう片方を求めて警告を出します。
|
|
195
|
+
その停留所の予定時刻が無いときは求めず、足りない値をエラーにします。始発時刻で運行を分けるのは
|
|
196
|
+
frequencies.txt の便だけで、それには `--static` が必要なため、
|
|
197
|
+
`--static` が無いときに `start_time` のある運行(VehiclePosition では `vehicle.id` の無い車両)は、
|
|
198
|
+
報告して使いません。問題はフィードのエンティティと項目で示します。
|
|
199
|
+
- `check FEED.pb…` は、保存した GTFS Realtime フィードのスナップショットを読み、問題だけを書きます。終了コードは
|
|
200
|
+
`realtime` と同じです。各スナップショットに、`realtime` の問題(`--static` があれば、静的フィードに無い便など)と、
|
|
201
|
+
次の GTFS-JP の規則を当てはめます。時刻がフィードの時刻より前の停留所では `uncertainty` が 0
|
|
202
|
+
(`uncertain-passed`)。停車イベントに両方あるときは `time` = 予定時刻 + `delay`(`inconsistent-delay`。
|
|
203
|
+
予定時刻は `--static` から、NEW と REPLACEMENT の便では `scheduled_time` から取ります)。取得したとき、
|
|
204
|
+
`header.timestamp` が 10 分より古くない(`stale`。GTFS-JP では変化が無くても更新します。取得より 30 秒以上
|
|
205
|
+
あとに作られたフィードは時計のずれで、警告です)。内容を 30 秒ごとに更新する規則は、スナップショットでは
|
|
206
|
+
確かめられません。すべての有効期間がフィードの時刻の 1 週間より前に終わったお知らせを報告します
|
|
207
|
+
(`alert-old`。続いているお知らせや、終わりの無いお知らせは古くなりません)。便の更新のフィードの続いた
|
|
208
|
+
スナップショット(時刻順。空のスナップショットと、車両やお知らせだけのスナップショットは除きます)で、終点に着いて 1 分たつ前に
|
|
209
|
+
フィードから消えた便を報告します(`trip-dropped`、`--static` が必要)。着く時刻は、更新にある終点の時刻か、
|
|
210
|
+
時刻表の時刻に最後の遅れを足したものです。5 分おきのスナップショットでは、その 1 分よりかなり前に消えた便
|
|
211
|
+
だけが分かります。
|
|
212
|
+
規則はフィードが送った値で確かめ、そこから求めた値は使いません。取得した時刻はファイルの更新日時で、
|
|
213
|
+
スナップショットが 1 つなら `--fetched-at` でも指定できます。読めないスナップショットがあると、終了コード 2 で
|
|
214
|
+
止まります。
|
|
215
|
+
- `validate` は、各エンティティを `https://datamodels.jp/schema/transit/<型>/v1.json` で検証します。
|
|
216
|
+
合わないエンティティがあれば 1、入力やスキーマを読めなければ 2 で終わります。
|
|
217
|
+
|
|
218
|
+
## Develop / 開発
|
|
219
|
+
|
|
220
|
+
```bash
|
|
221
|
+
uv sync
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
```bash
|
|
225
|
+
uv run pytest
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
```bash
|
|
229
|
+
uv run ruff check .
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
`tests/schemas/` holds copies of the published schemas, and of the catalog schemas they refer to,
|
|
233
|
+
so the tests run offline;
|
|
234
|
+
`uv run python scripts/update_schemas.py` refreshes them, and CI checks that they are current.
|
|
235
|
+
The test fixtures are extracts of Toei's real feeds; see [tests/fixtures/README.md](https://github.com/geolonia/datamodels-gtfs/blob/main/tests/fixtures/README.md)
|
|
236
|
+
for the source and licence.
|
|
237
|
+
|
|
238
|
+
### Release / リリース
|
|
239
|
+
|
|
240
|
+
Once, before the first release: on pypi.org, add a pending trusted publisher for the project
|
|
241
|
+
`datamodels-gtfs` with owner `geolonia`, repository `datamodels-gtfs`, workflow `publish.yml` and
|
|
242
|
+
environment `pypi`; in this repository's settings, create the environment `pypi`, limited to `v*` tags.
|
|
243
|
+
Without the publisher, PyPI refuses the upload: the GitHub release stays published, and the workflow
|
|
244
|
+
has to be run again once it is set up.
|
|
245
|
+
|
|
246
|
+
1. In a PR: set `__version__` in `src/datamodels_gtfs/__init__.py` and move the entries under
|
|
247
|
+
Unreleased in [CHANGELOG.md](https://github.com/geolonia/datamodels-gtfs/blob/main/CHANGELOG.md) to a section for the version and the release date.
|
|
248
|
+
2. After it is merged, publish a GitHub release whose tag is `v` + the version, such as `v0.1.0`, on
|
|
249
|
+
the merged commit. [publish.yml](https://github.com/geolonia/datamodels-gtfs/blob/main/.github/workflows/publish.yml) then checks the tag, runs the tests,
|
|
250
|
+
builds the wheel and the sdist, and publishes them on PyPI by trusted publishing (no token is stored
|
|
251
|
+
here). A pre-release publishes nothing.
|
|
252
|
+
|
|
253
|
+
最初のリリースの前に一度だけ: pypi.org で、プロジェクト `datamodels-gtfs` に pending trusted publisher
|
|
254
|
+
(owner `geolonia`、リポジトリ `datamodels-gtfs`、ワークフロー `publish.yml`、environment `pypi`)を
|
|
255
|
+
登録します。このリポジトリの設定では、`v*` タグだけが使える environment `pypi` を作ります。publisher が
|
|
256
|
+
無いと PyPI はアップロードを拒否します。GitHub のリリースは公開されたまま残るので、設定したあとで
|
|
257
|
+
ワークフローを再実行します。
|
|
258
|
+
|
|
259
|
+
1. PR で `src/datamodels_gtfs/__init__.py` の `__version__` を変え、[CHANGELOG.md](https://github.com/geolonia/datamodels-gtfs/blob/main/CHANGELOG.md) の
|
|
260
|
+
Unreleased の項目を、そのバージョンとリリース日の節に移します。
|
|
261
|
+
2. マージ後、そのコミットに `v` + バージョン(例: `v0.1.0`)のタグで GitHub のリリースを公開します。
|
|
262
|
+
[publish.yml](https://github.com/geolonia/datamodels-gtfs/blob/main/.github/workflows/publish.yml) がタグを確かめ、テストを実行し、wheel と sdist を作り、
|
|
263
|
+
trusted publishing で PyPI に公開します(トークンはこのリポジトリに置きません)。プレリリースでは
|
|
264
|
+
何も公開しません。
|
|
265
|
+
|
|
266
|
+
## Related / 関連
|
|
267
|
+
|
|
268
|
+
- [geolonia/datamodels](https://github.com/geolonia/datamodels): the catalog, whose `models/transit/`
|
|
269
|
+
schemas, mappings and notes this tool follows.
|
|
270
|
+
- [gtfs-jp-kit](https://github.com/Jasonin2099/gtfs-jp-kit): GTFS-JP profile checks; general GTFS-JP
|
|
271
|
+
rules found here are offered there.
|
|
272
|
+
|
|
273
|
+
## License / ライセンス
|
|
274
|
+
|
|
275
|
+
[MIT](https://github.com/geolonia/datamodels-gtfs/blob/main/LICENSE). `src/datamodels_gtfs/realtime/gtfs-realtime.proto` (and the descriptor built from it) is
|
|
276
|
+
from [google/transit](https://github.com/google/transit), Apache-2.0
|
|
277
|
+
([LICENSE-gtfs-realtime.txt](https://github.com/geolonia/datamodels-gtfs/blob/main/src/datamodels_gtfs/realtime/LICENSE-gtfs-realtime.txt)).
|
|
278
|
+
Test fixtures: see [tests/fixtures/README.md](https://github.com/geolonia/datamodels-gtfs/blob/main/tests/fixtures/README.md).
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
# datamodels-gtfs
|
|
2
|
+
|
|
3
|
+
Convert GTFS-JP feeds into the entities of the [datamodels.jp](https://datamodels.jp) `transit`
|
|
4
|
+
subject (NGSI-LD, key-values or normalized), and GTFS Realtime feeds into TripUpdate,
|
|
5
|
+
VehiclePosition and ServiceAlert entities. `check` tests saved GTFS Realtime snapshots against the
|
|
6
|
+
GTFS-JP v4.0 Part 2 rules that a JSON Schema cannot check.
|
|
7
|
+
|
|
8
|
+
GTFS-JP のフィードを [datamodels.jp](https://datamodels.jp) の `transit` 分野のエンティティ
|
|
9
|
+
(NGSI-LD、キー・バリュー形式と正規化形式)に、GTFS Realtime のフィードを TripUpdate、
|
|
10
|
+
VehiclePosition、ServiceAlert のエンティティに変換するツールです。`check` は、保存した GTFS Realtime の
|
|
11
|
+
スナップショットを、JSON Schema では確かめられない GTFS-JP 第4.0版 第2部の規則で検査します。
|
|
12
|
+
|
|
13
|
+
> **Status: 0.1.0, the first release.** It converts every GTFS-JP static type and every GTFS Realtime
|
|
14
|
+
> type of the catalog's `transit` subject. Before 1.0.0, a minor version may change the command line
|
|
15
|
+
> and the entities written; see [CHANGELOG.md](https://github.com/geolonia/datamodels-gtfs/blob/main/CHANGELOG.md).
|
|
16
|
+
>
|
|
17
|
+
> **最初のリリース(0.1.0)です。** カタログの `transit` 分野にある GTFS-JP の静的フィードと GTFS Realtime の
|
|
18
|
+
> 型をすべて変換します。1.0.0 より前は、マイナーバージョンでコマンドラインや出力するエンティティが変わることが
|
|
19
|
+
> あります。[CHANGELOG.md](https://github.com/geolonia/datamodels-gtfs/blob/main/CHANGELOG.md) を見てください。
|
|
20
|
+
|
|
21
|
+
## Install / インストール
|
|
22
|
+
|
|
23
|
+
Python 3.10 or later. The one dependency is `protobuf`, for GTFS Realtime; the static conversion does
|
|
24
|
+
not load it. Validation needs `jsonschema` (the `validate` extra).
|
|
25
|
+
|
|
26
|
+
Python 3.10 以降。依存するパッケージは GTFS Realtime 用の `protobuf` だけで、静的なフィードの変換では
|
|
27
|
+
読み込みません。検証には `jsonschema`(`validate` の追加機能)を使います。
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
pip install "datamodels-gtfs[validate]"
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
As a command only, in its own environment / コマンドとしてだけ、専用の環境に入れるとき:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
uv tool install "datamodels-gtfs[validate]"
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Use / 使い方
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
datamodels-gtfs static ToeiBus-GTFS.zip --feed-key 8000020130001-toeibus -o entities.jsonl
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
datamodels-gtfs realtime trip_update.pb --static Toei-Train-GTFS.zip --feed-key 8000020130001-toeitrain -o trips.jsonl
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
datamodels-gtfs validate entities.jsonl
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
- `static FEED` reads a GTFS zip file or folder and writes one entity per line (JSON Lines).
|
|
54
|
+
`--normalized` writes the normalized form, with dates and date-times typed as the catalog's
|
|
55
|
+
examples (`{"@type": "Date", "@value": "2026-04-01"}`); `--type Agency` limits the types.
|
|
56
|
+
- `--feed-key` goes into every id: `urn:ngsi-ld:<Type>:<feedKey>:<GTFS id>`. Use the publisher's
|
|
57
|
+
13-digit corporate number (法人番号), a hyphen and a feed name
|
|
58
|
+
([geolonia/datamodels#358](https://github.com/geolonia/datamodels/issues/358)).
|
|
59
|
+
- Names are LanguageProperty values: the field's text in the feed language, plus its readings
|
|
60
|
+
(`ja-Hrkt`) and translations from `translations.txt`. Dates become `YYYY-MM-DD` and times `HH:MM:SS` (still times of the service day, so
|
|
61
|
+
`25:30:00` stays as it is); a reference
|
|
62
|
+
to a row that does not exist is reported, and the Relationship is still written.
|
|
63
|
+
- Where GTFS-JP requires a value that the international GTFS reference lets you leave empty (an
|
|
64
|
+
empty `location_type`, one route colour without the other, an empty `routes.agency_id` in a feed
|
|
65
|
+
with one agency), the international default is filled in with a `default-filled` warning.
|
|
66
|
+
`--strict` checks at the GTFS-JP level instead: nothing is filled, and each one is a
|
|
67
|
+
`required-missing` error.
|
|
68
|
+
- Rules that span the rows of a trip are checked too: times at the first and last stop, and times
|
|
69
|
+
and `shape_dist_traveled` along the trip. `stop_times.txt` is read row by row, so memory stays
|
|
70
|
+
small (the 1.1 million stop times of the Toei bus feed take about 20 seconds and 90 MB). If the
|
|
71
|
+
rows of a trip are not together in the file, the checks along a trip only see each run of rows,
|
|
72
|
+
and one warning says so.
|
|
73
|
+
- Each `shape_id` of `shapes.txt` becomes one Shape: its points, in `shape_pt_sequence` order, make a
|
|
74
|
+
LineString, and their `shape_dist_traveled` values the array `shapePtDistTraveled`, written only
|
|
75
|
+
when every point has one and they increase. The points are kept in memory until the file is read
|
|
76
|
+
(the 748 shapes of the Toei bus feed take under a second).
|
|
77
|
+
- `transfers.txt` has no id column, so a Transfer's id ends in a hash of its six key columns, as
|
|
78
|
+
the catalog says; the id stays the same when rows are reordered. Besides the stops, trips and
|
|
79
|
+
minimum time that each `transfer_type` needs, the tool checks that a trip belongs to the route
|
|
80
|
+
on the same side and that types 4 and 5 name platforms, not stations.
|
|
81
|
+
- Fares (Fares V1): `price` is whole yen (`210.00` is read as 210); an empty `transfers` means
|
|
82
|
+
unlimited transfers and is left out. A FareRule's id ends in a hash of its five columns, like a
|
|
83
|
+
Transfer's; its zones are checked against the `zone_id` values of `stops.txt`. A missing
|
|
84
|
+
`fare_attributes.txt` is a warning: GTFS-JP requires it unless the fares are too complex for it.
|
|
85
|
+
- An Attribution without `attribution_id` gets an id from a hash of its other columns, as the
|
|
86
|
+
catalog says. At least one of the three roles must be 1, and at most one of agency, route and
|
|
87
|
+
trip may be given (the others are reported and left out).
|
|
88
|
+
- Problems go to standard error with file, line and column, in English or Japanese (`--lang`, or
|
|
89
|
+
from `LANG`); `--problems-json` also writes them as JSON. Exit codes: 0 when there are no errors
|
|
90
|
+
(warnings only), 1 when the feed has errors (the entities are still written), 2 when the tool
|
|
91
|
+
cannot run (no such feed, a bad `--feed-key`, a file that cannot be read); then nothing is written.
|
|
92
|
+
- `realtime FEED.pb` reads one GTFS Realtime feed (a fetch saved to a file) and writes a TripUpdate
|
|
93
|
+
per run of a trip (`urn:ngsi-ld:TripUpdate:<feedKey>:<trip_id>:<service day>`, and `:<start time>`
|
|
94
|
+
for a trip in frequencies.txt), a VehiclePosition per vehicle
|
|
95
|
+
(`urn:ngsi-ld:VehiclePosition:<feedKey>:<vehicle.id>`; without `vehicle.id`, the TripUpdate key
|
|
96
|
+
`<trip_id>:<service day>`, with the start time for a trip in frequencies.txt) and a ServiceAlert
|
|
97
|
+
per alert (`urn:ngsi-ld:ServiceAlert:<feedKey>:<FeedEntity.id>`), following the catalog and the
|
|
98
|
+
decisions of geolonia/datamodels#375: times as ISO 8601 with `+09:00`, enumerations by name, and in
|
|
99
|
+
`--normalized` form `observedAt` on the measured values; alert texts are values per language.
|
|
100
|
+
`--static` names the GTFS-JP feed it belongs to: trips, routes and stops are checked against it,
|
|
101
|
+
the service day of a trip (or vehicle) without `start_date` comes from its calendar and timetable,
|
|
102
|
+
and when a stop gives only `time` or only `delay` (GTFS-JP requires both), the other is worked out
|
|
103
|
+
from the scheduled time in stop_times.txt (`scheduled_time` for NEW and REPLACEMENT trips), with a
|
|
104
|
+
warning. Where there is no scheduled time for that stop, nothing is worked out and the missing
|
|
105
|
+
value is an error.
|
|
106
|
+
A run is told apart by its start time only for a trip in frequencies.txt, which needs `--static`:
|
|
107
|
+
without it, a vehicle or trip update with a `start_time` but no `vehicle.id` (for a VehiclePosition)
|
|
108
|
+
is reported and skipped. Problems name the feed entity and the field.
|
|
109
|
+
- `check FEED.pb…` reads saved snapshots of a GTFS Realtime feed and writes only problems, with the
|
|
110
|
+
exit codes of `realtime`. Each snapshot gets the problems of `realtime` (with `--static`, such as
|
|
111
|
+
trips missing from the static feed) and these GTFS-JP rules: `uncertainty` is 0 at a stop whose
|
|
112
|
+
time is before the feed time (`uncertain-passed`); where a stop event gives both, `time` is the
|
|
113
|
+
scheduled time + `delay` (`inconsistent-delay`; the scheduled time comes from `--static`, or from
|
|
114
|
+
`scheduled_time` for NEW and REPLACEMENT trips); `header.timestamp` is no older than 10 minutes
|
|
115
|
+
when fetched, as GTFS-JP renews it even without changes (`stale`; a feed made more than 30 s after
|
|
116
|
+
it was fetched means a clock is wrong, a warning). The 30 s refresh of the content cannot be seen
|
|
117
|
+
in a snapshot. An alert whose every active period ended more than a week before the feed time is
|
|
118
|
+
reported (`alert-old`; one still going on, or without an end, is never old). Over consecutive
|
|
119
|
+
snapshots of the trip update feed (in time order; empty snapshots, and those with only vehicles or
|
|
120
|
+
alerts, are left out of this), a trip that leaves the feed before 1 minute after its arrival at the last stop is
|
|
121
|
+
reported (`trip-dropped`, with `--static`): the arrival is the update's own time at the last stop,
|
|
122
|
+
or the timetable's plus the last delay. Snapshots 5 minutes apart only show trips that left well
|
|
123
|
+
before that minute. The rules look at the values the feed sends, not at values worked out from them.
|
|
124
|
+
The fetch time is the file's modification time, or `--fetched-at` for a single snapshot. A
|
|
125
|
+
snapshot that cannot be read stops the run with exit code 2.
|
|
126
|
+
- `validate` checks each entity against `https://datamodels.jp/schema/transit/<Type>/v1.json`:
|
|
127
|
+
exit 1 when an entity does not match, 2 when the input or a schema cannot be read.
|
|
128
|
+
|
|
129
|
+
日本語:
|
|
130
|
+
|
|
131
|
+
- `static FEED` は GTFS の zip ファイルかフォルダを読み、1 行に 1 エンティティ(JSON Lines)を書きます。
|
|
132
|
+
`--normalized` で正規化形式にし、日付と日時はカタログの例のとおり型付きで書きます
|
|
133
|
+
(`{"@type": "Date", "@value": "2026-04-01"}`)。`--type Agency` で型を絞ります。
|
|
134
|
+
- `--feed-key` はすべての id に入ります(`urn:ngsi-ld:<型>:<feedKey>:<GTFS の ID>`)。提供する組織の
|
|
135
|
+
法人番号(13 桁)、ハイフン、フィードの名前を勧めます。
|
|
136
|
+
- 名前は LanguageProperty です。フィードの言語の値に、`translations.txt` の読み(`ja-Hrkt`)と
|
|
137
|
+
翻訳を加えます。日付は `YYYY-MM-DD`、時刻は `HH:MM:SS` にします(運行日の時刻のままなので、`25:30:00` もそのままです)。無い行への参照は報告し、Relationship はそのまま書きます。
|
|
138
|
+
- GTFS-JP では必須で、国際仕様では空にできる値(空の `location_type`、片方だけの路線の色、事業者が
|
|
139
|
+
1 つのフィードでの空の `routes.agency_id`)は、国際仕様の既定値を補い、`default-filled` の警告を
|
|
140
|
+
出します。`--strict` を付けると GTFS-JP の水準で検査し、値を補わずに `required-missing` のエラーにします。
|
|
141
|
+
- 便の行にまたがる規則も確かめます。始発と終着の時刻、便に沿った時刻と `shape_dist_traveled` です。
|
|
142
|
+
`stop_times.txt` は 1 行ずつ読むので、メモリはあまり使いません(都営バスの 110 万件の停車時刻で
|
|
143
|
+
約 20 秒、90 MB)。便の行がファイルの中でまとまっていないときは、便に沿った検査は続いた行の中だけで行い、
|
|
144
|
+
そのことを 1 回だけ警告します。
|
|
145
|
+
- `shapes.txt` は `shape_id` ごとに 1 つの Shape にします。点を `shape_pt_sequence` の順に並べて
|
|
146
|
+
LineString にし、`shape_dist_traveled` の値を配列 `shapePtDistTraveled` にします。配列は、すべての点に
|
|
147
|
+
値があり、増えていくときだけ書きます。点はファイルを読み終えるまでメモリに置きます(都営バスの 748 の形状で
|
|
148
|
+
1 秒かかりません)。
|
|
149
|
+
- `transfers.txt` には id の列が無いので、Transfer の id の末尾は、カタログのとおりキーの 6 列から作るハッシュです。
|
|
150
|
+
行を並べ替えても id は変わりません。`transfer_type` ごとに必要な停留所、便、最小乗継時間のほか、同じ側の便が
|
|
151
|
+
その路線に属すること、4 と 5 が駅ではなく乗り場を指すことも確かめます。
|
|
152
|
+
- 運賃(Fares V1):`price` は円単位の整数です(`210.00` は 210 と読みます)。空の `transfers` は乗り換えが
|
|
153
|
+
何回でもできることで、属性を省きます。FareRule の id の末尾は、Transfer と同じく 5 列から作るハッシュです。
|
|
154
|
+
ゾーンは `stops.txt` の `zone_id` と照らし合わせます。`fare_attributes.txt` が無いときは警告です。運賃が
|
|
155
|
+
複雑で表せない場合を除き、GTFS-JP では必須です。
|
|
156
|
+
- `attribution_id` の無い Attribution の id は、カタログのとおりほかの列から作るハッシュです。3 つの役割の
|
|
157
|
+
少なくとも 1 つは 1 で、事業者、路線、便は 1 つまでです(ほかは報告して書きません)。
|
|
158
|
+
- 問題は標準エラーに、ファイル、行、列とともに英語か日本語で出ます(`--lang`、または `LANG`
|
|
159
|
+
から)。`--problems-json` で JSON にも書きます。終了コードは、エラーが無ければ(警告だけなら)0、
|
|
160
|
+
フィードにエラーがあれば 1(エンティティは書きます)、ツールが動けないとき(フィードが無い、
|
|
161
|
+
`--feed-key` が正しくない、読めないファイルがある)は 2 で、このときは何も書きません。
|
|
162
|
+
- `realtime FEED.pb` は GTFS Realtime のフィード(取得してファイルに保存したもの)を読み、便の運行ごとに
|
|
163
|
+
TripUpdate(`urn:ngsi-ld:TripUpdate:<feedKey>:<trip_id>:<運行日>`、frequencies.txt の便は
|
|
164
|
+
`:<始発時刻>` を続けます)を、車両ごとに VehiclePosition(`urn:ngsi-ld:VehiclePosition:<feedKey>:<vehicle.id>`。
|
|
165
|
+
`vehicle.id` が無いときは TripUpdate と同じ `<trip_id>:<運行日>` で、frequencies.txt の便は始発時刻を続けます)
|
|
166
|
+
を、お知らせごとに ServiceAlert(`urn:ngsi-ld:ServiceAlert:<feedKey>:<FeedEntity.id>`)を書きます。
|
|
167
|
+
カタログと geolonia/datamodels#375 の決定に従い、時刻は `+09:00` 付きの ISO 8601、列挙値は名前で書き、
|
|
168
|
+
`--normalized` では測った値に `observedAt` を付けます。お知らせの文は言語ごとの値にします。`--static` で
|
|
169
|
+
対応する GTFS-JP フィードを指定すると、便、路線、停留所を照らし合わせ、`start_date` の無い便(や車両)の
|
|
170
|
+
運行日をカレンダーと時刻表から決め、停留所に `time` か `delay` の片方しか無いとき(GTFS-JP では両方必須)は、
|
|
171
|
+
stop_times.txt の予定時刻(NEW と REPLACEMENT の便では `scheduled_time`)からもう片方を求めて警告を出します。
|
|
172
|
+
その停留所の予定時刻が無いときは求めず、足りない値をエラーにします。始発時刻で運行を分けるのは
|
|
173
|
+
frequencies.txt の便だけで、それには `--static` が必要なため、
|
|
174
|
+
`--static` が無いときに `start_time` のある運行(VehiclePosition では `vehicle.id` の無い車両)は、
|
|
175
|
+
報告して使いません。問題はフィードのエンティティと項目で示します。
|
|
176
|
+
- `check FEED.pb…` は、保存した GTFS Realtime フィードのスナップショットを読み、問題だけを書きます。終了コードは
|
|
177
|
+
`realtime` と同じです。各スナップショットに、`realtime` の問題(`--static` があれば、静的フィードに無い便など)と、
|
|
178
|
+
次の GTFS-JP の規則を当てはめます。時刻がフィードの時刻より前の停留所では `uncertainty` が 0
|
|
179
|
+
(`uncertain-passed`)。停車イベントに両方あるときは `time` = 予定時刻 + `delay`(`inconsistent-delay`。
|
|
180
|
+
予定時刻は `--static` から、NEW と REPLACEMENT の便では `scheduled_time` から取ります)。取得したとき、
|
|
181
|
+
`header.timestamp` が 10 分より古くない(`stale`。GTFS-JP では変化が無くても更新します。取得より 30 秒以上
|
|
182
|
+
あとに作られたフィードは時計のずれで、警告です)。内容を 30 秒ごとに更新する規則は、スナップショットでは
|
|
183
|
+
確かめられません。すべての有効期間がフィードの時刻の 1 週間より前に終わったお知らせを報告します
|
|
184
|
+
(`alert-old`。続いているお知らせや、終わりの無いお知らせは古くなりません)。便の更新のフィードの続いた
|
|
185
|
+
スナップショット(時刻順。空のスナップショットと、車両やお知らせだけのスナップショットは除きます)で、終点に着いて 1 分たつ前に
|
|
186
|
+
フィードから消えた便を報告します(`trip-dropped`、`--static` が必要)。着く時刻は、更新にある終点の時刻か、
|
|
187
|
+
時刻表の時刻に最後の遅れを足したものです。5 分おきのスナップショットでは、その 1 分よりかなり前に消えた便
|
|
188
|
+
だけが分かります。
|
|
189
|
+
規則はフィードが送った値で確かめ、そこから求めた値は使いません。取得した時刻はファイルの更新日時で、
|
|
190
|
+
スナップショットが 1 つなら `--fetched-at` でも指定できます。読めないスナップショットがあると、終了コード 2 で
|
|
191
|
+
止まります。
|
|
192
|
+
- `validate` は、各エンティティを `https://datamodels.jp/schema/transit/<型>/v1.json` で検証します。
|
|
193
|
+
合わないエンティティがあれば 1、入力やスキーマを読めなければ 2 で終わります。
|
|
194
|
+
|
|
195
|
+
## Develop / 開発
|
|
196
|
+
|
|
197
|
+
```bash
|
|
198
|
+
uv sync
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
```bash
|
|
202
|
+
uv run pytest
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
```bash
|
|
206
|
+
uv run ruff check .
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
`tests/schemas/` holds copies of the published schemas, and of the catalog schemas they refer to,
|
|
210
|
+
so the tests run offline;
|
|
211
|
+
`uv run python scripts/update_schemas.py` refreshes them, and CI checks that they are current.
|
|
212
|
+
The test fixtures are extracts of Toei's real feeds; see [tests/fixtures/README.md](https://github.com/geolonia/datamodels-gtfs/blob/main/tests/fixtures/README.md)
|
|
213
|
+
for the source and licence.
|
|
214
|
+
|
|
215
|
+
### Release / リリース
|
|
216
|
+
|
|
217
|
+
Once, before the first release: on pypi.org, add a pending trusted publisher for the project
|
|
218
|
+
`datamodels-gtfs` with owner `geolonia`, repository `datamodels-gtfs`, workflow `publish.yml` and
|
|
219
|
+
environment `pypi`; in this repository's settings, create the environment `pypi`, limited to `v*` tags.
|
|
220
|
+
Without the publisher, PyPI refuses the upload: the GitHub release stays published, and the workflow
|
|
221
|
+
has to be run again once it is set up.
|
|
222
|
+
|
|
223
|
+
1. In a PR: set `__version__` in `src/datamodels_gtfs/__init__.py` and move the entries under
|
|
224
|
+
Unreleased in [CHANGELOG.md](https://github.com/geolonia/datamodels-gtfs/blob/main/CHANGELOG.md) to a section for the version and the release date.
|
|
225
|
+
2. After it is merged, publish a GitHub release whose tag is `v` + the version, such as `v0.1.0`, on
|
|
226
|
+
the merged commit. [publish.yml](https://github.com/geolonia/datamodels-gtfs/blob/main/.github/workflows/publish.yml) then checks the tag, runs the tests,
|
|
227
|
+
builds the wheel and the sdist, and publishes them on PyPI by trusted publishing (no token is stored
|
|
228
|
+
here). A pre-release publishes nothing.
|
|
229
|
+
|
|
230
|
+
最初のリリースの前に一度だけ: pypi.org で、プロジェクト `datamodels-gtfs` に pending trusted publisher
|
|
231
|
+
(owner `geolonia`、リポジトリ `datamodels-gtfs`、ワークフロー `publish.yml`、environment `pypi`)を
|
|
232
|
+
登録します。このリポジトリの設定では、`v*` タグだけが使える environment `pypi` を作ります。publisher が
|
|
233
|
+
無いと PyPI はアップロードを拒否します。GitHub のリリースは公開されたまま残るので、設定したあとで
|
|
234
|
+
ワークフローを再実行します。
|
|
235
|
+
|
|
236
|
+
1. PR で `src/datamodels_gtfs/__init__.py` の `__version__` を変え、[CHANGELOG.md](https://github.com/geolonia/datamodels-gtfs/blob/main/CHANGELOG.md) の
|
|
237
|
+
Unreleased の項目を、そのバージョンとリリース日の節に移します。
|
|
238
|
+
2. マージ後、そのコミットに `v` + バージョン(例: `v0.1.0`)のタグで GitHub のリリースを公開します。
|
|
239
|
+
[publish.yml](https://github.com/geolonia/datamodels-gtfs/blob/main/.github/workflows/publish.yml) がタグを確かめ、テストを実行し、wheel と sdist を作り、
|
|
240
|
+
trusted publishing で PyPI に公開します(トークンはこのリポジトリに置きません)。プレリリースでは
|
|
241
|
+
何も公開しません。
|
|
242
|
+
|
|
243
|
+
## Related / 関連
|
|
244
|
+
|
|
245
|
+
- [geolonia/datamodels](https://github.com/geolonia/datamodels): the catalog, whose `models/transit/`
|
|
246
|
+
schemas, mappings and notes this tool follows.
|
|
247
|
+
- [gtfs-jp-kit](https://github.com/Jasonin2099/gtfs-jp-kit): GTFS-JP profile checks; general GTFS-JP
|
|
248
|
+
rules found here are offered there.
|
|
249
|
+
|
|
250
|
+
## License / ライセンス
|
|
251
|
+
|
|
252
|
+
[MIT](https://github.com/geolonia/datamodels-gtfs/blob/main/LICENSE). `src/datamodels_gtfs/realtime/gtfs-realtime.proto` (and the descriptor built from it) is
|
|
253
|
+
from [google/transit](https://github.com/google/transit), Apache-2.0
|
|
254
|
+
([LICENSE-gtfs-realtime.txt](https://github.com/geolonia/datamodels-gtfs/blob/main/src/datamodels_gtfs/realtime/LICENSE-gtfs-realtime.txt)).
|
|
255
|
+
Test fixtures: see [tests/fixtures/README.md](https://github.com/geolonia/datamodels-gtfs/blob/main/tests/fixtures/README.md).
|