JSON > + direction_id_use_other_trips_with_same_headsign #sncf#80
Draft
mmathieum wants to merge 1 commit into
Draft
JSON > + direction_id_use_other_trips_with_same_headsign #sncf#80mmathieum wants to merge 1 commit into
JSON > + direction_id_use_other_trips_with_same_headsign #sncf#80mmathieum wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
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 bydirection_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 on lines
357
to
359
| @NotNull | ||
| private Collection<Integer> getAllTripRouteIdInts() { | ||
| public Collection<Integer> getAllTripRouteIdInts() { | ||
| if (USE_DB_ONLY) { |
Comment on lines
377
to
381
| public void updateTripDirectionId(int directionId, @Nullable Collection<Integer> tripIdInts) { | ||
| if (tripIdInts == null) { | ||
| return; | ||
| } | ||
| if (tripIdInts == null) return; | ||
| List<Integer> routeIdInts = new ArrayList<>(); | ||
| for (Integer tripIdInt : tripIdInts) { | ||
| routeIdInts.add(getTripRouteId(tripIdInt)); |
Comment on lines
+12
to
+26
| getAllTripRouteIdInts().forEach { routeIdInt -> | ||
| getRouteTrips(routeIdInt) | ||
| .filter { it.directionIdOrOriginal == null } | ||
| .groupBy { it.tripHeadsign } | ||
| .forEach { (tripHeadsign, gTripsNoDirectionId) -> | ||
| if (tripHeadsign == null) return@forEach | ||
| val allRouteTripsWithSameHeadsign = getRouteTrips(routeIdInt) | ||
| .filter { it.tripHeadsign == tripHeadsign } | ||
| .takeIf { it.isNotEmpty() } ?: return@forEach | ||
| val distinctOriginalDirectionIds = allRouteTripsWithSameHeadsign.mapNotNull { it.directionIdOrOriginal }.distinct() | ||
| distinctOriginalDirectionIds.singleOrNull()?.let { originalDirectionId -> | ||
| updateTripDirectionId(originalDirectionId, gTripsNoDirectionId.map { it.tripIdInt }) | ||
| tripIdDirectionFixed += gTripsNoDirectionId.size | ||
| } | ||
| } |
Comment on lines
225
to
229
| fun updateList(gTrips: MutableList<GTrip>, condition: (GTrip) -> Boolean, updateTrip: (GTrip) -> GTrip): List<GTrip> { | ||
| for (i in 0 until gTrips.size) { | ||
| val gTrip = gTrips[i] | ||
| for ((i, element) in gTrips.withIndex()) { | ||
| val gTrip = element | ||
| if (condition(gTrip)) { | ||
| gTrips[i] = updateTrip(gTrip) |
Comment on lines
+8
to
+10
| fun GSpec.fixMissingTripDirectionIds() { | ||
| if (!Configs.routeConfig.directionIdUseOtherTripsWithSameHeadsign) return | ||
| MTLog.log("Try fixing GTFS trips w/o direction IDs...") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Try to fix missing trips.direction_id when other route trips with same head-sign have a direction_id...