fleetmap-reports 2.0.376 → 2.0.377
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 +10 -0
package/package.json
CHANGED
package/src/util/trips.js
CHANGED
|
@@ -133,6 +133,9 @@ function isInsideTimetable (t, userData) {
|
|
|
133
133
|
function updateTrip (device, t, route) {
|
|
134
134
|
route = route.filter(p => p && p.attributes.ignition)
|
|
135
135
|
if (!route.length) { return }
|
|
136
|
+
const originalDistance = t.distance
|
|
137
|
+
const originalDuration = t.duration
|
|
138
|
+
const originalSpentFuel = t.spentFuel
|
|
136
139
|
const distance = calculateDistance(route, device ? device.attributes['report.ignoreOdometer'] : true) * 1000
|
|
137
140
|
t.distance = distance
|
|
138
141
|
t.duration = new Date(route[route.length - 1].fixTime).getTime() - new Date(route[0].fixTime).getTime()
|
|
@@ -140,6 +143,13 @@ function updateTrip (device, t, route) {
|
|
|
140
143
|
t.averageSpeed = distance > 0 ? ((route.reduce((a, b) => a + b.speed, 0)) / route.length) : 0
|
|
141
144
|
t.startOdometer = device && !device.attributes['report.ignoreOdometer'] && route[0].attributes.odometer ? route[0].attributes.odometer : route[0].attributes.totalDistance
|
|
142
145
|
t.endOdometer = device && !device.attributes['report.ignoreOdometer'] && route[route.length - 1].attributes.odometer ? route[route.length - 1].attributes.odometer : route[route.length - 1].attributes.totalDistance
|
|
146
|
+
if (originalSpentFuel > 0) {
|
|
147
|
+
// A trip clipped at a report day boundary keeps only part of its route, so its
|
|
148
|
+
// share of the trip's total fuel must be prorated too, otherwise the full trip's
|
|
149
|
+
// fuel gets counted on both days it was split across.
|
|
150
|
+
const ratio = originalDistance > 0 ? distance / originalDistance : (originalDuration > 0 ? t.duration / originalDuration : 1)
|
|
151
|
+
t.spentFuel = originalSpentFuel * Math.min(Math.max(ratio, 0), 1)
|
|
152
|
+
}
|
|
143
153
|
}
|
|
144
154
|
|
|
145
155
|
function getUncompletedTrip (device, deviceRoute, deviceTrips) {
|