Skip to content
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

Post deviated trip notification #260

Merged
merged 44 commits into from
Nov 13, 2024
Merged

Conversation

binh-dam-ibigroup
Copy link
Collaborator

@binh-dam-ibigroup binh-dam-ibigroup commented Oct 9, 2024

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
  • [na] The description lists all applicable issues this PR seeks to resolve
  • [na] The description lists any configuration setting(s) that differ from the default settings
  • All tests and CI builds passing

Description

This PR sets up a job to send post-trip surveys for users who took trips the day before.
The same notification endpoint will be used for both trip monitoring notifications and trip survey notifications post travel.

Blockers:

  • Need a modified or new push notifications endpoint for trip surveys.

@binh-dam-ibigroup binh-dam-ibigroup added the BLOCKED Blocked (waiting on another PR to be merged) label Oct 9, 2024
Copy link
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.

A few comments, but pretty solid so far.

/**
* Get users whose last trip survey notification was at least a week ago.
*/
public static List<OtpUser> getUsersWithNotificationsOverAWeekAgo() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is or should there be a option to opt-out of receiving surveys?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No opt-out of post-travel surveys at the moment.

@@ -84,6 +85,16 @@ public static void main(String[] args) throws IOException, InterruptedException
1,
TimeUnit.MINUTES
);

// Schedule recurring job for post-trip surveys, once every few hours
// TODO: Determine whether this should go in some other process.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the trigger location is fine. Perhaps follow the approach of ConnectedDataManager.scheduleTripHistoryUploadJob(); and have the schduler in the class. It might also be benefical to have the ability to disable this via a config property.

Copy link
Contributor

Choose a reason for hiding this comment

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

@binh-dam-ibigroup thoughts on these two points?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We'd have to rethink where to run periodic tasks.

@br648 br648 assigned binh-dam-ibigroup and unassigned br648 Oct 15, 2024
@binh-dam-ibigroup binh-dam-ibigroup marked this pull request as ready for review October 29, 2024 20:58
@binh-dam-ibigroup binh-dam-ibigroup removed the BLOCKED Blocked (waiting on another PR to be merged) label Oct 29, 2024
Copy link
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 looks good to me. Some minor points to consider, but approving.

@@ -84,6 +85,16 @@ public static void main(String[] args) throws IOException, InterruptedException
1,
TimeUnit.MINUTES
);

// Schedule recurring job for post-trip surveys, once every few hours
// TODO: Determine whether this should go in some other process.
Copy link
Contributor

Choose a reason for hiding this comment

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

@binh-dam-ibigroup thoughts on these two points?

@@ -91,4 +98,40 @@ public void updateNotificationMessage(String routeId, String body) {
busNotificationMessages
);
}

/** The sum of the deviations for all tracking locations that have it. */
public double computeTotalDeviation() {
Copy link
Contributor

Choose a reason for hiding this comment

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

This method has no usages. Remove?

@@ -152,6 +152,8 @@ private static EndTrackingResponse completeJourney(TripTrackingData tripData, bo
trackedJourney.end(isForciblyEnded);
Persistence.trackedJourneys.updateField(trackedJourney.id, TrackedJourney.END_TIME_FIELD_NAME, trackedJourney.endTime);
Persistence.trackedJourneys.updateField(trackedJourney.id, TrackedJourney.END_CONDITION_FIELD_NAME, trackedJourney.endCondition);
trackedJourney.longestConsecutiveDeviatedPoints = trackedJourney.computeLargestConsecutiveDeviations();
Persistence.trackedJourneys.updateField(trackedJourney.id, TrackedJourney.LONGEST_CONSECUTIVE_DEVIATED_POINTS_FIELD_NAME, trackedJourney.longestConsecutiveDeviatedPoints);
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit. Wrap this line.

Locale locale = I18nUtils.getOtpUserLocale(otpUser);
String tripTime = DateTimeUtils.formatShortDate(trip.itinerary.startTime, locale);
String body = String.format(
org.opentripplanner.middleware.i18n.Message.TRIP_SURVEY_NOTIFICATION.get(locale),
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit. Consider a static import.

Comment on lines +23 to +27
location.tripStatus = d == null
? null
: d == 1
? TripStatus.DEVIATED
: TripStatus.ON_SCHEDULE;
Copy link
Contributor

Choose a reason for hiding this comment

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

Brilliant!

@br648 br648 assigned binh-dam-ibigroup and unassigned br648 Oct 30, 2024
Copy link
Contributor

@JymDyerIBI JymDyerIBI left a comment

Choose a reason for hiding this comment

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

👍 This looks good.

@binh-dam-ibigroup
Copy link
Collaborator Author

@br648 and @JymDyerIBI I added a notificationId to the push message, in addition to updates to the survey ids/subdomains.

Copy link
Contributor

@JymDyerIBI JymDyerIBI left a comment

Choose a reason for hiding this comment

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

👍 Changes look good.

@binh-dam-ibigroup binh-dam-ibigroup merged commit 120d920 into dev Nov 13, 2024
2 checks passed
@binh-dam-ibigroup binh-dam-ibigroup deleted the post-deviated-trip-notification branch November 13, 2024 16:25
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.

3 participants