Coder Social home page Coder Social logo

transitmatters / new-train-tracker Goto Github PK

View Code? Open in Web Editor NEW
29.0 4.0 11.0 1.41 MB

Tracking the MBTA's new Orange, Red, and Green trains

Home Page: http://traintracker.transitmatters.org/

License: MIT License

Python 22.81% HTML 0.94% CSS 6.72% JavaScript 4.21% TypeScript 63.02% Shell 2.29%

new-train-tracker's Introduction

New Train Tracker

lint deploy

Developed by TransitMatters Labs

Shows new MBTA Orange, Red, and Green Line trains as they come into service.

Install & Run

Dependencies:

  • node 20.x (with npm 10.x)
  • python 3.12
  • poetry
    • Ensure poetry is using the correct Python version by running poetry env use <your python3.12 binary>

Run:

To use an API key, put it in server/secrets.py or as an environment variable MBTA_V3_API_KEY

Linting

To lint frontend and backend code, run $ npm run lint in the root directory

To lint just frontend code, run $ npm run lint-frontend

To lint just backend code, run $ npm run lint-backend

Server Deployment

Additional requirements:

  • nginx

Nginx serves as a reverse-proxy for the app running on localhost:5001. The Flask app is run under gunicorn and controlled by systemd, which will restart after failure or reboot automatically.

AWS Deployment

  1. Make sure AWS CLI is set up and working — i.e. aws cloudformation describe-stacks | wc -l should work
  2. Make sure these environment variables are set up in your shell (ask a Labs member for values if needed):
  • TM_NTT_CERT_ARN (for production)
  • TM_LABS_WILDCARD_CERT_ARN (for beta)
  1. A key named transitmatters-ntt needs to be available in your AWS account and copied to ~/.ssh/transitmatters-ntt.pem.
  2. You will also need to create an ec2-secrets.py file in the devops/ directory.
  3. Run cd devops && ./deploy.sh (add -p for production) to deploy.
  4. You're all set! Visit:

Other Deployments

This project generally fits the "Flask app" mold. Contact us if you need help: [email protected]

Support TransitMatters

If you've found this app helpful or interesting, please consider donating to TransitMatters to help support our mission to provide data-driven advocacy for a more reliable, sustainable, and equitable transit system in Metropolitan Boston.

new-train-tracker's People

Contributors

androotubelli avatar austinjpaul avatar colbychaskell avatar danielreynoldsma avatar dependabot[bot] avatar devinmatte avatar idreyn avatar mathcolo avatar nathan-weinberg avatar patrickcleary avatar purcellif17 avatar rudiejd avatar skyqrose avatar thiteixeira avatar z0glen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

new-train-tracker's Issues

Update Python to 3.12

Because we're running on EC2 we should be able to update to Python 3.11 or 3.12 today

Every other product at TM is using Python 3.10 now, we should at least get NTT in-line. Soon we'll be on 3.11 and 3.12

Create Ansible playbook specifically for fresh deployments

The current deploy-on-lightsail.yml Ansible playbook can only be used to update existing deployments of the Train Tracker. It wouldn't be a bad idea to have a separate playbook designed for performing fresh deployments of the app.

Extend Green Line visualization/tracking to account for GLX

GLX is currently planned to open in December for the Union Branch and May for the Medford Branch. We need to extend the GL code to take into account these new stations. @idreyn If you have any details as to what exactly needs to be done feel free to drop them here for whoever ends up picking this up.

fix silverline logging

The changes to tally the new vehicles seen don't account for the logging of the silverline that's happening.
Separating the processing from the tallying would be ideal.

Add timestamps to log files

The cron task (cd /home/ubuntu/new-train-tracker && /home/ubuntu/.local/bin/pipenv run python3 -m server.history.update_history_db >> /home/ubuntu/new-train-database-updates.log) and the mbta_api call (new-train-tracker/server/mbta_api.py: print(f"Writing problematic API response to {log_path}")) both generate log files that don't have timestamps. It would be great to add timestamps to these for diagnosing issues.

Add analytics

We use Google Analytics for the data dashboard, so let's hook that up here too.

Make the `apple-touch-icon` work for iOS

We have an apple-touch-icon.png file in the repo which is supposed to be used when the NTT is added to the Home Screen. This...isn't working, and I can't figure out why. There's probably something I'm not doing correctly with the image itself or the link tag in template.html.

Add ability to filter by sub-line (GL B/C/D/E & RL Ashmont/Braintree)

This would be very helpful for when there's several trains bunched up in one rendered location, and you have to keep selecting the location to scroll through the trains, and it doesn't always scroll through all of them.

Alternatively/simultaneously, it would be nice to color code the sub-lines and expand a bunch of overlapping trains when one is selected.

Database Overhaul

Should include list of npm commands and things to look out for if setting up a new instance of the project, maybe some troubleshooting tips...

  • At the very least modify the README to list a running Postgres server as a dependency
  • Also add some links to helpful, tested OS-specific instructions on how to set one up
  • For our own purposes try to install this from scratch on an EC2/Lightsail Ubuntu instance and write down or script the steps we needed to take
  • Factor any OS-agnostic steps we missed into create_history_db.py
  • (Optional) Replace or supplement secrets.py with environment variables?
  • #84

Show how busy each train is

The v3 api provides info about how busy the trains are. On the new orange and red line trains the data is given per car. We should show that on the map for the curious folks

Display average travel time between stations

It could be cool to be able to click on two stations and see the average travel time between them, especially if you're trying to schedule when you should leave to catch one of the new trains

Add labels for GL branch stations

Mobile viewports are too small to fit full station names but we could:

  • Make them teeny tiny
  • Abbreviate them
  • Make them appear when the station dot is tapped

Make it easier to deploy local changes to Beta

Currently, deploy-playbook.yml is hardcoded to deploy whatever is on the org main branch - this is good for CD, but we should extend the playbook and deploy.sh to make it easier to deploy local changes without having to manually edit the playbook

Better API key management

[ ] Specify API key an with environment variable
[ ] Via the file secrets.py
[ ] Make the API calls not fail if an API key isn't present via env var or secrets.py

Save state on refresh

NTT page refreshes should send you back to the same line/mode you were already viewing. No need for URL state though, I don't think...

RL last seen not updating properly

I wonder if this is due to Ashmont shuttling? We received this to labs@.

Hi,
Earlier today (Friday, 20-October-2023) the redline new trains tracker said there were two new trains on the line. Now, when I look, (after 5:30 PM same day), it says there are no new trains, and that a new red line train was last seen 6 days ago.

That looks like a bug....

Thanks

OL strip map line becomes translucent on NEW -> ALL transition

To reproduce:

  • Load the tracker
  • Move to OL
  • Switch from NEW to ALL trains

The strip map line will go translucent. This is a visual cue we use for the non-selected branch of GL and RL and should never happen on the OL.

Screen.Recording.2022-09-21.at.9.58.20.PM.mov

secrets.py should not be overwritten point blank

@z0glen made a delightful change to permit NTT to run without an adjacent PostgreSQL server. That included a secrets.py modification, which the CD job overwrote on merge with the instance copy. I added Zach's change to said copy, but ideally the key would be patched in (or read from env? or elsewhere?)

Backup last_seen.json

The NTT working directory now contains last_seen.json for the "last seen" times. We should back that up automatically, in case something happens to the server.

Add codepaths to allow running the tracker without a database

Since we're considering using the Data Dashboard infrastructure for the history data, we can eventually wind down this repo's dependency on a locally-hosted Postgres database. As a first step, let's make our Postgres dependency opt-in — so that the app will build and run without a database available, and provide dummy/fallback data in its absence.

Add the Mattapan line

A user wrote in to point out that the ancient PCC cars are being retrofitted with new components, which may be of interest to the same folks who are interested in hunting down new trains. New or not, this will be a good addition as fleet delivery wears on and the NTT becomes just the "train tracker" with Blue, Silver, etc.

We could possibly tack this onto the bottom of the Ashmont strip map, though that's technically harder (and maybe not as appropriate for the use case) than just putting it into its own tab.

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.