fleetmap-reports 1.0.448 → 1.0.450

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": "1.0.448",
3
+ "version": "1.0.450",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
package/src/index.test.js CHANGED
@@ -51,8 +51,9 @@ describe('Test_Reports', function () {
51
51
  const device = data[0].devices.find(d => d.device.id === 22326)
52
52
  assert.equal(device.trips.length, 7) // Total Trips
53
53
  assert.equal(device.trips[0].endPOIName, 'Casa João')
54
+ assert.equal(device.trips[0].idleTime, 602000)
54
55
  assert.equal(device.trips[1].endPOIName, undefined)
55
- assert.equal(device.totalDistance, 339204.53999999166) // Total Kms
56
+ assert.equal(device.totalDistance, 339170.3099999875) // Total Kms
56
57
  }, 20000)
57
58
  // eslint-disable-next-line no-undef
58
59
  it('Trip by driver', async () => {
@@ -65,10 +66,10 @@ describe('Test_Reports', function () {
65
66
  assert.equal(data.length, 1)
66
67
  console.log(data[0].drivers)
67
68
  const driver = data[0].drivers.find(d => d.driver.id === 14020)
68
- assert.equal(driver.trips.length, 9) // Total Trips
69
- assert.equal(driver.totalDuration, 6274000)
70
- assert.equal(driver.maxSpeed, 70.1944)
71
- }, 20000)
69
+ assert.equal(driver.trips.length, 13) // Total Trips
70
+ assert.equal(driver.totalDuration, 8159000)
71
+ assert.equal(driver.maxSpeed, 78.8337)
72
+ }, 90000)
72
73
  // eslint-disable-next-line no-undef
73
74
  it('Trip without addresses', async () => {
74
75
  const report = await getReports()
@@ -226,7 +227,7 @@ describe('Test_Reports', function () {
226
227
  assert.equal(data.length, 1)
227
228
  const device = data[0].devices.find(d => d.device.id === 22326)
228
229
  const totalIdleTime = device.idleEvents.reduce((a, b) => a + b.idleTime, 0)
229
- assert.equal(device.idleEvents.length, 8) // Total Alerts
230
+ assert.equal(device.idleEvents.length, 9) // Total Alerts
230
231
  assert.equal(totalIdleTime, 1294000) // Total Duration
231
232
  }, 20000)
232
233
  // eslint-disable-next-line no-undef
@@ -169,9 +169,10 @@ function processDevices (from, to, devices, data, userData, traccar) {
169
169
  }
170
170
 
171
171
  const stop = getStop(new Date(trip.startTime), stops)
172
+
172
173
  if (stop && !trip.endTimeIsOut) {
173
174
  trip.stopDuration = (new Date(stop.endTime) - new Date(stop.startTime))
174
- trip.stopEngineHours = stop.engineHours
175
+ trip.stopEngineHours = trip.idleTime + stop.idleTime
175
176
  } else {
176
177
  trip.stopDuration = 0
177
178
  trip.stopEngineHours = 0
@@ -270,6 +271,7 @@ async function exportTripReportToPDF (userData, reportData) {
270
271
  }
271
272
 
272
273
  if (tripsData) {
274
+ // eslint-disable-next-line new-cap
273
275
  const doc = new jsPDF.jsPDF('l')
274
276
  await headerFromUser(doc, translations.report.titleTripReport, userData.user)
275
277
 
package/src/util/route.js CHANGED
@@ -1,4 +1,5 @@
1
1
  function getIdleEvents (route, driver) {
2
+ const speedThreshold = 3
2
3
  const idleEvents = []
3
4
 
4
5
  const routeByDevice = route.reduce(function (a, x) {
@@ -8,8 +9,9 @@ function getIdleEvents (route, driver) {
8
9
 
9
10
  Object.keys(routeByDevice).forEach(function (key) {
10
11
  let inIdle = false
12
+ let last = null
11
13
  routeByDevice[key].forEach(p => {
12
- if (p.attributes.ignition && p.speed === 0 && (!driver || p.attributes.driverUniqueId === driver.uniqueId)) {
14
+ if (p.attributes.ignition && p.speed < speedThreshold && (!driver || p.attributes.driverUniqueId === driver.uniqueId)) {
13
15
  if (!inIdle) {
14
16
  const idleEvent = {
15
17
  position: p,
@@ -17,20 +19,16 @@ function getIdleEvents (route, driver) {
17
19
  }
18
20
  idleEvents.push(idleEvent)
19
21
  inIdle = true
20
- } else {
21
- if (!idleEvents[idleEvents.length - 1].position.attributes.driverUniqueId) {
22
- idleEvents[idleEvents.length - 1].position.attributes.driverUniqueId = p.attributes.driverUniqueId
23
- }
22
+ }
24
23
 
25
- if (p.attributes.idleTime) {
26
- idleEvents[idleEvents.length - 1].idleTime = p.attributes.idleTime
27
- }
24
+ if (!idleEvents[idleEvents.length - 1].position.attributes.driverUniqueId) {
25
+ idleEvents[idleEvents.length - 1].position.attributes.driverUniqueId = p.attributes.driverUniqueId
28
26
  }
27
+
28
+ last = p
29
29
  } else if (inIdle) {
30
30
  const currentIdleEvent = idleEvents[idleEvents.length - 1]
31
- if (p.attributes.idleTime === undefined) {
32
- currentIdleEvent.idleTime = new Date(p.fixTime) - new Date(currentIdleEvent.position.fixTime)
33
- }
31
+ currentIdleEvent.idleTime = new Date(last.fixTime) - new Date(currentIdleEvent.position.fixTime)
34
32
  inIdle = false
35
33
  }
36
34
  })
@@ -38,5 +36,4 @@ function getIdleEvents (route, driver) {
38
36
 
39
37
  return idleEvents
40
38
  }
41
-
42
39
  exports.getIdleEvents = getIdleEvents