fleetmap-reports 2.0.110 → 2.0.112

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fleetmap-reports",
3
- "version": "2.0.110",
3
+ "version": "2.0.112",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -12,7 +12,7 @@ const traccarHelper = require('./util/traccar')
12
12
  const trips = require('./util/trips')
13
13
  const {
14
14
  isInsideTimetable, isPartialInsideTimetable, getTripIdleTime, calculateStopDuration,
15
- getUncompletedTrip
15
+ getUncompletedTrip, getTripTotalKms
16
16
  } = require('./util/trips')
17
17
  const { devicesToProcess, deviceName } = require('./util/device')
18
18
  const { getIdleEvents } = require('./util/route')
@@ -175,7 +175,9 @@ async function processDevices (from, to, devices, data, userData, traccar) {
175
175
  const stops = data.stops.filter(s => s.deviceId === d.id)
176
176
 
177
177
  trips.forEach(trip => {
178
- trip.totalKms = trip.distance / 1000
178
+ const stop = getStop(new Date(trip.startTime), stops)
179
+
180
+ trip.totalKms = getTripTotalKms(trip, stop)
179
181
 
180
182
  const nearestPOIs = getNearestPOIs(trip.endLon, trip.endLat, userData.geofences)
181
183
  if (nearestPOIs.length > 0) {
@@ -213,8 +215,6 @@ async function processDevices (from, to, devices, data, userData, traccar) {
213
215
  : 0
214
216
  }
215
217
 
216
- const stop = getStop(new Date(trip.startTime), stops)
217
-
218
218
  if (deviceRoute.some(r => r.attributes.fuel) ||
219
219
  automaticReports.deviceWithFuelInfo(d)) {
220
220
  trip.fuelConsumption = calculateConsumption(d, { trips: [trip], stops: (stop ? [stop] : []), route: deviceRoute })
@@ -284,15 +284,15 @@ async function processDrivers (from, to, userData, data) {
284
284
 
285
285
  if (trips) {
286
286
  trips.forEach(trip => {
287
- trip.totalKms = trip.distance / 1000
287
+ const stop = data.stops.find(s => s.deviceId === trip.deviceId && (new Date(s.startTime).getTime() === new Date(trip.endTime).getTime()))
288
+
289
+ trip.totalKms = getTripTotalKms(trip, stop)
288
290
 
289
291
  const nearestPOIs = getNearestPOIs(trip.endLon, trip.endLat, userData.geofences)
290
292
  if (nearestPOIs.length > 0) {
291
293
  trip.endPOIName = nearestPOIs[0].p.name
292
294
  }
293
295
 
294
- const stop = data.stops.find(s => s.deviceId === trip.deviceId && (new Date(s.startTime).getTime() === new Date(trip.endTime).getTime()))
295
-
296
296
  trip.stopEngineHours = getTripIdleTime(trip, idleEvents) + (stop ? stop.engineHours : 0)
297
297
  })
298
298
 
package/src/util/trips.js CHANGED
@@ -10,7 +10,7 @@ function checkTripsKms (traccarInstance, from, to, devices, data) {
10
10
  if (trips.length > 0) {
11
11
  // Vehicles with imported positions. calculate trip distance with route positions
12
12
  trips.forEach(t => {
13
- if (t.distance === minDistance && t.averageSpeed > minAvgSpeed) {
13
+ if (t.distance === minDistance && t.averageSpeed > minAvgSpeed && data.route.find(p => p.source === 'import')) {
14
14
  const tripRoute = data.route.filter(p => p.deviceId === t.deviceId &&
15
15
  new Date(p.fixTime).getTime() >= new Date(t.startTime).getTime() &&
16
16
  new Date(p.fixTime).getTime() <= new Date(t.endTime).getTime())
@@ -217,6 +217,11 @@ function calculateStopDuration (stop) {
217
217
  return totalStopTime - (stop.engineHours > 0 ? stop.engineHours : 0)
218
218
  }
219
219
 
220
+ function getTripTotalKms (trip, stop) {
221
+ // 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
222
+ return (trip.distance + (stop ? (stop.endOdometer - stop.startOdometer) : 0)) / 1000
223
+ }
224
+
220
225
  exports.checkTripsKms = checkTripsKms
221
226
  exports.isInsideTimetable = isInsideTimetable
222
227
  exports.isPartialInsideTimetable = isPartialInsideTimetable
@@ -227,3 +232,4 @@ exports.calculateTrip = calculateTrip
227
232
  exports.getTripIdleTime = getTripIdleTime
228
233
  exports.calculateStopDuration = calculateStopDuration
229
234
  exports.getUncompletedTrip = getUncompletedTrip
235
+ exports.getTripTotalKms = getTripTotalKms