Code Monkey home page Code Monkey logo

mta_tracker's Introduction

MTA Tracker

GitHub Actions status | integration-tests

Introduction

MTA Tracker is a small web service to monitor NYC MTA subway service. The web service provides two endpoints /status and /uptime that can be used to check delays and uptime for a given subway line.

Given Requirements

  • Continuously monitors the status of MTA service to see whether a line is delayed or not.
    • When a line transitions from not delayed → delayed, you should print the following message to console or to a logfile: “Line <line_name> is experiencing delays”.
    • Similarly, when a line transitions from delayed → not delayed, you should print the following message to console or to a logfile: “Line <line_name> is now recovered”.
  • Exposes an endpoint called /status, which takes the name of a particular line as an argument and returns whether or not the line is currently delayed.
  • Exposes an endpoint called /uptime, which also takes the name of a particular line as an argument and returns the fraction of time that it has not been delayed since inception.
    • More concretely, “uptime” is defined as 1 - (total_time_delayed / total_time)

Getting Started

  1. clone this repo locally
  2. cd into project dir with Dockerfile and run... (Note: celery worker is started right away)
docker-compose up --build
  1. In another terminal window, use cli cmd to create tables in postgres db
docker-compose exec api mta_tracker db reset
  1. (Optional) check to see tables have been created in postgres db
docker-compose exec postgres psql -U mta_tracker -d mta_tracker
  1. Ping the status endpoint for a subway line's status
http://localhost:8000/mta_tracker/api/v1.0/subway/lines/status?line=L
  1. Ping the uptime endpoint for a subway line's uptime
http://localhost:8000/mta_tracker/api/v1.0/subway/lines/uptime?line=L
  1. Check logs for messages related to subway line status changes
docker-compose exec api cat logs/line_status.log

Testing

  • Run the following command to test endpoints
docker-compose exec api py.test mta_tracker/tests

Clean up

docker-compose stop
docker-compose rm -f
docker rmi -f $(docker images -qf dangling=true)

Implementation details

  • A celery worker runs the task in mta_tracker/tasks/tasks.py every minute. All details regarding the continuous monitoring of MTA service status can be found in that file, including logging and where data is stored in the db.
  • To understand endpoints, see mta_tracker/resources/subway/lines.py.

Known Issues

  • Celery config should be stored in same file as flask configs...this way instance folder can be used for prod configs.
  • Times are all in UTC

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.