forked from googlemaps/fleet-debugger
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add LMFS task visualizations (googlemaps#132)
* feat: add LMFS task visualizations Shows planned location vs actual location for all tasks. Time-sider controls only the status of the task, not it's presence on the map. * fix: add basic tests for LMFS tasks Created new test and updated the lmfs demo data to a dataset I recently generated
- Loading branch information
Showing
12 changed files
with
395 additions
and
21 deletions.
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
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# LMFS Tasks | ||
|
||
Displays all tasks assigned to the vehicle. Time slider allows replaying task state/outcome | ||
changes. | ||
|
||
The red or green arrows indicate the delta between the planned location and outcome location | ||
for the task. | ||
|
||
Task markers are clickable and will show basic data in the json viewer. | ||
|
||
![Screenshot](screenshots/tasks.png) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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 |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Task.js | ||
* | ||
* Processed log for a task. Handles computing the state of | ||
* a task at a specified time. | ||
*/ | ||
import _ from "lodash"; | ||
|
||
class Task { | ||
constructor(date, taskIdx, taskReq, taskResp) { | ||
this.taskIdx = taskIdx; | ||
this.taskId = taskReq.taskid; | ||
this.updates = []; | ||
this.firstUpdate = date; | ||
this.addUpdate(date, taskReq, taskReq, taskResp); | ||
} | ||
|
||
/** | ||
* Returns the status of the task at the specified date. Note that | ||
* many task changes are actually done as side-effects of vehicle changes | ||
* and thus the debugger only has visibily into a task change if there | ||
* is an update_task call made. | ||
*/ | ||
getTaskInfo(maxDate) { | ||
const taskInfo = { | ||
taskid: this.taskId, | ||
}; | ||
const lastUpdate = _(this.updates) | ||
.filter((update) => update.date <= maxDate) | ||
.last(); | ||
|
||
if (lastUpdate) { | ||
// The create vs update task input and output protos are annoyingly | ||
// different. The following code attemps to handle both. | ||
taskInfo.type = lastUpdate.taskResp.type || lastUpdate.taskReq.task.type; | ||
taskInfo.plannedlocation = | ||
lastUpdate.taskResp.plannedlocation || | ||
lastUpdate.taskReq.task.plannedlocation; | ||
taskInfo.taskoutcome = lastUpdate.taskResp.taskoutcome; | ||
taskInfo.state = lastUpdate.taskResp.state; | ||
taskInfo.taskoutcomelocationsource = | ||
lastUpdate.taskResp.taskoutcomelocationsource; | ||
taskInfo.taskoutcomelocation = lastUpdate.taskResp.taskoutcomelocation; | ||
taskInfo.taskoutcometime = lastUpdate.taskResp.taskoutcometime; | ||
taskInfo.trackingid = | ||
lastUpdate.taskResp.trackingid || lastUpdate.taskReq.task.trackingid; | ||
if (taskInfo.taskoutcomelocationsource) { | ||
taskInfo.plannedVsActualDeltaMeters = | ||
window.google.maps.geometry.spherical.computeDistanceBetween( | ||
{ | ||
lat: taskInfo.plannedlocation.point.latitude, | ||
lng: taskInfo.plannedlocation.point.longitude, | ||
}, | ||
{ | ||
lat: taskInfo.taskoutcomelocation.point.latitude, | ||
lng: taskInfo.taskoutcomelocation.point.longitude, | ||
} | ||
); | ||
} | ||
} | ||
return taskInfo; | ||
} | ||
|
||
addUpdate(date, taskReq, taskResp) { | ||
this.lastUpdate = date; | ||
this.updates.push({ | ||
date, | ||
taskReq, | ||
taskResp, | ||
}); | ||
} | ||
} | ||
export { Task as default }; |
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* TaskLogs.js | ||
* | ||
* Processes raw logs into task oriented logs where a single entry | ||
* contains all the information about a task. | ||
*/ | ||
import _ from "lodash"; | ||
import Task from "./Task"; | ||
class TaskLogs { | ||
constructor(tripLogs) { | ||
this.tasks = {}; | ||
this.processTasks(tripLogs.getRawLogs_()); | ||
this.minDate = tripLogs.minDate; | ||
this.maxDate = tripLogs.maxDate; | ||
} | ||
|
||
processTasks(logs) { | ||
_(logs) | ||
.filter( | ||
// TODO #133: response can be empty on errors -- we should highlight those rows!! | ||
(le) => | ||
(le.logname.match("create_task") || | ||
le.logname.match("update_task")) && | ||
le.jsonpayload.response | ||
) | ||
.forEach((le, taskIdx) => { | ||
const taskReq = le.jsonpayload.request; | ||
const taskResp = le.jsonpayload.response; | ||
let task = this.tasks[taskReq.taskid]; | ||
if (!task) { | ||
task = this.tasks[taskReq.taskid] = new Task( | ||
le.date, | ||
taskIdx, | ||
taskReq, | ||
taskResp | ||
); | ||
} else { | ||
task.addUpdate(le.date, taskReq, taskResp); | ||
} | ||
}); | ||
} | ||
|
||
/* | ||
* Tasks are always shown -- no matter the state of the timeslider. | ||
* | ||
* The timeslider is used purely to control what task state/outcome | ||
* is displayed. | ||
*/ | ||
getTasks(maxDate) { | ||
maxDate = maxDate || this.maxDate; | ||
return _(this.tasks) | ||
.values() | ||
.map((task) => task.getTaskInfo(maxDate)) | ||
.compact(); | ||
} | ||
} | ||
|
||
export { TaskLogs as default }; |
Oops, something went wrong.