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

fix: CreateTrip request restricted logs fields #215

Merged
merged 1 commit into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 102 additions & 0 deletions datasets/two-trips-bay-area.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,57 @@
"logName": "projects/geod-support-gems/logs/fleetengine.googleapis.com%2Fcreate_trip",
"receiveTimestamp": "2025-02-05T17:02:31.930882511Z"
},
{
"insertId": "8e52d8598e91a29781900b4cd57b0d41.tos",
"jsonPayload": {
"request": {
"trip": {
"pickupPoint": {
"point": {
"longitude": -122.06790357828139,
"latitude": 37.34471314799388
}
},
"dropoffPoint": {
"point": {
"latitude": 37.40531584395862,
"longitude": -122.02161066234112
}
}
}
},
"response": {
"pickupPoint": {
"point": {
"longitude": -122.06790357828139,
"latitude": 37.34471314799388
}
},
"dropoffPoint": {
"point": {
"longitude": -122.02161066234112,
"latitude": 37.40531584395862
}
}
},
"parentInsertId": "8e52d8598e91a29781900b4cd57b0d41",
"@type": "type.googleapis.com/maps.fleetengine.v1.CreateTripRestrictedLog"
},
"resource": {
"type": "fleetengine.googleapis.com/Fleet",
"labels": {
"location": "global",
"resource_container": "projects/geod-support-gems"
}
},
"timestamp": "2025-02-05T17:02:31.483732Z",
"labels": {
"trip_id": "fb1318df-9a2e-4455-9b17-3a7433a681e4",
"restriction": "TOS_RESTRICTED"
},
"logName": "projects/geod-support-gems/logs/fleetengine.googleapis.com%2Fcreate_trip_restricted",
"receiveTimestamp": "2025-02-05T17:02:31.930882511Z"
},
{
"insertId": "0bca336ca8378607a53814a212d744c2",
"jsonPayload": {
Expand Down Expand Up @@ -50063,6 +50114,57 @@
"logName": "projects/geod-support-gems/logs/fleetengine.googleapis.com%2Fcreate_trip",
"receiveTimestamp": "2025-02-05T17:49:42.201753772Z"
},
{
"insertId": "6b39a9a3b3f2216ba46f894b57b48ddf.tos",
"jsonPayload": {
"@type": "type.googleapis.com/maps.fleetengine.v1.CreateTripRestrictedLog",
"parentInsertId": "6b39a9a3b3f2216ba46f894b57b48ddf",
"response": {
"dropoffPoint": {
"point": {
"longitude": -122.09279280155899,
"latitude": 37.42417038875794
}
},
"pickupPoint": {
"point": {
"longitude": -122.02984202653171,
"latitude": 37.40465747488186
}
}
},
"request": {
"trip": {
"pickupPoint": {
"point": {
"longitude": -122.02984202653171,
"latitude": 37.40465747488186
}
},
"dropoffPoint": {
"point": {
"latitude": 37.42417038875794,
"longitude": -122.09279280155899
}
}
}
}
},
"resource": {
"type": "fleetengine.googleapis.com/Fleet",
"labels": {
"resource_container": "projects/geod-support-gems",
"location": "global"
}
},
"timestamp": "2025-02-05T17:49:41.419859Z",
"labels": {
"trip_id": "1906d1b8-cc4e-43a1-a649-43adb926d3e3",
"restriction": "TOS_RESTRICTED"
},
"logName": "projects/geod-support-gems/logs/fleetengine.googleapis.com%2Fcreate_trip_restricted",
"receiveTimestamp": "2025-02-05T17:49:42.201753772Z"
},
{
"insertId": "509ba20fea62f0bafe2ac6fd059dd293",
"jsonPayload": {
Expand Down
2 changes: 0 additions & 2 deletions src/TripLogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ function processRawLogs(rawLogs, solutionType) {
if (currentLocation?.rawlocation) {
lastKnownState.location = currentLocation.rawlocation;
lastKnownState.heading = currentLocation.heading ?? lastKnownState.heading;
log("Updating last known location:", lastKnownState.location);
}

// If Navigation SDK is NO_GUIDANCE, reset the lastKnownState planned route and traffic.
Expand All @@ -173,7 +172,6 @@ function processRawLogs(rawLogs, solutionType) {
} else if (currentRouteSegment) {
lastKnownState.routeSegment = currentRouteSegment;
lastKnownState.routeSegmentTraffic = currentRouteSegmentTraffic;
log("Updating last known route segment");
}

// Apply last known state to a log entry
Expand Down
40 changes: 23 additions & 17 deletions src/localStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import JSZip from "jszip";
import { DEFAULT_API_KEY } from "./constants";
import { log } from "./Utils";

const DB_NAME = "FleetDebuggerDB";
const STORE_NAME = "uploadedData";
Expand All @@ -28,7 +29,7 @@ async function openDB() {
}

export async function uploadFile(file, index) {
console.log(`Uploading file: ${file.name}`);
console.log(`Importing file: ${file.name}`);
let parsedData;
if (file.name.endsWith(".zip")) {
parsedData = await processZipFile(file);
Expand All @@ -41,7 +42,7 @@ export async function uploadFile(file, index) {
parsedData = ensureCorrectFormat(parsedData);

await saveToIndexedDB(parsedData, index);
console.log("File uploaded and saved successfully");
log("File imported and stored successfully");
}

async function processZipFile(file) {
Expand Down Expand Up @@ -73,11 +74,11 @@ async function processJsonFile(file) {
}

export function parseJsonContent(content) {
console.log("Parsing JSON content");
log("Parsing JSON content");
try {
return JSON.parse(content);
} catch (error) {
console.log("Initial JSON parsing failed, attempting to wrap in array");
log("Initial JSON parsing failed, attempting to wrap in array");
try {
return JSON.parse(`[${content}]`);
} catch (innerError) {
Expand All @@ -100,8 +101,8 @@ export function removeEmptyObjects(obj) {
return obj;
}

function isRestrictedLog(log) {
return log.jsonPayload?.["@type"]?.includes("Restricted") || false;
function isRestrictedLog(row) {
return row.jsonPayload?.["@type"]?.includes("Restricted") || false;
}

export function ensureCorrectFormat(data) {
Expand All @@ -114,28 +115,33 @@ export function ensureCorrectFormat(data) {
const logsArray = Array.isArray(data) ? data : [data];

const restrictedLogsMap = new Map();
logsArray.forEach((log) => {
if (isRestrictedLog(log)) {
removeEmptyObjects(log.jsonPayload);
restrictedLogsMap.set(log.jsonPayload.parentInsertId, log);
logsArray.forEach((row) => {
if (isRestrictedLog(row)) {
removeEmptyObjects(row.jsonPayload);
restrictedLogsMap.set(row.jsonPayload.parentInsertId, row);
}
});

// Filter out restricted logs while merging their TOS-restricted attributes into their parent logs.
const mergedLogs = logsArray.filter((log) => {
if (isRestrictedLog(log)) {
const mergedLogs = logsArray.filter((row) => {
if (isRestrictedLog(row)) {
return false;
}
const restrictedLog = restrictedLogsMap.get(log.insertId)?.jsonPayload;
const restrictedLog = restrictedLogsMap.get(row.insertId)?.jsonPayload;
if (restrictedLog) {
["request", "response"].forEach((section) => {
if (restrictedLog[section] && log.jsonPayload[section]) {
if (restrictedLog[section] && row.jsonPayload[section]) {
TOS_RESTRICTED_ATTRIBUTES.forEach((attr) => {
if (restrictedLog[section][attr] !== undefined) {
log.jsonPayload[section][attr] = restrictedLog[section][attr];
row.jsonPayload[section][attr] = restrictedLog[section][attr];
}
if (restrictedLog[section].vehicle?.[attr] !== undefined) {
log.jsonPayload[section].vehicle[attr] = restrictedLog[section].vehicle[attr];
row.jsonPayload[section].vehicle = row.jsonPayload[section].vehicle || {};
row.jsonPayload[section].vehicle[attr] = restrictedLog[section].vehicle[attr];
}
if (restrictedLog[section].trip?.[attr] !== undefined) {
row.jsonPayload[section].trip = row.jsonPayload[section].trip || {};
row.jsonPayload[section].trip[attr] = restrictedLog[section].trip[attr];
}
});
}
Expand All @@ -145,7 +151,7 @@ export function ensureCorrectFormat(data) {
});

// Determine the solution type based on the presence of _delivery_vehicle logs
const isLMFS = mergedLogs.some((log) => log.logName?.includes("_delivery_vehicle"));
const isLMFS = mergedLogs.some((row) => row.logName?.includes("_delivery_vehicle"));
const solutionType = isLMFS ? "LMFS" : "ODRD";
console.log(`Determined solution type: ${solutionType}`);

Expand Down
Loading