From 1985f2f26f80a716defdfd08d6b5431607fe35b5 Mon Sep 17 00:00:00 2001 From: regeter <2320305+regeter@users.noreply.github.com> Date: Fri, 1 May 2026 17:24:12 -0700 Subject: [PATCH 1/2] feat: Make trips more robust for errors and API calls. --- src/TripLogs.js | 48 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 11 deletions(-) diff --git a/src/TripLogs.js b/src/TripLogs.js index 0ac6453..ed4bd45 100644 --- a/src/TripLogs.js +++ b/src/TripLogs.js @@ -132,12 +132,33 @@ function processRawLogs(rawLogs, solutionType) { let sortedLogs = isReversed ? _.reverse(origLogs) : origLogs; let newLogs = []; + const tripBoundaries = new Map(); // tripId -> { minTime, maxTime } + + // First pass to find boundaries for each trip + for (const origLog of sortedLogs) { + const apiCall = processApiCall(origLog); + if (apiCall && apiCall.response) { + const currentTrips = apiCall.response.currenttrips; + if (currentTrips && Array.isArray(currentTrips)) { + const timestampMS = new Date(origLog.timestamp || origLog.servertime).getTime(); + for (const tripId of currentTrips) { + if (!tripBoundaries.has(tripId)) { + tripBoundaries.set(tripId, { minTime: timestampMS, maxTime: timestampMS }); + } else { + const bounds = tripBoundaries.get(tripId); + bounds.minTime = Math.min(bounds.minTime, timestampMS); + bounds.maxTime = Math.max(bounds.maxTime, timestampMS); + } + } + } + } + } + const lastKnownState = { location: null, heading: 0, routeSegment: null, routeSegmentTraffic: null, - currentTrips: [], responseLocation: null, responseHeading: 0, }; @@ -157,7 +178,6 @@ function processRawLogs(rawLogs, solutionType) { newLog.request = apiCall.request; newLog.response = apiCall.response; newLog.error = apiCall.error; - const hasApiError = !!newLog.error || (origLog.jsonpayload && origLog.jsonpayload.errorresponse); adjustFieldFormats(solutionType, newLog); @@ -242,13 +262,16 @@ function processRawLogs(rawLogs, solutionType) { } } - // Keep the same current trips if we had an API error - if (hasApiError && lastKnownState.currentTrips.length > 0) { - log(`Preserving current trips due to API error for log at ${newLog.timestamp}`); - if (!newLog.response) newLog.response = {}; - newLog.response.currenttrips = [...lastKnownState.currentTrips]; - } else if (_.get(newLog, "response.currenttrips")) { - lastKnownState.currentTrips = [...newLog.response.currenttrips]; + const newCurrentTrips = _.get(newLog, "response.currenttrips"); + + if (!newCurrentTrips || newCurrentTrips.length === 0) { + for (const [tripId, bounds] of tripBoundaries.entries()) { + if (newLog.timestampMS >= bounds.minTime && newLog.timestampMS <= bounds.maxTime) { + log(`Backfilling trip ${tripId} for log at ${newLog.timestamp}`); + newLog.lastlocationResponse.currenttrips = [tripId]; + break; + } + } } // Sort currentTrips array since sometimes it could contain multiple trip ids in random order @@ -326,7 +349,7 @@ class TripLogs { } // Check trip ID in vehicle rows - const currentTrips = _.get(le, "response.currenttrips"); + const currentTrips = _.get(le, "response.currenttrips") || _.get(le, "lastlocationResponse.currenttrips"); if (currentTrips && Array.isArray(currentTrips)) { return currentTrips.some((id) => id.includes(trimmedFilter)); } @@ -506,7 +529,10 @@ class TripLogs { const stopsLeft = _.get(logEntry, "response.remainingvehiclejourneysegments"); return stopsLeft && "Stops Left " + stopsLeft.length; } else { - const currentTrips = _.get(logEntry, "response.currenttrips"); + let currentTrips = _.get(logEntry, "response.currenttrips"); + if (!currentTrips || currentTrips.length === 0) { + currentTrips = _.get(logEntry, "lastlocationResponse.currenttrips"); + } if (currentTrips && Array.isArray(currentTrips) && currentTrips.length > 0) { return currentTrips[0]; } From 5542311b98a72004b67dfe06f946e029b0311e73 Mon Sep 17 00:00:00 2001 From: regeter <2320305+regeter@users.noreply.github.com> Date: Fri, 1 May 2026 17:28:05 -0700 Subject: [PATCH 2/2] Change trip color from light blue to red. Red is already used for the slowest traffic but overall still better than the blue which matches river/water. --- src/Trip.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Trip.js b/src/Trip.js index 5840609..8e77814 100644 --- a/src/Trip.js +++ b/src/Trip.js @@ -118,7 +118,6 @@ class Trip { */ export function getColor(tripIdx) { const colors = [ - "#0dcaf0", // Cyan "#97cc04", // Lime Green "#198754", // Green "#6A0DAD", // Purple @@ -127,6 +126,7 @@ export function getColor(tripIdx) { "#d63384", // Magenta "#f45d01", // Orange "#fdc500", // Gold + "#e63946", // Vibrant Red ]; return colors[tripIdx % colors.length]; }