Create a departure board similar to [ https://commons.wikimedia.org/wiki/File:North_Station_departure_board.JPG ]
Board should show
- the predicted departures at North and South stations
- the train destinations
- departure times
- the track numbers
- boarding status (e.g. 'Boarding', 'All Aboard', 'Delayed')
- real time updates for predicted departures
- npm install
- npm run keys
- npm start
- https://localhost:8889/?key=your\_api\_key , or,
add your API key to public/js/app.js
- without a valid API key live stream will not work
- this is to prevent having to store my API key in the source coe
-
Initialize board with predictions for North and South stations.
- Retrieve list of current predictions
- Filter for predictions that have departure times
- Flatten into a simpler structure for use in templates
-
Open stream for live receiving prediction updates
- For each trip in stream
- If current list has a matching prediction, then update existing with new departure time / status. Match is performed using trip ID
- If current list does not have a matching prediction, push the new prediction onto the list ( it's a new upcoming departure )
-
Prune predictions list by removing predictions whose departure times are null or are in the past
- Couldn't figure out how to get "trip" included in realtime streamed predictions. So makes a second API call for "trip" in order to populate "destination", using trip.attributes.headsign
- Didn't implement boarding track number. Would currently use same approach as for trips.
- Some vehicle ids look like
block_2151_schedBasedVehicle
. In this case I extract the integer and use that as the train id. Not sure that's correct. - Initial board often has fewer entries compared to boards at mbta.com. Could be remedied by fetching schedules to fill out departure times for predictions that don't have them, thus adding more predictions to the list ( list only displays predictions that have departure times )
On branch backfill-departures-using-schedules
Initial batch of predictions has only a few departures with times. So board looks a little sparse, and on weekends can be empty. A more complete initial list is generated by backfilling departure times using trip schedules, since
The naive version is missing departures that show up on ( https://mbta.com/stops/place-north ) and ( https://mbta.com/stops/place-sstat ).
The initial batch of predictions only has times for departures that are close in time.
So this version backfills the missing departure times by retrieving schedules, and using the station departure times to backfill the initial predictions.
This is my first use of Vue. I'm not a front end developer, so I chose the simplest framework that has data bindings, but still there was a learning curve, and it's mostly cut and paste from a "Hello World"
Still feeling clumsy with the MBTA API, and I know I'm not using it very well wrt getting relationship object information into streamed prediction objects.