-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Send bus notifications if first leg is bus #264
Open
br648
wants to merge
6
commits into
dev
Choose a base branch
from
feature/OTP-1435-bus-notify-first-leg
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
89d5074
refactor(Notify bus op if first leg is bus leg):
br648 4df263b
refactor(Various changes to allow bus notification to be sent on firs…
br648 f135775
refactor(Fixed merge conflicts):
br648 188f531
Update src/main/java/org/opentripplanner/middleware/triptracker/Manag…
br648 2b3e003
refactor(Update to work with first leg of trip):
br648 820584f
refactor(TravelerPosition.java): Removed redundant constructor
br648 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -136,10 +136,7 @@ public static TripInstruction alignTravelerToTrip( | |
Locale locale = travelerPosition.locale; | ||
|
||
if (isApproachingEndOfLeg(travelerPosition)) { | ||
if (isBusLeg(travelerPosition.nextLeg) && isWithinOperationalNotifyWindow(travelerPosition)) { | ||
BusOperatorActions | ||
.getDefault() | ||
.handleSendNotificationAction(tripStatus, travelerPosition); | ||
if (sendBusNotification(travelerPosition, isStartOfTrip, tripStatus)) { | ||
// Regardless of whether the notification is sent or qualifies, provide a 'wait for bus' instruction. | ||
return new WaitForTransitInstruction(travelerPosition.nextLeg, travelerPosition.currentTime, locale); | ||
} | ||
|
@@ -157,6 +154,32 @@ public static TripInstruction alignTravelerToTrip( | |
return null; | ||
} | ||
|
||
/** | ||
* Send bus notification if the first leg is a bus leg or approaching a bus leg and within the notify window. | ||
*/ | ||
public static boolean sendBusNotification( | ||
TravelerPosition travelerPosition, | ||
boolean isStartOfTrip, | ||
TripStatus tripStatus | ||
) { | ||
if (shouldNotifyBusOperator(travelerPosition, isStartOfTrip)) { | ||
BusOperatorActions | ||
.getDefault() | ||
.handleSendNotificationAction(tripStatus, travelerPosition); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* Given the traveler's position and leg type, check if bus notification should be sent. | ||
*/ | ||
public static boolean shouldNotifyBusOperator(TravelerPosition travelerPosition, boolean isStartOfTrip) { | ||
return (isStartOfTrip) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extract a variable for the leg to pass to |
||
? isBusLeg(travelerPosition.expectedLeg) && isWithinOperationalNotifyWindow(travelerPosition.currentTime, travelerPosition.expectedLeg) | ||
: isBusLeg(travelerPosition.nextLeg) && isWithinOperationalNotifyWindow(travelerPosition); | ||
} | ||
|
||
/** | ||
* Align the traveler's position to the nearest transit stop or destination. | ||
*/ | ||
|
@@ -218,15 +241,19 @@ public static boolean isAtEndOfLeg(TravelerPosition travelerPosition) { | |
return getDistanceToEndOfLeg(travelerPosition) <= TRIP_INSTRUCTION_IMMEDIATE_RADIUS; | ||
} | ||
|
||
public static boolean isWithinOperationalNotifyWindow(TravelerPosition travelerPosition) { | ||
return isWithinOperationalNotifyWindow(travelerPosition.currentTime, travelerPosition.nextLeg); | ||
} | ||
|
||
/** | ||
* Make sure the traveler is on schedule or ahead of schedule (but not too far) to be within an operational window | ||
* for the bus service. | ||
*/ | ||
public static boolean isWithinOperationalNotifyWindow(TravelerPosition travelerPosition) { | ||
var busDepartureTime = getBusDepartureTime(travelerPosition.nextLeg); | ||
public static boolean isWithinOperationalNotifyWindow(Instant currentTime, Leg busLeg) { | ||
var busDepartureTime = getBusDepartureTime(busLeg); | ||
return | ||
(travelerPosition.currentTime.equals(busDepartureTime) || travelerPosition.currentTime.isBefore(busDepartureTime)) && | ||
ACCEPTABLE_AHEAD_OF_SCHEDULE_IN_MINUTES >= getMinutesAheadOfDeparture(travelerPosition.currentTime, busDepartureTime); | ||
(currentTime.equals(busDepartureTime) || currentTime.isBefore(busDepartureTime)) && | ||
ACCEPTABLE_AHEAD_OF_SCHEDULE_IN_MINUTES >= getMinutesAheadOfDeparture(currentTime, busDepartureTime); | ||
} | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is at the start of a trip where the first leg is transit, there is no approaching the end of the leg.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@binh-dam-ibigroup If possible can you provide a trip which starts with a transit leg? I'm going to edit an existing trip (walk-to-bus-transition.json) to test with, but would prefer a real-world exampl
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@binh-dam-ibigroup this has grown a bit from my initial take on it! I think this covers the what is needed.