transitmatters / t-performance-dash

TransitMatters performance visualizer for the MBTA
https://dashboard.transitmatters.org/
MIT License
52 stars 17 forks source link

Extract python library #166

Open ianhi opened 2 years ago

ianhi commented 2 years ago

It would be awesome if the generalizable parts of chalicelib could be extracted into a standalone python package to allow people to use it to do whatever analysis they may want.

FWIW I recently wanted to make some plots and ended up sorta rolling my own version of some stuff: https://github.com/ianhi/mbta-analysis#mbta-analysis because I was finding it difficult to extract the current chalicelib to work outside of the connections with s3 and app framework.

Definitely happy to help with this!

austinjpaul commented 2 years ago

Hi Ian,

So glad you're interested in this! Our chalicelib implementation is quite closely tied to our backend infrastructure, so i'm not surprised you ran into issues.

However, our backend functions are accessible via this API: https://dashboard-api2.transitmatters.org/aggregate/traveltimes2?from_stop=22-0-11531&to_stop=22-0-17391&to_stop=22-0-415&start_date=2021-10-01&end_date=2021-11-30

We haven't publicized it anywhere, so it's not documented, but we'd be happy if you (or anyone else) decided to use it. If you inspect the network requests the dashboard is making, you should be able to see what you need.

I love the comparison analysis tool you're working on- if you have any ideas on how we might incorporate something like that into the dashboard, I'm all ears!

ianhi commented 2 years ago

However, our backend functions are accessible via this API:

Oh interesting!

Is there a list of the stops anywhere? 22-0-11531 is a touch opaque.

Also, whats the deal with the v2 api? I kept seeing that it would be discontinued in 2018 which is long past. Also, am I correct that the v3 API would not work for the current transit matters infrastructure?

I love the comparison analysis tool you're working on- if you have any ideas on how we might incorporate something like that into the dashboard, I'm all ears!

I only did it in python because that's where I'm most comfortable, but I think this would be an entirely frontend project. Add a toggle compare and then when it's on add a second row of the route and stop selection.

austinjpaul commented 2 years ago

Yeah, you're not wrong. Stops can be found in our front-end source code. https://github.com/transitmatters/t-performance-dash/blob/main/src/bus_constants/22.json It's basically route-direction-stop_id. Sometimes there are multiple stop ids because of changes to GTFS or bus timepoint reporting, e.g.

As far as MBTA APIs go, I'm pretty sure v2 was replaced by v3. We're using the performance API (historical info is not available from v3). And even then, performanceapi serves only the last 90 days of rail, so all older data and all bus data is processed separately.

It definitely requires some thought as to how the UI should look/work. Probably requires some major changes to how we currently handle things. In the meantime, your tool is looking quite useful for generating these comparison plots albeit offline.