fleetmap-reports 1.0.594 → 1.0.595

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.594",
3
+ "version": "1.0.595",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -135,7 +135,7 @@ async function getEvents (traccarInstance, from, to, devices, userData, deviceCo
135
135
 
136
136
  const events = []
137
137
  if (userData.roadSpeedLimits) {
138
- const hereResults = await getHereEvents(devices, routes, userData.maxSpeedThreshold)
138
+ const hereResults = await getHereEvents(devices, routes, userData.maxSpeedThreshold, userData.minimumIdleTime)
139
139
  console.log('got', hereResults.length, 'from here')
140
140
  events.push(...hereResults)
141
141
  } else if (!userData.useVehicleSpeedLimit && userData.customSpeed) {
@@ -297,7 +297,7 @@ async function getCustomSpeedLimitEvents (devices, routes, customSpeed) {
297
297
  return events
298
298
  }
299
299
 
300
- async function getHereEvents (devices, routes, threshold) {
300
+ async function getHereEvents (devices, routes, threshold, minimumMinutes = 0) {
301
301
  try {
302
302
  console.log('PROCESS_HERE_EVENTS', process.env.PROCESS_HERE_EVENTS)
303
303
  console.log('here speed limit events', devices.length, 'devices')
@@ -348,13 +348,13 @@ async function getHereEvents (devices, routes, threshold) {
348
348
  })
349
349
  }))
350
350
  await Promise.all(promises)
351
- return events
351
+ return events.filter(e => e.eventTime >= minimumMinutes * 60 * 1000)
352
352
  } catch (e) {
353
353
  console.error(e)
354
354
  }
355
355
  }
356
356
 
357
- function calculateEventData (positions, pIndex, alert, device, geofence, userData) {
357
+ function calculateEventData (positions, pIndex, alert, device, geofence) {
358
358
  let endEventPosition = alert.position
359
359
  let maxSpeed = alert.position.speed
360
360
  let dist = 0
@@ -3,18 +3,6 @@ const { getReports } = require('./index')
3
3
  const assert = require('assert')
4
4
  const utils = require('../util/utils')
5
5
 
6
- async function getSpeedingReport (report, userData) {
7
- const data = await report.speedingReport(
8
- new Date(Date.UTC(2022, 1, 17, 0, 0, 0, 0)),
9
- new Date(Date.UTC(2022, 1, 17, 23, 59, 59, 0)),
10
- userData)
11
-
12
- const device = data[0].devices.find(d => d.device.id === 22326)
13
- const totalDistance = device.alerts.reduce((a, b) => a + b.distance, 0)
14
- const totalEventTime = device.alerts.reduce((a, b) => a + b.eventTime, 0)
15
- return { device, totalDistance, totalEventTime }
16
- }
17
-
18
6
  // eslint-disable-next-line no-undef
19
7
  describe('Test_Reports', function () {
20
8
  it('converts to pdf', async () => {
@@ -35,42 +23,6 @@ describe('Test_Reports', function () {
35
23
  console.log(utils.convertToLocaleString(new Date(), 'es-CL', 'Europe/Madrid'))
36
24
  })
37
25
 
38
- // eslint-disable-next-line no-undef
39
- it('works with road speed limits', async () => {
40
- const report = await getReports()
41
- const userData = await report.getUserData()
42
- userData.roadSpeedLimits = true
43
- const { device } = await getSpeedingReport(report, userData)
44
- assert.equal(device.alerts.length, 104) // Total Alerts
45
- // assert.equal(totalDistance, 36.63687856826021) // Total Kms
46
- // assert.equal(totalEventTime, 1524000) // Total Duration
47
- }, 200000)
48
- // eslint-disable-next-line no-undef
49
- it('works by device speed limit', async () => {
50
- const report = await getReports()
51
- const userData = await report.getUserData()
52
- userData.roadSpeedLimits = false
53
- userData.customSpeed = false
54
- userData.useVehicleSpeedLimit = true
55
- const data = await report.speedingReport(
56
- new Date(Date.UTC(2022, 9, 22, 0, 0, 0, 0)),
57
- new Date(Date.UTC(2022, 9, 23, 23, 59, 59, 0)),
58
- userData)
59
- assert.equal(data[0].devices.length, 0)
60
- }, 900000)
61
-
62
- // eslint-disable-next-line no-undef
63
- it('Speeding with custom speed', async () => {
64
- const report = await getReports()
65
- const userData = await report.getUserData()
66
-
67
- userData.useVehicleSpeedLimit = false
68
- userData.customSpeed = 100
69
- const { device, totalDistance, totalEventTime } = await getSpeedingReport(report, userData)
70
- assert.equal(device.alerts.length, 13) // Total Alerts
71
- assert.equal(totalDistance, 46.64576895855739) // Total Kms
72
- assert.equal(totalEventTime, 1402000) // Total Duration
73
- }, 999990000)
74
26
  // eslint-disable-next-line no-undef
75
27
  it('Trip by device', async () => {
76
28
  const report = await getReports()
@@ -0,0 +1,62 @@
1
+ const { getReports } = require('./index')
2
+ const assert = require('assert')
3
+
4
+ async function getSpeedingReport (report, userData) {
5
+ const data = await report.speedingReport(
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
+ userData)
9
+
10
+ const device = data[0].devices.find(d => d.device.id === 22326)
11
+ const totalDistance = device && device.alerts.reduce((a, b) => a + b.distance, 0)
12
+ const totalEventTime = device && device.alerts.reduce((a, b) => a + b.eventTime, 0)
13
+ return { device, totalDistance, totalEventTime }
14
+ }
15
+ // eslint-disable-next-line no-undef
16
+ describe('speeding tests', function () {
17
+ // eslint-disable-next-line no-undef
18
+ it('works with road speed limits', async () => {
19
+ const report = await getReports()
20
+ const userData = await report.getUserData()
21
+ userData.roadSpeedLimits = true
22
+ const { device } = await getSpeedingReport(report, userData)
23
+ assert.equal(device.alerts.length, 104) // Total Alerts
24
+ console.log(device.alerts)
25
+
26
+ userData.minimumIdleTime = 1
27
+ const r = await getSpeedingReport(report, userData)
28
+ r.device.alerts.forEach(a => assert.equal(true, a.eventTime >= 60000))
29
+ assert.equal(r.device.alerts.length, 6) // Total Alerts
30
+ }, 200000)
31
+
32
+ // eslint-disable-next-line no-undef
33
+ it('works by device speed limit', async () => {
34
+ const report = await getReports()
35
+ const userData = await report.getUserData()
36
+ userData.roadSpeedLimits = false
37
+ userData.customSpeed = false
38
+ userData.useVehicleSpeedLimit = true
39
+ const data = await report.speedingReport(
40
+ new Date(Date.UTC(2022, 9, 22, 0, 0, 0, 0)),
41
+ new Date(Date.UTC(2022, 9, 23, 23, 59, 59, 0)),
42
+ userData)
43
+ assert.equal(data[0].devices.length, 0)
44
+ }, 900000)
45
+
46
+ // eslint-disable-next-line no-undef
47
+ it('Speeding with custom speed', async () => {
48
+ const report = await getReports()
49
+ const userData = await report.getUserData()
50
+
51
+ userData.useVehicleSpeedLimit = false
52
+ userData.customSpeed = 100
53
+ const {
54
+ device,
55
+ totalDistance,
56
+ totalEventTime
57
+ } = await getSpeedingReport(report, userData)
58
+ assert.equal(device.alerts.length, 13) // Total Alerts
59
+ assert.equal(totalDistance, 46.64576895855739) // Total Kms
60
+ assert.equal(totalEventTime, 1402000) // Total Duration
61
+ }, 999990000)
62
+ })