Coder Social home page Coder Social logo

mbta_departure_board's Introduction

MBTA Departure Board for North and South Stations

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

Running the example

  • 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

Overall Approach ( Naive version )

  1. Initialize board with predictions for North and South stations.

    1. Retrieve list of current predictions
    2. Filter for predictions that have departure times
    3. Flatten into a simpler structure for use in templates
  2. Open stream for live receiving prediction updates

    1. For each trip in stream
    2. If current list has a matching prediction, then update existing with new departure time / status. Match is performed using trip ID
    3. If current list does not have a matching prediction, push the new prediction onto the list ( it's a new upcoming departure )
  3. Prune predictions list by removing predictions whose departure times are null or are in the past

Compromises, Hacks, Ommitted Functionality

  • 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 )

More complete version

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.

Excuses

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.