fleetmap-reports 1.0.593 → 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 +1 -1
- package/src/speeding-report.js +4 -4
- package/src/tests/index.test.js +13 -48
- package/src/tests/speeding.test.js +62 -0
- package/src/util/route.js +16 -0
- package/src/zone-report.js +11 -5
package/package.json
CHANGED
package/src/speeding-report.js
CHANGED
|
@@ -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
|
|
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
|
package/src/tests/index.test.js
CHANGED
|
@@ -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()
|
|
@@ -412,4 +364,17 @@ describe('Test_Reports', function () {
|
|
|
412
364
|
assert.equal(device.geofences[0].totalTime, '28777')
|
|
413
365
|
assert.equal(device.geofences[0].geofenceName, 'Casa João')
|
|
414
366
|
}, 30000)
|
|
367
|
+
// eslint-disable-next-line no-undef
|
|
368
|
+
it('Zone Report With Stops', async () => {
|
|
369
|
+
const report = await getReports()
|
|
370
|
+
const userData = await report.getUserData()
|
|
371
|
+
userData.onlyWithStop = true
|
|
372
|
+
const data = await report.zoneReport(new Date(2023, 1, 1, 0, 0, 0, 0),
|
|
373
|
+
new Date(2023, 1, 5, 23, 59, 59, 0),
|
|
374
|
+
userData)
|
|
375
|
+
|
|
376
|
+
assert.equal(data.length, 1)
|
|
377
|
+
const device = data[0].devices.find(d => d.device.id === 82063)
|
|
378
|
+
assert.equal(device.geofences.length, 15)
|
|
379
|
+
}, 30000)
|
|
415
380
|
})
|
|
@@ -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
|
+
})
|
package/src/util/route.js
CHANGED
|
@@ -36,4 +36,20 @@ function getIdleEvents (route, driver) {
|
|
|
36
36
|
|
|
37
37
|
return idleEvents
|
|
38
38
|
}
|
|
39
|
+
|
|
40
|
+
function filterPositions (positions) {
|
|
41
|
+
return positions.filter(filterPosition)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function filterPosition (p) {
|
|
45
|
+
if (p.valid === false) {
|
|
46
|
+
return p.attributes.ignition || p.attributes.motion
|
|
47
|
+
}
|
|
48
|
+
if (p.protocol === 'osmand') {
|
|
49
|
+
return !(p.attributes.event >= 200 || p.attributes.event === 30)
|
|
50
|
+
}
|
|
51
|
+
return true
|
|
52
|
+
}
|
|
53
|
+
|
|
39
54
|
exports.getIdleEvents = getIdleEvents
|
|
55
|
+
exports.filterPositions = filterPositions
|
package/src/zone-report.js
CHANGED
|
@@ -13,6 +13,7 @@ const booleanPointInPolygon = require('@turf/boolean-point-in-polygon')
|
|
|
13
13
|
const distance = require('@turf/distance')
|
|
14
14
|
const axios = require('axios')
|
|
15
15
|
const { processServerSide } = require('./util')
|
|
16
|
+
const { filterPositions } = require('./util/route')
|
|
16
17
|
const sliceSize = 200
|
|
17
18
|
const deviceChunk = 5
|
|
18
19
|
const fileName = 'ZoneReport'
|
|
@@ -68,11 +69,13 @@ async function createZoneReport (from, to, userData, traccar) {
|
|
|
68
69
|
traccar, from, to, slice, true, false, false, false,
|
|
69
70
|
deviceCount, devices.length, sliceSize, deviceChunk, undefined)
|
|
70
71
|
|
|
71
|
-
const
|
|
72
|
+
const route = filterPositions(data.route)
|
|
73
|
+
|
|
74
|
+
const alerts = getInAndOutEvents(slice, route, userData)
|
|
72
75
|
console.log('Geofence Enter/Exit Alerts:' + alerts.length)
|
|
73
76
|
|
|
74
77
|
if (alerts.length) {
|
|
75
|
-
allData.devices.push(...await processDevices(from, to, devices, userData, { alerts, route
|
|
78
|
+
allData.devices.push(...await processDevices(from, to, devices, userData, { alerts, route }))
|
|
76
79
|
}
|
|
77
80
|
deviceCount = deviceCount + slice.length
|
|
78
81
|
}
|
|
@@ -87,6 +90,8 @@ async function processDevices (from, to, devices, userData, data) {
|
|
|
87
90
|
|
|
88
91
|
for (const d of devices) {
|
|
89
92
|
const alerts = data.alerts.filter(t => t.deviceId === d.id)
|
|
93
|
+
const deviceRoute = data.route.filter(p => p.deviceId === d.id)
|
|
94
|
+
|
|
90
95
|
if (alerts.length > 0) {
|
|
91
96
|
const zoneInOutData = []
|
|
92
97
|
const zoneInData = {}
|
|
@@ -101,9 +106,8 @@ async function processDevices (from, to, devices, userData, data) {
|
|
|
101
106
|
const geofence = userData.geofences.find(g => g.id === a.geofenceId)
|
|
102
107
|
if (zoneInData[a.geofenceId]) {
|
|
103
108
|
const totalInTime = moment(a.position.fixTime).diff(moment(zoneInData[a.geofenceId].position.fixTime), 'seconds')
|
|
104
|
-
const route =
|
|
109
|
+
const route = deviceRoute.filter(p => new Date(p.fixTime).getTime() >= new Date(zoneInData[a.geofenceId].position.fixTime).getTime() &&
|
|
105
110
|
new Date(p.fixTime).getTime() <= new Date(a.position.fixTime).getTime())
|
|
106
|
-
console.log(route)
|
|
107
111
|
if (geofence) {
|
|
108
112
|
zoneInOutData.push({
|
|
109
113
|
inTime: zoneInData[a.geofenceId].position,
|
|
@@ -167,6 +171,9 @@ function getInAndOutEvents (devices, route, userData) {
|
|
|
167
171
|
|
|
168
172
|
const entryMap = []
|
|
169
173
|
routePoints.forEach(p => {
|
|
174
|
+
if (!p.properties.position.valid) {
|
|
175
|
+
return
|
|
176
|
+
}
|
|
170
177
|
geofencesFeatures.forEach(g => {
|
|
171
178
|
if (g.geometry.type === 'Polygon') {
|
|
172
179
|
if (booleanPointInPolygon.default(p, g)) {
|
|
@@ -343,7 +350,6 @@ function exportZoneReportToExcel (userData, reportData) {
|
|
|
343
350
|
}
|
|
344
351
|
}))
|
|
345
352
|
})
|
|
346
|
-
console.log(data)
|
|
347
353
|
return {
|
|
348
354
|
headers,
|
|
349
355
|
data,
|