Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Add Rule for Block Consistency in route_type Values Across block_id #1925

Open
YuliaTom opened this issue Nov 25, 2024 · 1 comment
Labels
new rule New rule to be added

Comments

@YuliaTom
Copy link

YuliaTom commented Nov 25, 2024

Describe the problem

This is a proposal for a new validation rule for the GTFS Validator, inspired by the GTFS specification's description of block_id. According to the spec, block_id is used to group trips operated by the same vehicle, and this implies that all trips within the same block should share the same mode of transportation. A validation rule can help ensure that vehicles are not incorrectly switching modes within a block.
Specifically, this rule would check that all trips sharing the same block_id in trips.txt reference routes with consistent route_type values in routes.txt. If a block_id is found to span multiple route_type values, a WARNING should be issued.
This enhancement aligns with how some GTFS consumers (such as Google, please see the attached screenshot) handle blocks to ensure feed quality and could prevent potential errors in downstream systems.

Proposed Rule
Rule Name: Inconsistent route_type Values in Trips Sharing a block_id
Description: Trips with the same block_id in the trips.txt file must have consistent route_type values in the routes.txt file. If trips within a block have differing route_type values, a warning needs to be issued.
Severity: WARNING
Affected Files:
trips.txt
routes.txt

Describe the new validation rule

routeTypeMap = {route["route_id"]: route["route_type"] for route in gtfsData["routes.txt"]}

blockRouteTypes = {}
for trip in gtfsData["trips.txt"]:
    block_id = trip["block_id"]
    route_id = trip["route_id"]
    if block_id and route_id in routeTypeMap:
        blockRouteTypes.setdefault(block_id, set()).add(routeTypeMap[route_id])

warnings = []
for block_id, route_types in blockRouteTypes.items():
    if len(route_types) > 1:
        warnings.append(f"Inconsistent route_types for block_id '{block_id}': {list(route_types)}")

return warnings

Sample GTFS datasets

austin_gtfs.zip

In this GTFS sample block_id 20090-1-161 is associated with routes 20 and 484. Route 20 is of type 1 and 484 of type 3, which should trigger the inconsistent route type warning.

Severity

WARNING

Additional context

Image

@YuliaTom YuliaTom added new rule New rule to be added status: Needs triage Applied to all new issues labels Nov 25, 2024
@emmambd
Copy link
Contributor

emmambd commented Nov 29, 2024

Thanks for flagging this @YuliaTom! We agree this should be added as a warning in the validator and will be added to our backlog.

If you'd like to accelerate the development of this rule, you are welcome to add it and open a PR for review! Read more about our code contribution guidelines and process here.

@emmambd emmambd removed the status: Needs triage Applied to all new issues label Nov 29, 2024
@emmambd emmambd added this to the 7.0 Validator Release milestone Nov 29, 2024
@qcdyx qcdyx removed this from the 7.0 Validator Release milestone Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new rule New rule to be added
Projects
None yet
Development

No branches or pull requests

3 participants