fleetmap-reports 1.0.490 → 1.0.491

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.490",
3
+ "version": "1.0.491",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
package/src/index.test.js CHANGED
@@ -3,15 +3,13 @@ const assert = require('assert')
3
3
 
4
4
  async function getSpeedingReport (report, userData) {
5
5
  const data = await report.speedingReport(
6
- new Date(Date.UTC(2022, 7, 15, 0, 0, 0, 0)),
7
- new Date(Date.UTC(2022, 7, 15, 23, 59, 59, 0)),
6
+ new Date(Date.UTC(2022, 1, 17, 0, 0, 0, 0)),
7
+ new Date(Date.UTC(2022, 1, 17, 23, 59, 59, 0)),
8
8
  userData)
9
9
  assert.equal(data.length, 1)
10
- const device = data[0].devices[0]
11
- console.log(device)
10
+ const device = data[0].devices.find(d => d.device.id === 22326)
12
11
  const totalDistance = device.alerts.reduce((a, b) => a + b.distance, 0)
13
12
  const totalEventTime = device.alerts.reduce((a, b) => a + b.eventTime, 0)
14
- console.log(device.alerts)
15
13
  return { device, totalDistance, totalEventTime }
16
14
  }
17
15
 
@@ -23,10 +21,9 @@ describe('Test_Reports', function () {
23
21
  const userData = await report.getUserData()
24
22
  userData.roadSpeedLimits = true
25
23
  const { device, totalDistance, totalEventTime } = await getSpeedingReport(report, userData)
26
- assert.equal(device.alerts.length, 16) // Total Alerts
27
- console.log(device.alerts)
28
- assert.equal(totalDistance, 74.71054403083238) // Total Kms
29
- assert.equal(totalEventTime, 3009000) // Total Duration
24
+ assert.equal(device.alerts.length, 104) // Total Alerts
25
+ assert.equal(totalDistance, 36.6525856031222) // Total Kms
26
+ assert.equal(totalEventTime, 1524000) // Total Duration
30
27
  }, 200000)
31
28
  // eslint-disable-next-line no-undef
32
29
  it('Speeding with custom speed', async () => {
@@ -36,9 +33,9 @@ describe('Test_Reports', function () {
36
33
  userData.useVehicleSpeedLimit = false
37
34
  userData.customSpeed = 100
38
35
  const { device, totalDistance, totalEventTime } = await getSpeedingReport(report, userData)
39
- assert.equal(device.alerts.length, 24) // Total Alerts
40
- assert.equal(totalDistance, 49.481065231791064) // Total Kms
41
- assert.equal(totalEventTime, 1523000) // Total Duration
36
+ assert.equal(device.alerts.length, 13) // Total Alerts
37
+ assert.equal(totalDistance, 46.64576895855739) // Total Kms
38
+ assert.equal(totalEventTime, 1402000) // Total Duration
42
39
  }, 20000)
43
40
  // eslint-disable-next-line no-undef
44
41
  it('Trip by device', async () => {
@@ -261,7 +258,7 @@ describe('Test_Reports', function () {
261
258
  assert.equal(data.length, 1)
262
259
  const device = data[0].devices.find(d => d.device.id === 22326)
263
260
  assert.equal(device.summary[0].startOdometer, 122502742.59)
264
- assert.equal(device.summary[0].distance, 1404204.4299999028)
261
+ assert.equal(device.summary[0].distance, 1427444.4699999243)
265
262
  assert.equal(device.summary[0].startTime, '2022-01-01T13:35:47.000+0000')
266
263
  assert.equal(device.summary[0].endTime, '2022-01-31T17:36:27.000+0000')
267
264
  }, 40000)
@@ -289,7 +286,7 @@ describe('Test_Reports', function () {
289
286
  assert.equal(data.length, 1)
290
287
  const device = data[0].devices.find(d => d.device.id === 22326)
291
288
  assert.equal(device.summary[5].startOdometer, 122923290.95)
292
- assert.equal(device.summary[5].distance, 77021.6400000006)
289
+ assert.equal(device.summary[5].distance, 77033.18999999762)
293
290
  assert.equal(device.summary[5].startTime, '2022-01-06T18:35:36.000+0000')
294
291
  assert.equal(device.summary[5].endTime, '2022-01-06T19:54:27.000+0000')
295
292
  }, 90000)
@@ -233,6 +233,7 @@ async function processDevices (from, to, devices, events, routes, userData) {
233
233
  async function findEventsPosition (from, to, devices, events, routes, userData) {
234
234
  for (const d of devices) {
235
235
  const deviceEvents = events.filter(e => e.deviceId === d.id && e.positionId)
236
+ console.log(d.name, deviceEvents.length)
236
237
  if (deviceEvents.length > 0) {
237
238
  const positions = routes.filter(p => p.deviceId === d.id)
238
239
  for (const a of deviceEvents) {
@@ -256,8 +257,6 @@ async function findEventsPosition (from, to, devices, events, routes, userData)
256
257
  a.driver = (driver && driver.name) || a.position.attributes.driverUniqueId
257
258
  }
258
259
  a.deviceName = d.name
259
-
260
- return pIndex
261
260
  }
262
261
  }
263
262
  deviceEvents.sort((a, b) => new Date(a.position.fixTime) - new Date(b.position.fixTime))
@@ -351,6 +350,7 @@ function calculateEventData (positions, pIndex, alert, device, geofence, userDat
351
350
  let dist = 0
352
351
  while (pIndex + 1 < positions.length) {
353
352
  pIndex++
353
+ console.log(pIndex)
354
354
  dist += distance.default(point([endEventPosition.longitude, endEventPosition.latitude]),
355
355
  point([positions[pIndex].longitude, positions[pIndex].latitude]))
356
356
  endEventPosition = positions[pIndex]
@@ -358,6 +358,7 @@ function calculateEventData (positions, pIndex, alert, device, geofence, userDat
358
358
  alert.eventTime = new Date(endEventPosition.fixTime) - new Date(alert.position.fixTime)
359
359
  alert.attributes.maxSpeed = maxSpeed
360
360
  alert.distance = dist
361
+ console.log(alert)
361
362
  break
362
363
  } else {
363
364
  if (maxSpeed < endEventPosition.speed) {