Adventures in Data: Tackling the TEC Network #2
Last time, we mapped out real-time bus positions. Now, let's add bus stops and routes to our digital canvas. It's all about layering up the data to get a clearer picture. Let's dive in!
Parsing GTFS
Dealing with Files
- GTFS, Unzipped: GTFS packs public transportation data into a zip with several CSV files. Key players include
stops.txt
, routes.txt
, trips.txt
, and stop_times.txt
.
- The Lazy Way: Parsing these isn't rocket science, but hey, why reinvent the wheel? Found a nifty Rust crate that does the heavy lifting: gtfs-structures.
Sending Data
Backend Endpoints
- New Endpoints Alert: Added
/theorical
, /shape
, and /info
on the backend. They're your go-to for theoretical data, line shapes, and line info.
Client Side
Handling Data
- Storing and Syncing: We pull data from the backend, stashing it in global state. A websocket keeps us in sync with real-time data.
- Interactive Lines: Click a bus, and voilĂ ! Stops and shapes for that line pop up.
Deltas and Realities
- Calculating Deltas: With all line data at hand, we're set to calculate deltas between theory and reality. It's a game of matching the closest stops and factoring in distance and speed. Result? Pretty darn close to real life!
The New View
- Map Upgrade: Now, our map not only shows real-time buses but also lines, stops, and the real-vs-theory delta. We're getting there!
Dedicated Map
Going the Extra Mile
- Why OSM?: Decided to roll out a dedicated OpenStreetMap (OSM). Overkill? Maybe. But it's cool, and who doesn't like a bit of map customization?
- The Setup Odyssey: It was a journey with old tools and scarce docs. Ended up using Geofabrik for data, osm2pgsql for importing, and a mix of mapnik, apache2, mod_tile, and renderd for the server setup.
- Worth It?: Absolutely not necessary, but totally cool. Plus, I've sunk too much time into this to back out now!
Where Are We Now?
Recap
- Blog Mission: Keep fetching and displaying data.
- Achievements Unlocked: We've got stops, shapes, and delta data on the map. Plus, our very own OSM setup. It's a work in progress, but the foundation is solid.
Take me to the 3rd part!
Back to the index