Skip to content

Consume GTFS-RT Vehicle Positions, introduce API - #3981

Merged
leonardehrenfried merged 41 commits into
opentripplanner:dev-2.xfrom
ibi-group:vehicle-positions
Mar 22, 2022
Merged

Consume GTFS-RT Vehicle Positions, introduce API#3981
leonardehrenfried merged 41 commits into
opentripplanner:dev-2.xfrom
ibi-group:vehicle-positions

Conversation

@leonardehrenfried

@leonardehrenfried leonardehrenfried commented Mar 14, 2022

Copy link
Copy Markdown
Member

Summary

This PR adds a graph updater that downloads GTFS-RT Vehicle Position feeds. It keeps an internal data model and accounting for them and adds the entities to the legacy graphql API.

This is a port of what IBI added to their 1.5 fork last year: ibi-group#63

The main difference is that the positions are not added directly to the TripPattern instances but they are stored in a separate service just as the realtime alerts are.

Configuration

To use it add the following to router-config.json

{
  "updaters": [
    {
      "type": "vehicle-positions",
      "sourceType": "gtfs-http",
      "url": "https://s3.amazonaws.com/kcm-alerts-realtime-prod/vehiclepositions.pb",
      "feedId": "1",
      "frequencySec": 59
    }
  ]
}

You can query them in the legacy GraphQL API like this:

query {
	patterns {
		route {
			gtfsId
			shortName
		}
		code
		vehiclePositions {
			vehicleId
			lat
			lon
			vehicleId
			stopRelationship {
				status
				stop {
					name
				}
			}
			lastUpdated
			trip {
				gtfsId
				tripHeadsign
			}
		}
	}
}


Future work

This solution provides an easy to consume API for drawing a couple of dozen vehicles on a map, but is not really suitable for fetching a large number of quickly updating positions. For such a system a streaming approach (MQTT, websockets, ...) would superior. Once IBI has streaming data sources and the need to draw a large number of updates on a screen, they might contribute a solution for this.

Unit tests

Both the parser and the matcher/service have tests.

Code style

Yes.

Documentation

Yes.

/cc @miles-grant-ibigroup @demory

@leonardehrenfried
leonardehrenfried requested a review from a team as a code owner March 14, 2022 10:15
@leonardehrenfried leonardehrenfried changed the title Consume GTFS-RT Vehicle Positions and introduce API Consume GTFS-RT Vehicle Positions, introduce API Mar 14, 2022
Comment thread pom.xml Outdated
Comment thread src/ext/resources/legacygraphqlapi/schema.graphqls Outdated
@leonardehrenfried leonardehrenfried removed their assignment Mar 14, 2022
hannesj
hannesj previously approved these changes Mar 18, 2022
Comment thread src/ext/resources/legacygraphqlapi/schema.graphqls Outdated
Comment thread src/ext/resources/legacygraphqlapi/schema.graphqls Outdated
Comment thread src/ext/resources/legacygraphqlapi/schema.graphqls Outdated
Comment thread src/ext/resources/legacygraphqlapi/schema.graphqls Outdated
Comment thread src/ext/resources/legacygraphqlapi/schema.graphqls
Comment thread src/ext/resources/legacygraphqlapi/schema.graphqls Outdated
Comment thread src/ext/resources/legacygraphqlapi/schema.graphqls Outdated
Comment thread src/ext/resources/legacygraphqlapi/schema.graphqls Outdated

@optionsome optionsome left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is undoing @t2gran work on the data fetchers. I guess it's better to use the version that is automatically generated instead of always rerunning the intellij refactor thingy?

@leonardehrenfried

Copy link
Copy Markdown
Member Author

This is undoing @t2gran work on the data fetchers. I guess it's better to use the version that is automatically generated instead of always rerunning the intellij refactor thingy?

Yes, after you left we decided the following: we will keep the public but Hannes will look into modifying the generator so that this is no longer emitted.

@leonardehrenfried
leonardehrenfried merged commit fcfd2d9 into opentripplanner:dev-2.x Mar 22, 2022
t2gran pushed a commit that referenced this pull request Mar 22, 2022
vesavlad added a commit to opentransportro/OpenTripPlanner that referenced this pull request Apr 3, 2022
Consume GTFS-RT Vehicle Positions, introduce API
# Conflicts:
#	src/ext/java/org/opentripplanner/ext/legacygraphqlapi/LegacyGraphQLIndex.java
#	src/ext/java/org/opentripplanner/ext/legacygraphqlapi/generated/LegacyGraphQLDataFetchers.java
#	src/ext/java/org/opentripplanner/ext/legacygraphqlapi/generated/LegacyGraphQLTypes.java
#	src/main/java/org/opentripplanner/model/TripPattern.java
#	src/main/java/org/opentripplanner/updater/DataSourceType.java
#	src/main/java/org/opentripplanner/updater/UpdatersParameters.java
@leonardehrenfried
leonardehrenfried deleted the vehicle-positions branch April 4, 2022 15:21
@leonardehrenfried leonardehrenfried added IBI Developed by or important for IBI Group and removed IBI test labels Jun 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

IBI Developed by or important for IBI Group !New Feature A functional feature targeting the end user.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants