fleetmap-reports 1.0.508 → 1.0.509
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/index.test.js +18 -3
- package/src/speeding-report.js +2 -2
package/package.json
CHANGED
package/src/index.test.js
CHANGED
|
@@ -6,7 +6,7 @@ async function getSpeedingReport (report, userData) {
|
|
|
6
6
|
new Date(Date.UTC(2022, 1, 17, 0, 0, 0, 0)),
|
|
7
7
|
new Date(Date.UTC(2022, 1, 17, 23, 59, 59, 0)),
|
|
8
8
|
userData)
|
|
9
|
-
|
|
9
|
+
|
|
10
10
|
const device = data[0].devices.find(d => d.device.id === 22326)
|
|
11
11
|
const totalDistance = device.alerts.reduce((a, b) => a + b.distance, 0)
|
|
12
12
|
const totalEventTime = device.alerts.reduce((a, b) => a + b.eventTime, 0)
|
|
@@ -16,7 +16,7 @@ async function getSpeedingReport (report, userData) {
|
|
|
16
16
|
// eslint-disable-next-line no-undef
|
|
17
17
|
describe('Test_Reports', function () {
|
|
18
18
|
// eslint-disable-next-line no-undef
|
|
19
|
-
it('
|
|
19
|
+
it('works with road speed limits', async () => {
|
|
20
20
|
const report = await getReports()
|
|
21
21
|
const userData = await report.getUserData()
|
|
22
22
|
userData.roadSpeedLimits = true
|
|
@@ -25,6 +25,21 @@ describe('Test_Reports', function () {
|
|
|
25
25
|
assert.equal(totalDistance, 36.63687856826021) // Total Kms
|
|
26
26
|
assert.equal(totalEventTime, 1524000) // Total Duration
|
|
27
27
|
}, 200000)
|
|
28
|
+
|
|
29
|
+
it('works by device speed limit', async () => {
|
|
30
|
+
const report = await getReports()
|
|
31
|
+
const userData = await report.getUserData()
|
|
32
|
+
userData.roadSpeedLimits = false
|
|
33
|
+
userData.customSpeed = 40
|
|
34
|
+
const data = await report.speedingReport(
|
|
35
|
+
new Date(Date.UTC(2022, 1, 17, 0, 0, 0, 0)),
|
|
36
|
+
new Date(Date.UTC(2022, 1, 17, 23, 59, 59, 0)),
|
|
37
|
+
userData)
|
|
38
|
+
const device = data[0].devices.find(d => d.device.id === 22326)
|
|
39
|
+
console.log('device', device)
|
|
40
|
+
assert.equal(device.alerts.length, 75) // Total Alerts
|
|
41
|
+
}, 900000)
|
|
42
|
+
|
|
28
43
|
// eslint-disable-next-line no-undef
|
|
29
44
|
it('Speeding with custom speed', async () => {
|
|
30
45
|
const report = await getReports()
|
|
@@ -36,7 +51,7 @@ describe('Test_Reports', function () {
|
|
|
36
51
|
assert.equal(device.alerts.length, 13) // Total Alerts
|
|
37
52
|
assert.equal(totalDistance, 46.64576895855739) // Total Kms
|
|
38
53
|
assert.equal(totalEventTime, 1402000) // Total Duration
|
|
39
|
-
},
|
|
54
|
+
}, 999990000)
|
|
40
55
|
// eslint-disable-next-line no-undef
|
|
41
56
|
it('Trip by device', async () => {
|
|
42
57
|
const report = await getReports()
|
package/src/speeding-report.js
CHANGED
|
@@ -260,6 +260,8 @@ async function findEventsPosition (from, to, devices, events, routes, userData)
|
|
|
260
260
|
a.driver = (driver && driver.name) || a.position.attributes.driverUniqueId
|
|
261
261
|
}
|
|
262
262
|
a.deviceName = d.name
|
|
263
|
+
} else {
|
|
264
|
+
console.error('cant find position for event', a)
|
|
263
265
|
}
|
|
264
266
|
}
|
|
265
267
|
deviceEvents.sort((a, b) => new Date(a.position.fixTime) - new Date(b.position.fixTime))
|
|
@@ -361,7 +363,6 @@ function calculateEventData (positions, pIndex, alert, device, geofence, userDat
|
|
|
361
363
|
let dist = 0
|
|
362
364
|
while (pIndex + 1 < positions.length) {
|
|
363
365
|
pIndex++
|
|
364
|
-
console.log(pIndex)
|
|
365
366
|
dist += distance.default(point([endEventPosition.longitude, endEventPosition.latitude]),
|
|
366
367
|
point([positions[pIndex].longitude, positions[pIndex].latitude]))
|
|
367
368
|
endEventPosition = positions[pIndex]
|
|
@@ -369,7 +370,6 @@ function calculateEventData (positions, pIndex, alert, device, geofence, userDat
|
|
|
369
370
|
alert.eventTime = new Date(endEventPosition.fixTime) - new Date(alert.position.fixTime)
|
|
370
371
|
alert.attributes.maxSpeed = maxSpeed
|
|
371
372
|
alert.distance = dist
|
|
372
|
-
console.log(alert)
|
|
373
373
|
break
|
|
374
374
|
} else {
|
|
375
375
|
if (maxSpeed < endEventPosition.speed) {
|