Skip to content

Trip Monitoring Docs#374

Merged
binh-dam-ibigroup merged 42 commits intodevfrom
monitor-trip-docs
Apr 27, 2026
Merged

Trip Monitoring Docs#374
binh-dam-ibigroup merged 42 commits intodevfrom
monitor-trip-docs

Conversation

@binh-dam-ibigroup
Copy link
Copy Markdown
Collaborator

@binh-dam-ibigroup binh-dam-ibigroup commented Apr 13, 2026

Checklist

  • Appropriate branch selected (all PRs must first be merged to dev before they can be merged to master)
  • Any modified or new methods or classes have helpful JavaDoc and code is thoroughly commented =
  • The description lists all applicable issues this PR seeks to resolve
  • The description lists any configuration setting(s) that differ from the default settings
  • All tests and CI builds passing

Description

This PR adds a new markdown file that provides an overview of trip monitoring.

Copy link
Copy Markdown
Contributor

@br648 br648 left a comment

Choose a reason for hiding this comment

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

This is good! A couple of comments to consider.

Comment thread docs/trip-monitoring.md Outdated
- **Padding/slack before, between, and after transit legs** (boarding, transfer, alighting slack, respectively)<br>
These constants ensure a traveler has enough time to exit a vehicle and go to the boarding location
of the next transit vehicle (see diagram below). OTP-middleware can guess the boarding and alighting slacks
from the original itinerary, however if an overall transfer slack is configured in OTP, it must also be configured in
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Where under OTP should this be checked and is the parameter the same name? Is it possible to get this value from the response to avoid a mismatch in values?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I added clarification in 658e206, thank you. The transfer slack is tough because we don't know whether an itinerary with transfers has the shortest allowable transfers or not.

Comment thread docs/trip-monitoring.md Outdated

#### Plan Method

If the leg id method fails, a `plan` GraphQL query is sent to OTP to replan the entire trip for the target date, using
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It might be worth adding why the leg id method might fail.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes, added in 6f5e651

@br648 br648 assigned binh-dam-ibigroup and unassigned br648 Apr 14, 2026
Copy link
Copy Markdown

@alec-georgoff alec-georgoff left a comment

Choose a reason for hiding this comment

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

One nit! This is awesome, thanks for putting the time into this :D

Comment thread docs/trip-monitoring.md Outdated

The **target date** (`MonitoredTrip.journeyState.targetDate`) is the date a trip is supposed to take place.
For one-time trips, the target date is simply the date of the trip. For recurring trips, the target date is the next
occurrence of the trip, based on the days the trip is being monitored. Note that holidays are not supported yet.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit: I might break out the note about holidays into a separate block so it's more noticeable if someone is skimming? Maybe something like this:

Note

Holidays are not yet supported for trip monitoring

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Didn't see that feature in the GH docs, very cool! (dd4ac78)

Add notes sections
Fix notes sections
Copy link
Copy Markdown
Contributor

@josh-willis-arcadis josh-willis-arcadis left a comment

Choose a reason for hiding this comment

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

Looks good as is. Some comments about adding more information to the current class diagrams and potential for more class diagrams. This would help clearly show the relationship between all the classes and their methods. I think these would be nice to haves.

Comment thread docs/trip-monitoring.md
Comment thread docs/trip-monitoring.md
---
title: Trip Monitoring Classes and Relevant Fields/Methods
---
classDiagram
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A nice addition to this class diagram could the specific methods in each class that are relevant to the trip monitoring process.

Comment thread docs/trip-monitoring.md
[`MonitorAllTripsJob`](../src/main/java/org/opentripplanner/middleware/tripmonitor/jobs/MonitorAllTripsJob.java)
that runs every minute in the background. The job splits the monitoring of all qualifying trips between threads
as determined by the number of CPUs on the instance. Each thread runs a
[`TripAnalyzer`](../src/main/java/org/opentripplanner/middleware/tripmonitor/jobs/TripAnalyzer.java)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

would love to see class diagrams for these at some point!

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I will delay implementing this suggestion. Right now, the flow diagram below better explains how the analyzers are set up.

Comment thread docs/trip-monitoring.md Outdated
---
flowchart LR
job["⏱️ MonitorAllTripsJob"]
analyzer1[TripAnalyzer<br>CheckMonitoredTrip]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

add CheckMonitoredTrip.run() to show which method in the class diagram was called.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Updated in da5dbc0

Comment thread docs/trip-monitoring.md Outdated
| `PLAN_QUERY_RESOURCE_URI` | Optional location of a custom GraphQL template for the OTP `plan` query. |
| `MAXIMUM_MONITORED_TRIP_ITINERARY_CHECKS` | The maximum number of attempts to obtain a matching itinerary (default 3). Used with `MonitoredTrip.attemptsToGetMatchingItinerary`. |

The [`ItineraryExistence`](../src/main/java/org/opentripplanner/middleware/models/ItineraryExistence.java) class
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

these are methods that could be added to the class diagram.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Added in fe2b038

Comment thread docs/trip-monitoring.md

#### Leg ID Method

The [`ItineraryChecker`](../src/main/java/org/opentripplanner/middleware/itinerarymatching/ItineraryChecker.java) class
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Would love to see Itinerary related classes in a class diagram. These are essential classes in this process.

Comment thread docs/trip-monitoring.md Outdated
("Unable to monitor trip") is sent.

A provision exists in the `CheckMonitorTrip` logic, so that a notification that a trip is no longer possible is sent
if no matching itinerary has been found for over a week. (This is not currently implemented.)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

could be a good use of a note.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Updated in da5dbc0

Comment thread docs/trip-monitoring.md
Once an occurrence of a trip completes, the journey state is "reset",
so that notifications can be sent again for the next trip occurrence.

A `JourneyState` consists of the following attributes:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

good place for another class diagram.

Comment thread docs/trip-monitoring.md Outdated
Upon saving a trip (POST), if the trip is recurring, OTP-middleware will perform an additional existence check.
If the check does not succeed, the request is rejected, and the trip is not saved or monitored. If the check passes,
the result is saved in `MonitoredTrip.itineraryExistence`.
(The check is not performed when saving one-time trips.)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

another good use of a note.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Updated in da5dbc0

Comment thread docs/trip-monitoring.md Outdated

| Notification Type | Description |
| --- | --- |
| `INITIAL_REMINDER` | Advance trip reminder ("Reminder for My Trip at 8:30"). If `MonitoredTrip.notifyAtLeadingInterval` is true, sent once at the lead monitoring time on the day a given trip occurs. |
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this is a good method to include in class diagram.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Added notification methods in 193e507.

@binh-dam-ibigroup binh-dam-ibigroup merged commit 5aba8ad into dev Apr 27, 2026
2 of 4 checks passed
@binh-dam-ibigroup binh-dam-ibigroup deleted the monitor-trip-docs branch April 27, 2026 18:42
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.

4 participants