Skip to content

Commit

Permalink
feat: Also add createTrip and updateTrip to trip related logs.
Browse files Browse the repository at this point in the history
  • Loading branch information
regeter committed Feb 18, 2025
1 parent 680542e commit 666c359
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions src/TripLogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -446,17 +446,38 @@ class TripLogs {
let tripIdx = 0;
let nonTripIdx = 0;
let lastTripStatus = "no status";
// assumes logs are already sorted
// also assumes out-of-order updates can't happen. Unclear
// if this is a good assumption, but it might be worth it to call out
// places where it happens (since that might actually be a client bug).

// First, create a map of trip IDs to their logs
const tripLogs = new Map();

// Collect all trip-related logs
_.forEach(this.rawLogs, (le) => {
if (le["@type"] === "createTrip" || le["@type"] === "updateTrip") {
const tripId = le.request?.tripid || _.get(le, "request.trip.name");
if (tripId) {
if (!tripLogs.has(tripId)) {
tripLogs.set(tripId, []);
}
tripLogs.get(tripId).push(le);
}
}
});

// Process vehicle updates and create trip segments
_.forEach(this.rawLogs, (le) => {
if (le["@type"] === "updateVehicle" || le["@type"] === "updateDeliveryVehicle") {
const newTripId = this.getSegmentID(le);
if (newTripId !== curTripId) {
curTripId = newTripId;
const tripName = newTripId ? newTripId : "non-trip-segment-" + nonTripIdx;
curTripData = new Trip(tripIdx, tripName, new Date(le.timestamp));

// If this is an actual trip (not a non-trip-segment), add its logs
if (tripLogs.has(newTripId)) {
curTripData.logs = tripLogs.get(newTripId);
log(`Added ${curTripData.logs.length} logs to trip ${newTripId}`);
}

this.trips.push(curTripData);
this.trip_ids.push(curTripData.tripName);

Expand All @@ -479,7 +500,6 @@ class TripLogs {
}
}
const tripStatus = _.get(le, "response.tripstatus");
// if the logs had a trip status, and it changed update
if (tripStatus && tripStatus !== lastTripStatus) {
this.tripStatusChanges.push({
newStatus: tripStatus,
Expand Down

0 comments on commit 666c359

Please sign in to comment.