fleetmap-reports 1.0.448 → 1.0.452

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.452",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -166,8 +166,7 @@ function processDevices (from, to, devices, routes, userData) {
166
166
  const route = routes.filter(p => p.deviceId === d.id)
167
167
 
168
168
  const idleEvents = getIdleEvents(route)
169
- console.log(idleEvents)
170
- const filteredEvents = idleEvents.filter(e => userData.minimumIdleMinutes ? e.idleTime > userData.minimumIdleMinutes * 60 * 1000 : true)
169
+ const filteredEvents = idleEvents.filter(e => e.idleTime > (userData.minimumIdleMinutes ? userData.minimumIdleMinutes * 60 * 1000 : 0))
171
170
 
172
171
  if (filteredEvents.length) {
173
172
  filteredEvents.forEach(e => {
package/src/index.test.js CHANGED
@@ -15,7 +15,6 @@ async function getSpeedingReport (report, userData) {
15
15
 
16
16
  // eslint-disable-next-line no-undef
17
17
  describe('Test_Reports', function () {
18
- this.timeout(500000)
19
18
  // eslint-disable-next-line no-undef
20
19
  it('Speeding by device', async () => {
21
20
  const report = await getReports()
@@ -51,8 +50,9 @@ describe('Test_Reports', function () {
51
50
  const device = data[0].devices.find(d => d.device.id === 22326)
52
51
  assert.equal(device.trips.length, 7) // Total Trips
53
52
  assert.equal(device.trips[0].endPOIName, 'Casa João')
53
+ assert.equal(device.trips[0].idleTime, 602000)
54
54
  assert.equal(device.trips[1].endPOIName, undefined)
55
- assert.equal(device.totalDistance, 339204.53999999166) // Total Kms
55
+ assert.equal(device.totalDistance, 339170.3099999875) // Total Kms
56
56
  }, 20000)
57
57
  // eslint-disable-next-line no-undef
58
58
  it('Trip by driver', async () => {
@@ -65,10 +65,10 @@ describe('Test_Reports', function () {
65
65
  assert.equal(data.length, 1)
66
66
  console.log(data[0].drivers)
67
67
  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)
68
+ assert.equal(driver.trips.length, 13) // Total Trips
69
+ assert.equal(driver.totalDuration, 8159000)
70
+ assert.equal(driver.maxSpeed, 78.8337)
71
+ }, 90000)
72
72
  // eslint-disable-next-line no-undef
73
73
  it('Trip without addresses', async () => {
74
74
  const report = await getReports()
@@ -199,7 +199,7 @@ describe('Test_Reports', function () {
199
199
  assert.equal(data.length, 1)
200
200
  assert.equal(data.length, 1)
201
201
  const device = data[0].devices.find(d => d.device.id === 22326)
202
- assert.equal(device.summary.distance, 1193284.3100000024) // Total Kms
202
+ assert.equal(device.summary.distance, 1183904.0299999565) // Total Kms
203
203
  }, 30000)
204
204
  // eslint-disable-next-line no-undef
205
205
  it('KmsReport byDevice groupByDay', async () => {
@@ -213,7 +213,7 @@ describe('Test_Reports', function () {
213
213
  assert.equal(data.length, 1)
214
214
  const device = data[0].devices.find(d => d.device.id === 22326)
215
215
  assert.equal(device.days.length, 10) // Total Kms
216
- assert.equal(device.days[5].kms, 23183.010000005364) // Total Kms
216
+ assert.equal(device.days[5].kms, 23124.280000001192) // Total Kms
217
217
  }, 30000)
218
218
  // eslint-disable-next-line no-undef
219
219
  it('Idle by device', async () => {
@@ -226,23 +226,26 @@ describe('Test_Reports', function () {
226
226
  assert.equal(data.length, 1)
227
227
  const device = data[0].devices.find(d => d.device.id === 22326)
228
228
  const totalIdleTime = device.idleEvents.reduce((a, b) => a + b.idleTime, 0)
229
- assert.equal(device.idleEvents.length, 8) // Total Alerts
230
- assert.equal(totalIdleTime, 1294000) // Total Duration
229
+ assert.equal(device.idleEvents.length, 9) // Total Alerts
230
+ assert.equal(totalIdleTime, 1592000) // Total Duration
231
231
  }, 20000)
232
232
  // eslint-disable-next-line no-undef
233
233
  it('Idle by driver', async () => {
234
234
  const report = await getReports()
235
235
  const userData = await report.getUserData()
236
- userData.minimumIdleMinutes = 2
236
+ userData.minimumIdleMinutes = 0
237
237
  userData.byDriver = true
238
+
239
+ console.log(userData.drivers)
238
240
  const data = await report.idleReport(new Date(2022, 0, 3, 0, 0, 0, 0),
239
241
  new Date(2022, 0, 7, 23, 59, 59, 0),
240
242
  userData)
241
243
  assert.equal(data.length, 1)
242
244
  const driver = data[0].drivers.find(d => d.driver.id === 14020)
245
+
243
246
  const totalIdleTime = driver.idleEvents.reduce((a, b) => a + b.idleTime, 0)
244
- assert.equal(driver.idleEvents.length, 1) // Total Alerts
245
- assert.equal(totalIdleTime, 8267000) // Total Duration
247
+ assert.equal(driver.idleEvents.length, 15) // Total Alerts
248
+ assert.equal(totalIdleTime, 16000) // Total Duration
246
249
  }, 20000)
247
250
  // eslint-disable-next-line no-undef
248
251
  it('Activity by device', async () => {
@@ -255,7 +258,7 @@ describe('Test_Reports', function () {
255
258
  assert.equal(data.length, 1)
256
259
  const device = data[0].devices.find(d => d.device.id === 22326)
257
260
  assert.equal(device.summary[0].startOdometer, 122502742.59)
258
- assert.equal(device.summary[0].distance, 1423529.600000009)
261
+ assert.equal(device.summary[0].distance, 1404204.4299999028)
259
262
  assert.equal(device.summary[0].startTime, '2022-01-01T13:35:47.000+0000')
260
263
  assert.equal(device.summary[0].endTime, '2022-01-31T17:36:27.000+0000')
261
264
  }, 40000)
@@ -283,8 +286,8 @@ describe('Test_Reports', function () {
283
286
  assert.equal(data.length, 1)
284
287
  const device = data[0].devices.find(d => d.device.id === 22326)
285
288
  assert.equal(device.summary[5].startOdometer, 122923290.95)
286
- assert.equal(device.summary[5].distance, 77020.37999999523)
287
- assert.equal(device.summary[5].startTime, '2022-01-06T18:35:04.000+0000')
289
+ assert.equal(device.summary[5].distance, 77021.6400000006)
290
+ assert.equal(device.summary[5].startTime, '2022-01-06T18:35:36.000+0000')
288
291
  assert.equal(device.summary[5].endTime, '2022-01-06T19:54:27.000+0000')
289
292
  }, 90000)
290
293
  // eslint-disable-next-line no-undef
@@ -320,11 +323,11 @@ describe('Test_Reports', function () {
320
323
  userData)
321
324
 
322
325
  assert.equal(tripsReport.length, 1)
323
- const device1 = tripsReport[0].devices.find(d => d.device.id === 11681)
324
- assert.equal(device1.trips.length, 44) // Total Trips
325
- assert.equal(device1.totalDistance, 882801.0815308811) // Total Kms
326
+ const device1 = tripsReport[0].devices.find(d => d.device.id === 22327)
327
+ assert.equal(device1.trips.length, 14) // Total Trips
328
+ assert.equal(device1.totalDistance, 83553.13999999687) // Total Kms
326
329
 
327
- const device2 = kmsReport[0].devices.find(d => d.device.id === 11681)
330
+ const device2 = kmsReport[0].devices.find(d => d.device.id === 22327)
328
331
  assert.equal(device2.summary.distance, device1.totalDistance) // Total Kms
329
332
  }, 30000)
330
333
  // 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/odoo.js CHANGED
@@ -1,16 +1,14 @@
1
1
 
2
- async function getOdooFuelServices (traccar, from, to) {
3
- const url = `/odoo/reports/refuelingServices?startDate=${from.toDateString()}&endDate=${to.toDateString()}`
2
+ async function getOdooFuelServices(traccar, from, to) {
3
+ const url = `/odoo/reports/refuelingServices?startDate=${from.toDateString()}&endDate=${to.toDateString()}`
4
4
 
5
- console.log('LOADING_MESSAGE:' + url)
6
- const { data } = await traccar.axios.get(url, {
7
- jar: traccar.cookieJar,
8
- withCredentials: true
9
- })
5
+ const {data} = await traccar.axios.get(url,{
6
+ jar: traccar.cookieJar,
7
+ withCredentials: true })
10
8
 
11
- console.log(data)
9
+ console.log(data)
12
10
 
13
- return data
11
+ return data
14
12
  }
15
13
 
16
14
  exports.getOdooFuelServices = getOdooFuelServices
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