All Projects → blahblahblah- → goodservice

blahblahblah- / goodservice

Licence: MIT license
Website that detects headway discrepancy on New York City Subway system using live countdown clocks

Programming Languages

javascript
184084 projects - #8 most used programming language
ruby
36898 projects - #4 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to goodservice

theweekendest
Real-time New York City subway service map
Stars: ✭ 51 (+96.15%)
Mutual labels:  transit, nyc, gtfs, mta, subway, gtfs-rt
subwayclock
Display clock for NYC subways
Stars: ✭ 29 (+11.54%)
Mutual labels:  transit, nyc, mta, subway
retro-gtfs
Collect real-time transit data and process it into a retroactive GTFS 'schedule' which can be used for routing/analysis
Stars: ✭ 45 (+73.08%)
Mutual labels:  transit, gtfs, gtfs-rt
public-transit-tools
Tools for working with GTFS public transit data in ArcGIS
Stars: ✭ 126 (+384.62%)
Mutual labels:  transit, gtfs, gtfs-rt
transitland-atlas
an open directory of mobility feeds and operators — powers both Transitland v1 and v2
Stars: ✭ 55 (+111.54%)
Mutual labels:  transit, gtfs, gtfs-rt
Loader
deploy
Stars: ✭ 6 (-76.92%)
Mutual labels:  transit, gtfs
Mobility Explorer
Understand transportation networks around the world using Transitland open data and Valhalla routing engine APIs
Stars: ✭ 31 (+19.23%)
Mutual labels:  transit, gtfs
mapzen-gtfs
Python library for reading and writing GTFS feeds
Stars: ✭ 27 (+3.85%)
Mutual labels:  transit, gtfs
Gtfs To Html
Build human readable transit timetables as HTML or PDF from GTFS.
Stars: ✭ 119 (+357.69%)
Mutual labels:  transit, gtfs
Mapnificent
Mapnificent shows you areas you can reach with public transport in a given time.
Stars: ✭ 302 (+1061.54%)
Mutual labels:  transit, gtfs
Transitland Datastore
Transitland's centralized web service API for both querying and editing aggregated transit data from around the world
Stars: ✭ 101 (+288.46%)
Mutual labels:  transit, gtfs
Rrrr
RRRR rapid real-time routing
Stars: ✭ 134 (+415.38%)
Mutual labels:  transit, gtfs
Awesome Transit
Community list of transit APIs, apps, datasets, research, and software 🚌🌟🚋🌟🚂
Stars: ✭ 713 (+2642.31%)
Mutual labels:  transit, gtfs
Tidytransit
R package for working with the General Transit Feed Specification (GTFS)
Stars: ✭ 84 (+223.08%)
Mutual labels:  transit, gtfs
Node Gtfs
Import GTFS transit data into SQLite and query routes, stops, times, fares and more.
Stars: ✭ 323 (+1142.31%)
Mutual labels:  transit, gtfs
Peartree
peartree: A library for converting transit data into a directed graph for sketch network analysis.
Stars: ✭ 116 (+346.15%)
Mutual labels:  transit, gtfs
nepomuk
A public transit router for GTFS feeds (currently only static) written in modern c++
Stars: ✭ 22 (-15.38%)
Mutual labels:  transit, gtfs
Onebusaway Application Modules
The core OneBusAway application suite.
Stars: ✭ 174 (+569.23%)
Mutual labels:  transit, gtfs
path-data
A gRPC API that exposes various information about the PATH transit system.
Stars: ✭ 29 (+11.54%)
Mutual labels:  nyc, subway
transxchange2gtfs
tool to convert transxchange data into a GTFS feed
Stars: ✭ 26 (+0%)
Mutual labels:  transit, gtfs

This repo is deprecated. The app has been re-written and its new source code can be found at https://github.com/blahblahblah-/goodservice-v2.

goodservice

This is a Rails app that generates live route maps, detects headway discrepancies, track delays and compare runtimes to the schedule on the New York City Subway system by comparing the data for live countdown clocks with the static schedule data provided by the MTA.

See it live at https://www.goodservice.io.

Running locally

To run locally, you'll need a couple things. First, the app has only been tested with Ruby 2.4.2 and Rails 5.2. We suggest managing this with rbenv. It also depends on Redis, Postgres, Yarn, and Semantic UI React. If you are on a Mac with Homebrew installed, you can get all these requirements with the following commands:

# Ruby dependencies
brew install rbenv
brew install ruby-build
rbenv install 2.4.2
gem install bundler
gem install rails
gem install foreman

# Other dependencies
brew install postgresql
brew install redis
brew install node
npm install -g yarn

Next, you'll need to sign up for a developer account with the MTA. To do so, go to https://api.mta.info. You'll get an API key and set it as MTA_KEY env variable.

Finally, you'll need to download the current static schedules from the MTA. Go to https://web.mta.info/developers/developer-data-terms.html, agree to the terms, and then download the data for New York City Transit. (Ctrl+F for "GTFS".) Put this into the import folder and unzip it.

Finally, to run the app locally, do

export MTA_KEY=<<YOUR API KEY>>
bundle install
yarn install
initdb
rails db:reset  # This will take a *very* long time on its first run
rails dev:cache
foreman start

A brief tour of the code

This is a Rails app that uses React as a view manager. As such, there are a lot of moving components. We briefly explain how data flows and how the code is laid out.

Server side: Rails

The server performs two major functions: First, it runs a cron job that updates the current status of all routes and lines. This cron job is located in /lib/clock.rb. It is currently hard coded to refresh train data every minute and to refresh route data every five minutes.

Second, it actually serves up the route info that is processed by this cron job. In particular, a Redis cache maintains all the headway info that is served by API (described below). All of the models that are used to process this information live in either /app/models or, closer to the ultimate product, in /app/models/display. If you want to start tracing through the code, you should begin at the self.headway_info function in /app/models/schedule_processor.rb.

A rake job at /lib/tasks/scheduler.rake is to be run daily to compile runtimes comparison history from the model LineDirectionStatus into JSON and stored into the LineStatusSummary model, as the LineDirectionStatus table can get really big. The job is indempotent, so it would not be a problem if it ran more than once.

Another cron job located in /lib/clock.rb runs daily at midnight to clear out old rows of data storing train statuses that drive the pretty graphs and historical stats.

Client side: React

The client side view libraries are a React app that is compiled by the webpacker gem. For more information on webpacker, you can see their repository. But the basic summary is that all entry points (in React lingo) live in /app/javascript/packs and are compiled to the /public directory. As with all Rails apps, this is driven by the views in /app/views, which are basically the bare minimum to get the compiled React to appear.

In the middle: An API

The React front end is fed by an API that Rails serves. The routes are specified in the /app/controllers directory. Specifically, dynamically-generated routes are specified in /config/routes.rb. The /api/info route is probably most interesting as it drives the main React app. This route refers specifically to the /app/controllers/api/info_controller.rb controller. Note that that file is a very thin wrapper around the ScheduleProcessor's headway_info function, which is specified in /app/models/schedule_processor.rb, simply returning a JSON of the results.

Supported external services

Twitter

The cron job to update route statuses is also capable of tweeting a list of delayed routes every 10 minutes. Make sure the env variables TWITTER_ACCESS_TOKEN, TWITTER_ACCESS_TOKEN_SECRET, TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET are populated.

Slack

/app/controllers/api/slack_controller.rb handles the API endpoints used to serve the goodservice.io Slack App, found here. The API pulls from Redis the JSON compiled by the cron job and transforms into a JSON structure that Slack can use. SLACK_CLIENT_ID and SLACK_CLIENT_SECRET env variables are required to allow installation of the app on to a Slack workspace. The env variable SLACK_SIGNING_SECRET is needed to process Slack API requests.

Dead Man's Snitch

Dead Man's Switch integration is supported to allow monitoring of the cron jobs being run. Ensure the env variables DEADMANSSNITCH_API_KEY and DEADMANSSNITCH_TOKEN are populated.

Google Analytics

The React frontend app uses react-router module to change browser's URL in the single-page app, so the app detects URL changes and sends the new URL to GA. Events that don't change the URL (i.e. certain modals and tabs, and Slack app events) are also sent to GA as events. Currently, the GA ID is hardcoded.

Other resources

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].