View Source MBTA.Api.Prediction (mbta_sdk v0.1.0)
API calls for all endpoints tagged Prediction
.
Summary
Functions
NOTE: A filter MUST be present for any predictions to be returned. List of predictions for trips. To get the scheduled times instead of the predictions, use /schedules
. The predicted arrival time (//data/{index}/attributes/arrival_time
) and departure time (/data/{index}/attributes/departure_time
) to/from a stop (/data/{index}/relationships/stop/data/id
) at a given sequence (/data/{index}/attriutes/stop_sequence
) along a trip (/data/{index}/relationships/trip/data/id
) going a direction (/data/{index}/attributes/direction_id
) along a route (/data/{index}/relationships/route/data/id
). See GTFS Realtime FeedMesage
FeedEntity
TripUpdate
TripDescriptor
See GTFS Realtime FeedMesage
FeedEntity
TripUpdate
StopTimeUpdate
## When a vehicle is predicted to be at a stop /predictions?filter[stop]=STOP_ID
## The predicted schedule for one route /predictions?filter[route]=ROUTE_ID
## The predicted schedule for a whole trip /predictions?filter[trip]=TRIP_ID
Functions
@spec api_web_prediction_controller_index( Tesla.Env.client(), keyword() ) :: {:ok, MBTA.Model.Forbidden.t()} | {:ok, MBTA.Model.TooManyRequests.t()} | {:ok, MBTA.Model.Predictions.t()} | {:ok, MBTA.Model.BadRequest.t()} | {:error, Tesla.Env.t()}
NOTE: A filter MUST be present for any predictions to be returned. List of predictions for trips. To get the scheduled times instead of the predictions, use /schedules
. The predicted arrival time (//data/{index}/attributes/arrival_time
) and departure time (/data/{index}/attributes/departure_time
) to/from a stop (/data/{index}/relationships/stop/data/id
) at a given sequence (/data/{index}/attriutes/stop_sequence
) along a trip (/data/{index}/relationships/trip/data/id
) going a direction (/data/{index}/attributes/direction_id
) along a route (/data/{index}/relationships/route/data/id
). See GTFS Realtime FeedMesage
FeedEntity
TripUpdate
TripDescriptor
See GTFS Realtime FeedMesage
FeedEntity
TripUpdate
StopTimeUpdate
## When a vehicle is predicted to be at a stop /predictions?filter[stop]=STOP_ID
## The predicted schedule for one route /predictions?filter[route]=ROUTE_ID
## The predicted schedule for a whole trip /predictions?filter[trip]=TRIP_ID
Parameters
connection
(MBTA.Connection): Connection to serveropts
(keyword): Optional parameters:"page[offset]"
(integer()): Offset (0-based) of first element in the page:"page[limit]"
(integer()): Max number of elements to return:sort
(String.t): Results can be sorted by the id or any/data/{index}/attributes
key. | JSON pointer | Direction |sort
| |--------------|-----------|------------| |/data/{index}/attributes/arrival_time
| ascending |arrival_time
| |/data/{index}/attributes/arrival_time
| descending |-arrival_time
| |/data/{index}/attributes/departure_time
| ascending |departure_time
| |/data/{index}/attributes/departure_time
| descending |-departure_time
| |/data/{index}/attributes/direction_id
| ascending |direction_id
| |/data/{index}/attributes/direction_id
| descending |-direction_id
| |/data/{index}/attributes/schedule_relationship
| ascending |schedule_relationship
| |/data/{index}/attributes/schedule_relationship
| descending |-schedule_relationship
| |/data/{index}/attributes/status
| ascending |status
| |/data/{index}/attributes/status
| descending |-status
| |/data/{index}/attributes/stop_sequence
| ascending |stop_sequence
| |/data/{index}/attributes/stop_sequence
| descending |-stop_sequence
| |/data/{index}/attributes/arrival_time
if present, otherwise/data/{index}/attributes/departure_time
| ascending |time
| |/data/{index}/attributes/arrival_time
if present, otherwise/data/{index}/attributes/departure_time
| descending |-time
|:"fields[prediction]"
(String.t): Fields to include with the response. Multiple fields MUST be a comma-separated (U+002C COMMA, ",") list. Note that fields can also be selected for included data types: see the V3 API Best Practices for an example.:include
(String.t): Relationships to include.schedule
stop
route
trip
vehicle
alerts
The value of the include parameter MUST be a comma-separated (U+002C COMMA, ",") list of relationship paths. A relationship path is a dot-separated (U+002E FULL-STOP, ".") list of relationship names. JSONAPI "include" behavior ## Examplehttps://api-v3.mbta.com/predictions?filter%5Bstop%5D=place-sstat&filter%5Bdirection_id%5D=0&include=stop
returns predictions from South Station with direction_id=0, below is a truncated response with only relevant fields displayed:{ "data": [ { "id": "prediction-CR-Weekday-Fall-18-743-South Station-02-1", "relationships": { "stop": { "data": { "id": "South Station-02", "type": "stop" } }, }, "type": "prediction" } ], "included": [ { "attributes": { "platform_code": "2", }, "id": "South Station-02", "type": "stop" } ], }
Note the stop relationship; use it to cross-reference stop-id with the included stops to retrieve the platform_code for the given prediction. ## Note on trips A Vehicle'strip
is what is currently being served. A Prediction also has avehicle
: this is the vehicle we predict will serve this trip/stop. Since we know vehicles make future trips, the trip the vehicle is currently servicing can be different from the trips we're making predictions for. For example: Vehicle 1234 is currently serving trip A The block is Trip A → Trip B → Trip C We'll be making predictions for the rest of trip A, as well as all the stops of trip B and trip C. Thetrip
for the Vehicle is alwaysA
, and all of the Predictions will reference Vehicle 1234.:"filter[latitude]"
(String.t): Latitude/Longitude must be both present or both absent.:"filter[longitude]"
(String.t): Latitude/Longitude must be both present or both absent.:"filter[radius]"
(Date.t): Radius accepts a floating point number, and the default is 0.01. For example, if you query for: latitude: 42, longitude: -71, radius: 0.05 then you will filter between latitudes 41.95 and 42.05, and longitudes -70.95 and -71.05.:"filter[direction_id]"
(String.t): Filter by direction of travel along the route. Must be used in conjuction withfilter[route]
to apply. The meaning ofdirection_id
varies based on the route. You can programmatically get the direction names from/routes
/data/{index}/attributes/direction_names
or/routes/{id}
/data/attributes/direction_names
.:"filter[route_type]"
(String.t): Filter by route_type: https://developers.google.com/transit/gtfs/reference/routes-file. Multipleroute_type
MUST be a comma-separated (U+002C COMMA, ",") list. Must be used in conjunction with another filter.:"filter[stop]"
(String.t): Filter by/data/{index}/relationships/stop/data/id
. Multiple IDs MUST be a comma-separated (U+002C COMMA, ",") list. Parent station IDs are treated as though their child stops were also included.:"filter[route]"
(String.t): Filter by/data/{index}/relationships/route/data/id
. Multiple IDs MUST be a comma-separated (U+002C COMMA, ",") list.:"filter[trip]"
(String.t): Filter by/data/{index}/relationships/trip/data/id
. Multiple IDs MUST be a comma-separated (U+002C COMMA, ",") list.:"filter[route_pattern]"
(String.t): Filter by/included/{index}/relationships/route_pattern/data/id
of a trip. Multipleroute_pattern_id
MUST be a comma-separated (U+002C COMMA, ",") list.
Returns
{:ok, MBTA.Model.Predictions.t}
on success{:error, Tesla.Env.t}
on failure