11/*
2- * TripLogs.js
2+ * src/ TripLogs.js
33 *
44 * Processes raw logs into 'trip segments'. A trip segment might
55 * be an individual trip, a contiguous non-trip region, or the route
@@ -9,6 +9,7 @@ import _ from "lodash";
99import Trip from "./Trip" ;
1010import HighVelocityJump from "./HighVelocityJump" ;
1111import MissingUpdate from "./MissingUpdate" ;
12+ import { log } from "./Utils" ;
1213
1314const maxDistanceForDwell = 20 ; // meters
1415const requiredUpdatesForDwell = 12 ; // aka 2 minute assuming update vehicle request at 10 seconds
@@ -96,16 +97,20 @@ function adjustFieldFormat(log, origPath, newPath, stringToTrim) {
9697}
9798
9899function processRawLogs ( rawLogs , solutionType ) {
99- console . log ( `Processing ${ rawLogs . length } raw logs for ${ solutionType } ` ) ;
100+ log ( `Processing ${ rawLogs . length } raw logs for ${ solutionType } ` ) ;
100101 const origLogs = rawLogs . map ( toLowerKeys ) ;
101102 const isReversed =
102103 origLogs . length > 1 &&
103104 new Date ( origLogs [ 0 ] . timestamp ) >
104105 new Date ( origLogs [ origLogs . length - 1 ] . timestamp ) ;
105- console . log ( `Raw logs are ${ isReversed ? "reversed" : "chronological" } ` ) ;
106+ log ( `Raw logs are ${ isReversed ? "reversed" : "chronological" } ` ) ;
106107
107108 let sortedLogs = isReversed ? _ . reverse ( origLogs ) : origLogs ;
108109 let newLogs = [ ] ;
110+ let lastKnownLocation = null ;
111+ let lastKnownHeading = 0 ;
112+ const vehiclePath =
113+ solutionType === "LMFS" ? "request.deliveryvehicle" : "request.vehicle" ;
109114
110115 for ( let idx = 0 ; idx < sortedLogs . length ; idx ++ ) {
111116 const origLog = sortedLogs [ idx ] ;
@@ -185,6 +190,18 @@ function processRawLogs(rawLogs, solutionType) {
185190 ) ;
186191 }
187192
193+ // Creating lastlocation for trip rows so that these still show the last known car marker
194+ const currentLocation = _ . get ( newLog , `${ vehiclePath } .lastlocation` ) ;
195+ if ( currentLocation ?. rawlocation ) {
196+ lastKnownLocation = currentLocation . rawlocation ;
197+ lastKnownHeading = currentLocation . heading ;
198+ } else if ( lastKnownLocation ) {
199+ _ . set ( newLog , `${ vehiclePath } .lastlocation` , {
200+ rawlocation : lastKnownLocation ,
201+ heading : lastKnownHeading ,
202+ } ) ;
203+ }
204+
188205 newLogs . push ( newLog ) ;
189206 }
190207 }
@@ -195,7 +212,7 @@ function processRawLogs(rawLogs, solutionType) {
195212
196213class TripLogs {
197214 constructor ( rawLogs , solutionType ) {
198- console . log (
215+ log (
199216 `Initializing TripLogs with ${ rawLogs . length } raw logs for ${ solutionType } `
200217 ) ;
201218 this . initialize ( rawLogs , solutionType ) ;
@@ -250,11 +267,9 @@ class TripLogs {
250267 this . processTripSegments ( ) ;
251268 this . debouncedGetHighVelocityJumps = _ . debounce (
252269 ( minDate , maxDate , callback ) => {
253- console . log ( "debouncedGetHighVelocityJumps executing" ) ;
270+ log ( "debouncedGetHighVelocityJumps executing" ) ;
254271 const jumps = this . getHighVelocityJumps ( minDate , maxDate ) ;
255- console . log (
256- `debouncedGetHighVelocityJumps found ${ jumps . length } jumps`
257- ) ;
272+ log ( `debouncedGetHighVelocityJumps found ${ jumps . length } jumps` ) ;
258273 callback ( jumps ) ;
259274 } ,
260275 300
@@ -331,7 +346,7 @@ class TripLogs {
331346 * updates.
332347 */
333348 getETADeltas ( minDate , maxDate ) {
334- console . log ( `Getting ETA deltas between ${ minDate } and ${ maxDate } ` ) ;
349+ log ( `Getting ETA deltas between ${ minDate } and ${ maxDate } ` ) ;
335350 let prevEntry ;
336351 this . etaDeltas = this . getRawLogs_ ( minDate , maxDate )
337352 . filter (
@@ -366,9 +381,7 @@ class TripLogs {
366381 * at an unrealistic velocity.
367382 */
368383 getHighVelocityJumps ( minDate , maxDate ) {
369- console . log (
370- `Getting high velocity jumps between ${ minDate } and ${ maxDate } `
371- ) ;
384+ log ( `Getting high velocity jumps between ${ minDate } and ${ maxDate } ` ) ;
372385
373386 let prevEntry ;
374387 let entries = this . getRawLogs_ ( minDate , maxDate )
@@ -384,7 +397,7 @@ class TripLogs {
384397 . compact ( )
385398 . value ( ) ;
386399
387- console . log ( `Created ${ entries . length } HighVelocityJump instances` ) ;
400+ log ( `Created ${ entries . length } HighVelocityJump instances` ) ;
388401
389402 const velocityJumps = HighVelocityJump . getSignificantJumps ( entries ) ;
390403 console . log ( `Found ${ velocityJumps . length } high velocity jumps` ) ;
@@ -410,7 +423,7 @@ class TripLogs {
410423 * description of the very simplistic algo used here.
411424 */
412425 getDwellLocations ( minDate , maxDate ) {
413- console . log ( `Getting dwell locations between ${ minDate } and ${ maxDate } ` ) ;
426+ log ( `Getting dwell locations between ${ minDate } and ${ maxDate } ` ) ;
414427 const dwellLocations = [ ] ;
415428 _ . forEach ( this . rawLogs , ( le ) => {
416429 const lastLocation = le . lastlocation ;
@@ -470,7 +483,7 @@ class TripLogs {
470483 }
471484
472485 processTripSegments ( ) {
473- console . log ( "Processing trip segments" ) ;
486+ log ( "Processing trip segments" ) ;
474487 let curTripId = "this is not a segment" ;
475488 let curTripData = undefined ;
476489 let tripIdx = 0 ;
0 commit comments