1- /*
2- * src/Trip.js
3- *
4- * Processed log for a trip. Currently only includes very basic information
5- * about the trip
6- */
1+ // src/Trip.js
2+
73import _ from "lodash" ;
84import Utils from "./Utils" ;
95
@@ -18,6 +14,7 @@ class Trip {
1814 this . firstUpdate = firstUpdate ;
1915 this . lastUpdate = "Unknown" ;
2016 this . plannedPath = [ ] ;
17+ this . logs = [ ] ;
2118 }
2219
2320 getTraveledDistance ( ) {
@@ -72,27 +69,35 @@ class Trip {
7269 return this . plannedPath ;
7370 }
7471
75- getPoint ( type , path ) {
76- return _ . get (
77- _ . find ( this . logs , ( log ) => log [ "@type" ] === type && _ . get ( log , path ) ) ,
78- path
79- ) ;
72+ getPointFromLogs ( path , useLatest ) {
73+ if ( ! this . logs || this . logs . length === 0 ) {
74+ return null ;
75+ }
76+
77+ const sortedLogs = useLatest ? _ . sortBy ( this . logs , "timestampMS" ) . reverse ( ) : this . logs ;
78+ for ( const log of sortedLogs ) {
79+ const point = _ . get ( log , `response.${ path } ` ) ;
80+ if ( point ) {
81+ return point ;
82+ }
83+ }
84+ return null ;
8085 }
8186
8287 getPickupPoint ( ) {
83- return this . getPoint ( "createTrip" , "request.trip. pickuppoint.point") ;
88+ return this . getPointFromLogs ( " pickuppoint.point", true ) ;
8489 }
8590
8691 getDropoffPoint ( ) {
87- return this . getPoint ( "createTrip" , "request.trip. dropoffpoint.point") ;
92+ return this . getPointFromLogs ( " dropoffpoint.point", true ) ;
8893 }
8994
9095 getActualPickupPoint ( ) {
91- return this . getPoint ( "updateTrip" , "response. actualpickuppoint.point") ;
96+ return this . getPointFromLogs ( " actualpickuppoint.point", false ) ;
9297 }
9398
9499 getActualDropoffPoint ( ) {
95- return this . getPoint ( "updateTrip" , "response. actualdropoffpoint.point") ;
100+ return this . getPointFromLogs ( " actualdropoffpoint.point", false ) ;
96101 }
97102}
98103
0 commit comments