fleetmap-reports 2.0.115 → 2.0.117
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/util/trips.js +22 -1
package/package.json
CHANGED
package/src/util/trips.js
CHANGED
|
@@ -188,10 +188,31 @@ function calculateStopDuration (stop) {
|
|
|
188
188
|
return totalStopTime - (stop.engineHours > 0 ? stop.engineHours : 0)
|
|
189
189
|
}
|
|
190
190
|
|
|
191
|
+
const maxDistanceDiff = 10000
|
|
192
|
+
|
|
193
|
+
function shouldRecalculate (trip, route) {
|
|
194
|
+
if (route && route.length) {
|
|
195
|
+
if (!trip.distance) {
|
|
196
|
+
return true
|
|
197
|
+
}
|
|
198
|
+
if (route[0].protocol === 'osmand' && route[0].attributes.odometer) {
|
|
199
|
+
const positions = route.filter(p => p.deviceId === trip.deviceId &&
|
|
200
|
+
new Date(p.fixTime).getTime() >= new Date(trip.startTime).getTime() &&
|
|
201
|
+
new Date(p.fixTime).getTime() <= new Date(trip.endTime).getTime())
|
|
202
|
+
if (positions.length) {
|
|
203
|
+
const totalDistance = positions[positions.length - 1].attributes.totalDistance - positions[0].attributes.totalDistance
|
|
204
|
+
return trip.distance < (totalDistance - maxDistanceDiff)
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
return false
|
|
209
|
+
}
|
|
210
|
+
|
|
191
211
|
function getTripTotalKms (trip, stop, route) {
|
|
192
212
|
// we need to add stop kms to ensure that the total kms for the day, calculated with the odometer difference, will be equal to the sum of kms of all trips
|
|
193
213
|
let distance = trip.distance + (stop ? (stop.endOdometer - stop.startOdometer) : 0)
|
|
194
|
-
if (
|
|
214
|
+
if (shouldRecalculate(trip, route)) {
|
|
215
|
+
distance = 0
|
|
195
216
|
const positions = route.filter(p => p.deviceId === trip.deviceId &&
|
|
196
217
|
new Date(p.fixTime).getTime() >= new Date(trip.startTime).getTime() &&
|
|
197
218
|
new Date(p.fixTime).getTime() <= new Date(trip.endTime).getTime())
|