fleetmap-reports 2.0.109 → 2.0.111

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.109",
3
+ "version": "2.0.111",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -98,10 +98,11 @@ function getDeviceData (allInOne, d) {
98
98
  deviceTrips.push(uncompletedTrip)
99
99
  }
100
100
 
101
- if (deviceRoute.find(p => p.attributes.xpert)) {
101
+ if (deviceRoute.find(p => p.attributes.rawXpert)) {
102
102
  // Inofleet unit with xpert data
103
- const endTripData = getEndTripMessages(deviceRoute).map(m => parseEndTripMessage(m.xpertString || m)).sort((a, b) => a.date.localeCompare(b.date))
104
- const canDriverStyle = getCanDriverStyleMessages(deviceRoute).map(m => parseCanDriverStyleMessage(m.xpertString || m)).sort((a, b) => a.date.localeCompare(b.date))
103
+ const xpertMessages = deviceRoute.map(p => p.attributes.rawXpert).filter(a => a)
104
+ const endTripData = getEndTripMessages(xpertMessages).map(m => parseEndTripMessage(m.xpertString || m)).sort((a, b) => a.date.localeCompare(b.date))
105
+ const canDriverStyle = getCanDriverStyleMessages(xpertMessages).map(m => parseCanDriverStyleMessage(m.xpertString || m)).sort((a, b) => a.date.localeCompare(b.date))
105
106
 
106
107
  const drivingTime = endTripData.length > 1 ? endTripData[endTripData.length - 1].totalTimeDriving - endTripData[0].totalTimeDriving : 0
107
108
  const idleTime = endTripData.length > 1 ? (endTripData[endTripData.length - 1].totalTimeInIdle || 0) - (endTripData[0].totalTimeInIdle || 0) : 0
@@ -145,7 +146,7 @@ function getDeviceData (allInOne, d) {
145
146
  const drivingTime = deviceTrips.reduce((a, b) => a + b.duration, 0)
146
147
  const drivingConsumption = calculateConsumption(d, { trips: deviceTrips, stops: [], route: deviceRoute, summary: deviceSummary }, undefined)
147
148
  const drivingDistance = deviceSummary ? deviceSummary.distance / 1000 : 0
148
- const idleTime = deviceTrips.reduce((a, b) => a + b.idleTime, 0) + deviceStops.reduce((a, b) => a + b.engineHours, 0)
149
+ const idleTime = deviceTrips.reduce((a, b) => a + (b.idleTime ? b.idleTime : 0), 0) + deviceStops.reduce((a, b) => a + b.engineHours, 0)
149
150
  const idleConsumption = deviceSummary && deviceSummary.spentFuel > drivingConsumption ? deviceSummary.spentFuel - drivingConsumption : 0
150
151
 
151
152
  const highEngineRPMSections = calculateRPMSections(deviceRoute, d.attributes.highRPM || 1300)
@@ -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
 
@@ -311,6 +311,11 @@ async function processDrivers (from, to, userData, data) {
311
311
  return driversResult
312
312
  }
313
313
 
314
+ function getTripTotalKms (trip, stop) {
315
+ // 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
316
+ return (trip.distance + (stop ? (stop.endOdometer - stop.startOdometer) : 0)) / 1000
317
+ }
318
+
314
319
  async function exportTripReportToPDF (userData, reportData) {
315
320
  console.log('exportTripReportToPDF')
316
321
 
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())
package/src/util/xpert.js CHANGED
@@ -44,18 +44,12 @@ function parseCanDriverStyleMessage (xpertMessage) {
44
44
  }
45
45
  }
46
46
 
47
- function getEndTripMessages (route) {
48
- const positions = route.filter(p => p.attributes.xpert &&
49
- (Array.isArray(p.attributes.xpert) ? p.attributes.xpert.find(x => x.type === '3') : p.attributes.xpert.split(';').find(m => m.startsWith('3'))))
50
-
51
- return positions.map(p => (Array.isArray(p.attributes.xpert) ? p.attributes.xpert.find(x => x.type === '3') : p.attributes.xpert.split(';').find(m => m.startsWith('3'))))
47
+ function getEndTripMessages (xpertMessages) {
48
+ return xpertMessages.map(xpert => (Array.isArray(xpert) ? xpert.find(x => x.type === '3') : xpert.split(';').find(m => m.startsWith('3')))).filter(a => a)
52
49
  }
53
50
 
54
- function getCanDriverStyleMessages (route) {
55
- const positions = route.filter(p => p.attributes.xpert &&
56
- (Array.isArray(p.attributes.xpert) ? p.attributes.xpert.find(x => x.type === '4') : p.attributes.xpert.split(';').find(m => m.startsWith('4'))))
57
-
58
- return positions.map(p => (Array.isArray(p.attributes.xpert) ? p.attributes.xpert.find(x => x.type === '4') : p.attributes.xpert.split(';').find(m => m.startsWith('4'))))
51
+ function getCanDriverStyleMessages (xpertMessages) {
52
+ return xpertMessages.map(xpert => (Array.isArray(xpert) ? xpert.find(x => x.type === '4') : xpert.split(';').find(m => m.startsWith('4')))).filter(a => a)
59
53
  }
60
54
 
61
55
  exports.parseEndTripMessage = parseEndTripMessage