Skip to content

Schedule-based thresholds for array size checks. - #33

Open
lemald wants to merge 20 commits into
mainfrom
lem-schedule-based-thresholds
Open

Schedule-based thresholds for array size checks.#33
lemald wants to merge 20 commits into
mainfrom
lem-schedule-based-thresholds

Conversation

@lemald

@lemald lemald commented Aug 26, 2026

Copy link
Copy Markdown
Member

Asana ticket: 🔮 Build out a way to measure RTR uptime

Note that I used Copilot for the initial implementation, though I read all the code over and modified it in places to be more idiomatic and readable.

To make our alerting and reliability metrics more accurate, we want to be able to dynamically assess our realtime data relative to the level of scheduled service, rather than relative to absolute thresholds. My changes to the README explain the new feature and how to configure it in more detail.

Some notes on how I came up with 0.05 as the multiplier: given that we currently have a shutdown of part of the Orange Line going on, I opted to look at the schedule data there. Grabbing all schedules for route Orange and filtering out shuttle bus stop times gave me the following:

❯ curl "https://api-v3.mbta.com/schedules?filter\[route\]=Orange&filter\[date\]=2026-08-26&filter\[min_time\]=11:00&filter\[max_time\]=13:00" | jq ".data[].relationships.route.data.id" | grep Orange | wc -l
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  427k  100  427k    0     0   854k      0 --:--:-- --:--:-- --:--:--  855k
     388

Meanwhile, querying the /predictions endpoint for route Orange returned a total of 39 predictions. I wanted to give about a factor of 2 for headroom, and 388 is almost exactly 10 times 39, so 1/10 divided by 2 for the headroom gives a ratio of 0.05. For a non-diversion example I looked at the current situation with light rail: during a representative 2-hour window there were 3000 stop times in the schedule, for a threshold of 150 predictions. In reality, we were producing 1078 predictions, showing that in some situations this is actually a very conservative threshold.

@lemald
lemald marked this pull request as ready for review August 26, 2026 20:02
@lemald
lemald requested review from a team, huangh and npatel-mbta and removed request for a team and huangh August 26, 2026 20:02

@npatel-mbta npatel-mbta left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I aslo used co-pilot to review the code, and the few minor issues it raised, I reviewed and think they don't really apply.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants