Skip to content

JSON > + direction_id_use_other_trips_with_same_headsign #sncf - #80

Open
mmathieum wants to merge 7 commits into
masterfrom
mm/json_direction_id_use_other_trips_with_same_headsign
Open

JSON > + direction_id_use_other_trips_with_same_headsign #sncf#80
mmathieum wants to merge 7 commits into
masterfrom
mm/json_direction_id_use_other_trips_with_same_headsign

Conversation

@mmathieum

@mmathieum mmathieum commented Jul 22, 2026

Copy link
Copy Markdown
Member

Try to fix missing trips.direction_id when other route trips with same head-sign have a direction_id...

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an opt-in GTFS parsing step to infer and fill missing trips.direction_id values by looking at other trips on the same route with the same trip_headsign, aligning with the PR goal of reducing missing direction IDs (e.g., SNCF feeds).

Changes:

  • Introduces GSpec.fixMissingTripDirectionIds() (guarded by direction_id_use_other_trips_with_same_headsign) and wires it into the parser startup flow.
  • Extends route JSON config (RouteConfig) with a new opt-in flag to enable this behavior.
  • Minor logging/formatting adjustments and a small iteration refactor.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/main/java/org/mtransit/parser/mt/MDirectionHeadSignFinder.kt Tweaks debug log message formatting for headsign/merge diagnostics.
src/main/java/org/mtransit/parser/gtfs/data/GTrip.kt Refactors list-update iteration style for trip updates.
src/main/java/org/mtransit/parser/gtfs/data/GSpecExt.kt Adds opt-in direction-id auto-fix logic based on same-route same-headsign trips.
src/main/java/org/mtransit/parser/gtfs/data/GSpec.java Exposes route-id enumeration for trips and includes minor formatting updates.
src/main/java/org/mtransit/parser/DefaultAgencyTools.java Calls the new direction-id auto-fix step during parsing startup.
src/main/java/org/mtransit/parser/config/gtfs/data/RouteConfig.kt Adds new JSON config flag direction_id_use_other_trips_with_same_headsign.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/main/java/org/mtransit/parser/gtfs/data/GSpec.java
Comment thread src/main/java/org/mtransit/parser/gtfs/data/GSpec.java Outdated
Comment thread src/main/java/org/mtransit/parser/gtfs/data/GSpecExt.kt
Comment thread src/main/java/org/mtransit/parser/gtfs/data/GTrip.kt Outdated
Comment thread src/main/java/org/mtransit/parser/gtfs/data/GSpecExt.kt
@mmathieum
mmathieum marked this pull request as ready for review July 23, 2026 19:44
@mmathieum
mmathieum requested a review from Copilot July 23, 2026 19:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Comment thread src/main/java/org/mtransit/parser/gtfs/data/GSpecExt.kt
@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 516fd264-1d8a-4b94-8151-4af3f767bc4f

📥 Commits

Reviewing files that changed from the base of the PR and between 246bab5 and 4f36c1e.

📒 Files selected for processing (7)
  • src/main/java/org/mtransit/parser/DefaultAgencyTools.java
  • src/main/java/org/mtransit/parser/config/gtfs/data/RouteConfig.kt
  • src/main/java/org/mtransit/parser/gtfs/data/GSpec.java
  • src/main/java/org/mtransit/parser/gtfs/data/GSpecExt.kt
  • src/main/java/org/mtransit/parser/gtfs/data/GTrip.kt
  • src/main/java/org/mtransit/parser/mt/MDirectionHeadSignFinder.kt
  • src/main/java/org/mtransit/parser/mt/MDirectionSplitter.kt

📝 Walkthrough

Summary by CodeRabbit

Release Notes

  • New Features

    • Added optional configuration property to enable direction ID inference from trips with matching headsigns.
    • Automatic detection and normalization of missing trip direction IDs integrated into the GTFS processing pipeline.
  • Improvements

    • Enhanced diagnostic logging with clearer formatting for direction ID resolution and merge operations.

Walkthrough

The change adds configurable inference for missing trip direction IDs, persists updates through GSpec extensions, and updates direction assignment callers. It also improves head-sign diagnostic messages.

Changes

Trip direction normalization

Layer / File(s) Summary
Direction update contract
src/main/java/org/mtransit/parser/gtfs/data/GSpec.java, src/main/java/org/mtransit/parser/gtfs/data/GSpecExt.kt, src/main/java/org/mtransit/parser/gtfs/data/GTrip.kt
GSpec exposes direction-related helpers. GTrip supports controlled direction updates. Matching trips update in place and direction IDs can be persisted.
Missing direction ID fix
src/main/java/org/mtransit/parser/config/gtfs/data/RouteConfig.kt, src/main/java/org/mtransit/parser/gtfs/data/GSpecExt.kt, src/main/java/org/mtransit/parser/DefaultAgencyTools.java
RouteConfig adds an opt-in head-sign setting. The GTFS pipeline infers missing direction IDs when one existing direction matches and applies the updates after GTFS loading.
Direction assignment and diagnostics
src/main/java/org/mtransit/parser/mt/MDirectionSplitter.kt, src/main/java/org/mtransit/parser/mt/MDirectionHeadSignFinder.kt
Direction splitting passes numeric direction IDs to the update helper. Head-sign merge and unresolved-situation logs now include clearer quoted values and trip IDs.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant DefaultAgencyTools
  participant GSpec
  participant GTrip
  participant Database
  DefaultAgencyTools->>GSpec: fixMissingTripDirectionIds()
  GSpec->>GTrip: group missing IDs by headsign
  GSpec->>GSpec: select one matching direction
  GSpec->>GTrip: updateDirectionId(tripIdInts, directionId)
  GSpec->>Database: persist direction IDs
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title identifies the JSON configuration for using direction IDs from trips with the same headsign, which matches the primary change.
Description check ✅ Passed The description clearly states that missing trips.direction_id values use direction IDs from other trips with the same headsign.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch mm/json_direction_id_use_other_trips_with_same_headsign

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants