Transitous Documentation

repository·main·Indexed 20 days ago

https://github.com/public-transport/transitous

A community-driven, provider-neutral international public transport routing service using open GTFS and GTFS-RT data feeds. The project includes a CLI for fetching and post-processing transit data (GTFS, GBFS, NETEX) via fetch.py, a MOTIS configuration generator, and tools for GTFS cleaning and validation. It supports multiple source types including Transitland Atlas, Mobility Database, HTTP, and FTP.

Tokens
2.6K
Snippets
4
Records
17
Agent score
71%

What's inside Transitous

  1. Overview of Transitous

    main
    Transitous is a community-run, provider-neutral international public transport routing service. It aims to provide free, privacy-focused routing that uses openly available GTFS/GTFS-RT feeds and FOSS routing engines, operating without regard to national borders.
  2. Timetable data sources for Great Britain

    main

    Timetable data for Great Britain is provided by Aubin MaaS Limited and includes the following components:

    • Bus Data: Data from the Department for Transport, Bus Open Data Service (guidance/requirements).
    • Rail Data: Converted National Rail timetable information powered by National Rail Enquiries (terms).
    • Location Data: Derived from OpenStreetMap under the ODbL Licence (copyright).
  3. Set up the Transitous website for development

    main

    To run the Transitous website locally for development, ensure you have the hugo (extended version) and npm installed.

    Follow these steps:

    1. Initialize submodules to ensure all dependencies are present.
    2. Install npm dependencies.
    3. Start the development server.

    Note: Hugo content rebuilds automatically, but if you modify PureScript files, you must restart the process to trigger a rebuild.

    git submodule update --init --checkout
    npm install
    npm run start
  4. How GTFS feed validity is determined

    main

    Transitous validates GTFS feeds to ensure they are not expired or set for a future date. The check_feed_timeframe_valid function uses the following logic:

    1. Timezone Detection: It attempts to find agency_timezone in the agency.txt file within the GTFS zip.
    2. Validity Check:
      • FeedValidity.IN_FUTURE: If the feed_start_date (from feed_info.txt) is in the future, the feed is considered not yet valid. If a feed is in the future, Transitous will skip the update and keep the old version.
      • FeedValidity.EXPIRED: If the feed's end date (checked via feed_info.txt, calendar.txt, or calendar_dates.txt) has passed, the feed is considered expired. If extend_calendar is not enabled in the source configuration, an error is raised.
  5. HTTP Source download behavior and TLS handling

    main

    When downloading from an HttpSource, the download_http_source function follows these rules:

    • URL Priority: It tries URLs in this order: url_override $\rightarrow$ url $\rightarrow$ cache_url.
    • TLS/SSL: If source.options.ignore_tls_errors is set to true, it uses a LenientCipherAdapter which sets cert_reqs=ssl.CERT_NONE and a lower security level (@SECLEVEL=1) to allow connection to servers with problematic certificates.
    • Conditional Downloads: It uses If-Modified-Since headers and checks the last-modified server header against the local file's modification time to avoid redundant downloads.
    • Embedded ZIPs: If the URL contains a # followed by a path (e.g., http://example.com/data.zip#inner.zip), it treats the content after the # as a specific file to extract from the downloaded ZIP.
  6. Configure Source options in Transitous

    main

    When defining a data source in Transitous, you can use several configuration keys to control how GTFS data is processed, fetched, and cleaned. The Source object (and its specialized subclasses) supports the following configuration parameters:

    General Processing

    • fix: Boolean. Whether to apply fixes to the data.
    • use-gtfsclean: Boolean. Whether to use GTFS cleaning logic (defaults to true).
    • fix-csv-quotes: Boolean. Whether to fix CSV quoting issues.
    • spec: String. The data specification (defaults to "gtfs").
    • skip: Boolean. Whether to skip this source.
    • skip-reason: String. The reason for skipping the source.
    • function: String (optional). A specific function to run.
    • script: String (optional). A specific script to run.
    • drop-too-fast-trips: Boolean. Whether to drop trips that are calculated to be too fast (defaults to true).
    • drop-shapes: Boolean. Whether to drop shapes (defaults to false).
    • drop-agency-names: List of strings. Agency names to drop.
    • keep-agency-names: List of strings. Agency names to keep.
    • keep-additional-fields: Boolean. Whether to keep additional fields (defaults to true).
    • extend-calendar: Boolean. Whether to extend the calendar.
    • default-timezone: String (optional). The default timezone for the source.
    • use-feed-proxy: Boolean. Whether to use a feed proxy.
    • enable-crowd-sourced-realtime: Boolean. Whether to enable crowd-sourced realtime data.

    Display Name Options

    Nested under display-name-options, you can control how names are mapped:

    • copy-trip-names-matching: String. Pattern for copying trip names.
    • keep-route-names-matching: String. Pattern for keeping route names.
    • move-headsigns-matching: String. Pattern for moving headsigns.

    License Information

    Nested under license:

    • spdx-identifier: String. The SPDX license ID.
    • url: String. URL to the license.
    • attribution-text: String. Text for attribution.
    • publisher: String. The license publisher.
    • publisher-url: String. URL for the publisher.
  7. Configure GTFS post-processing with gtfsclean

    main

    When fetching GTFS feeds, the Fetcher.postprocess method can apply various transformations using the gtfsclean tool. These options are controlled via the Source object in your metadata:

    • fix_csv_quotes: Runs ./src/fix-csv-quotes.py on the data.
    • use_gtfsclean: Enables the gtfsclean command with several sub-options:
      • fix: Applies --fix.
      • drop_too_fast_trips: Applies --drop-too-fast-trips.
      • drop_shapes: Applies --drop-shapes.
      • drop_agency_names: A list of agency names to drop using --drop-agency-names.
      • keep_agency_names: A list of agency names to keep using --keep-agency-names.
      • display_name_options:
        • copy_trip_names_matching: Uses --copy-trip-names-matching.
        • keep_route_names_matching: Uses --keep-route-names-matching.
        • move_headsigns_matching: Uses --move-headsigns-matching.
      • keep_additional_fields: Applies --keep-additional-fields.
  8. Validate SPDX license identifiers

    main
    Transitous requires valid SPDX license identifiers for feeds. The validate_spdx_identifier function ensures that the spdx_identifier provided in the source metadata is a valid expression that can be parsed by the license_expression library.
  9. Supported Source Types

    main

    Transitous supports several source types, which determine how data is retrieved. When defining a source in your configuration, set the type field to one of the following:

    • transitland-atlas: Uses the Transitland Atlas API. Requires transitland-atlas-id. Can include api-key and url-override.
    • mobility-database: Uses the Mobility Database. Requires mdb-id. Can include url-override.
    • http: Fetches data from a specific url. Supports http-options and cache-url.
    • ftp: Fetches data from an ftp URL.
    • url: Fetches data from a url. Supports headers and derive-trip-updates.