Add Scheduled bus time arrivals #14

Open
opened 2026-09-27 05:19:42 +00:00 by tentype · 0 comments
Member

Objective

Sometimes a bus is scheduled at a time according to the PRT's timetable, but there is no live GPS tracking for it, so we don't get it from the API. We want to fill those gaps with timetable trips from PRT's General Transit Feed Specification (GTFS) feed, marked with the gray "Scheduled" badge.

Here's the design we are using. The font is grayed out, with a "Scheduled" badge next to the bus line. Note that we've already implemented this in BusTimeEntry.svelte.
image

Suggested Approach

Knowledge Prereqs

Become familiar with these resources:

  • BusTime v3 API Guide - describes the fields of the response we get from the API. In particular, we use the Predictions API (section 3.8, page 25). Check out backend/src/lib.rs in this project to see how we parse this data.
  • General Transit Feed Specification - Every public transit agency publishes their scheduled operations, routes, stops, etc in a standardized dataset called the GTFS. Read these docs to familiarize yourself with what it contains and how we might be able to use its data.
  • PRT GTFS dataset - This is the one that the Pittsburgh Regional Transit uses (100 MB). It is updated quarterly, about 2 weeks before each schedule change

Data Exploration

Investigate what is the best way to get scheduled arrivals such that it is in a machine-readable format and it is easy to resync when it changes. The GFTS dataset seems like the best source of scheduled times so far, but do some more research and see if there's anything else that might be useful/more convenient.

If we are using the GFTS dataset, we probably don't want to store a 100 MB file in the repo or our database. Maybe we want to request the zip from the website and keep only the important parts of it at compile-time? Which fields should we keep? What are some other ways to use this data? Ask yourselves these questions and consider the benefits/drawbacks if we decide to go a certain way.

Before continuing, please explain your findings and what you suggest to do in the bus sign discord channel, so you can get some feedback :D

Backend

You'll need to edit the backend so that it efficiently reads and parses the data. Maybe make a new file for this if it's a lot of code, and look online for any crates (packages) that might be helpful. For example, use the csv crate if we're storing the data as a csv, etc.

Next, update the backend so it responds to API requests with any upcoming scheduled arrival. This is done in lib.rs. You'll probably want to edit the BusArrival struct so that it has the scheduled: bool field, along with some other changes.

Make sure that we prioritize live bus predictions over scheduled ones. We shouldn't have both at the same time (perhaps filter the vector of BusArrivals to do this).

Frontend

You won't need to do a lot here, since we've already created the scheduled style, but you'll need to make some small edits so that this works with the new backend API. Update the RouteInformation.arrivals type in both App.svelte and BusList.svelte, and use the BusTimeEntry component with scheduled=true to display a scheduled bus arrival.

Scheduled rows should be sorted below live ones that are in the same minute (edit the sortByArrival function in App.svelte if it doesn't do this).

Note to contributors

Take your time with this. While AI can probably one-shot the code, PLEASE try to do it by yourself for the learning experience. Try to use AI to explain things, not write code for you.

This video tutorial is lengthy, but it assumes no prior Rust experience. The first 20 minutes are dedicated purely to giving an overview Rust. The remaining parts of the video go over Axum, the web app framework we use.

You can also find resources linked on the CMU course 98-008: Intro to Rust Lang! Click on the materials dropdown of each lecture in the Schedules page (shameless plug)

The frontend should be a bit easier to pick up, but if you'd like, check out the official Svelte tutorial!

## Objective Sometimes a bus is scheduled at a time according to the PRT's timetable, but there is no live GPS tracking for it, so we don't get it from the API. We want to fill those gaps with timetable trips from PRT's General Transit Feed Specification (GTFS) feed, marked with the gray "Scheduled" badge. Here's the design we are using. The font is grayed out, with a "Scheduled" badge next to the bus line. Note that we've already implemented this in `BusTimeEntry.svelte`. ![image](/attachments/712e5b65-dc74-4938-8e1f-ce88296f9e41) ## Suggested Approach ### Knowledge Prereqs Become familiar with these resources: - [BusTime v3 API Guide](http://realtime.portauthority.org/bustime/apidoc/docs/DeveloperAPIGuide3_0.pdf) - describes the fields of the response we get from the API. In particular, we use the Predictions API (section 3.8, page 25). Check out `backend/src/lib.rs` in this project to see how we parse this data. - [General Transit Feed Specification](https://gtfs.org/documentation/schedule/reference/) - Every public transit agency publishes their scheduled operations, routes, stops, etc in a standardized dataset called the GTFS. Read these docs to familiarize yourself with what it contains and how we might be able to use its data. - [PRT GTFS dataset](https://www.rideprt.org/developerresources/GTFS.zip) - This is the one that the Pittsburgh Regional Transit uses (100 MB). It is updated quarterly, about 2 weeks before each schedule change ### Data Exploration Investigate what is the best way to get scheduled arrivals such that it is in a machine-readable format and it is easy to resync when it changes. The GFTS dataset seems like the best source of scheduled times so far, but do some more research and see if there's anything else that might be useful/more convenient. If we are using the GFTS dataset, we probably don't want to store a 100 MB file in the repo or our database. Maybe we want to request the zip from the website and keep only the important parts of it at compile-time? Which fields should we keep? What are some other ways to use this data? Ask yourselves these questions and consider the benefits/drawbacks if we decide to go a certain way. Before continuing, please explain your findings and what you suggest to do in the bus sign discord channel, so you can get some feedback :D ### Backend You'll need to edit the backend so that it efficiently reads and parses the data. Maybe make a new file for this if it's a lot of code, and [look online](https://crates.io/) for any crates (packages) that might be helpful. For example, use the [csv crate](https://crates.io/crates/csv) if we're storing the data as a csv, etc. Next, update the backend so it responds to API requests with any upcoming scheduled arrival. This is done in `lib.rs`. You'll probably want to edit the `BusArrival` struct so that it has the `scheduled: bool` field, along with some other changes. Make sure that we prioritize live bus predictions over scheduled ones. We shouldn't have both at the same time (perhaps filter the vector of `BusArrivals` to do this). ### Frontend You won't need to do a lot here, since we've already created the scheduled style, but you'll need to make some small edits so that this works with the new backend API. Update the `RouteInformation.arrivals` type in both `App.svelte` and `BusList.svelte`, and use the `BusTimeEntry` component with `scheduled=true` to display a scheduled bus arrival. Scheduled rows should be sorted below live ones that are in the same minute (edit the `sortByArrival` function in `App.svelte` if it doesn't do this). ## Note to contributors Take your time with this. While AI can probably one-shot the code, PLEASE try to do it by yourself for the learning experience. Try to use AI to explain things, not write code for you. [This video tutorial](https://www.youtube.com/watch?v=iPNEhKMIqNg) is lengthy, but it assumes no prior Rust experience. The first 20 minutes are dedicated purely to giving an overview Rust. The remaining parts of the video go over `Axum`, the web app framework we use. You can also find resources linked on the CMU course [98-008: Intro to Rust Lang](https://stuco.rs/)! Click on the materials dropdown of each lecture in the Schedules page (shameless plug) The frontend should be a bit easier to pick up, but if you'd like, check out the [official Svelte tutorial](https://svelte.dev/tutorial)!
142 KiB
echiu2 self-assigned this 2026-10-03 21:02:19 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
ScottyLabs/bus-sign#14
No description provided.