Skip to content

JSON > + direction_id_use_other_trips_with_same_headsign #sncf - #80

Open
mmathieum wants to merge 8 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 8 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: 061e96d6-03f7-48a1-aa91-3edf0723e8f9

📥 Commits

Reviewing files that changed from the base of the PR and between 4f36c1e and 0e42c51.

📒 Files selected for processing (1)
  • src/main/java/org/mtransit/parser/mt/MDirectionHeadSignFinder.kt
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/java/org/mtransit/parser/mt/MDirectionHeadSignFinder.kt

📝 Walkthrough

Summary by CodeRabbit

Release Notes

  • New Features

    • Added an optional setting to infer missing trip direction IDs from trips with matching headsigns.
    • Automatically detects and normalizes missing direction IDs during GTFS processing.
  • Improvements

    • Improved direction ID assignment for inferred trips.
    • Enhanced diagnostic logging with clearer details for direction 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

Possibly related PRs

🚥 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 configuration added for the headsign-based direction ID fix, but it is terse and uses unclear symbols.
Description check ✅ Passed The description directly explains the fix for missing trips.direction_id values using 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

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@qodo-code-review

Copy link
Copy Markdown

ⓘ Your Qodo trial ends soon. Ask your workspace admin to set up billing to keep reviews running after the trial. Manage billing

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