fleetmap-reports 1.0.474 → 1.0.476
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 +6 -3
- package/src/speeding-report.js +8 -3
package/package.json
CHANGED
package/src/index.test.js
CHANGED
|
@@ -8,8 +8,10 @@ async function getSpeedingReport (report, userData) {
|
|
|
8
8
|
userData)
|
|
9
9
|
assert.equal(data.length, 1)
|
|
10
10
|
const device = data[0].devices[0]
|
|
11
|
+
console.log(device)
|
|
11
12
|
const totalDistance = device.alerts.reduce((a, b) => a + b.distance, 0)
|
|
12
13
|
const totalEventTime = device.alerts.reduce((a, b) => a + b.eventTime, 0)
|
|
14
|
+
console.log(device.alerts)
|
|
13
15
|
return { device, totalDistance, totalEventTime }
|
|
14
16
|
}
|
|
15
17
|
|
|
@@ -21,9 +23,10 @@ describe('Test_Reports', function () {
|
|
|
21
23
|
const userData = await report.getUserData()
|
|
22
24
|
userData.roadSpeedLimits = true
|
|
23
25
|
const { device, totalDistance, totalEventTime } = await getSpeedingReport(report, userData)
|
|
24
|
-
assert.equal(device.alerts.length,
|
|
25
|
-
|
|
26
|
-
assert.equal(
|
|
26
|
+
assert.equal(device.alerts.length, 11) // Total Alerts
|
|
27
|
+
console.log(device.alerts)
|
|
28
|
+
assert.equal(totalDistance, 74.71054403083238) // Total Kms
|
|
29
|
+
assert.equal(totalEventTime, 3009000) // Total Duration
|
|
27
30
|
}, 200000)
|
|
28
31
|
// eslint-disable-next-line no-undef
|
|
29
32
|
it('Speeding with custom speed', async () => {
|
package/src/speeding-report.js
CHANGED
|
@@ -287,13 +287,15 @@ async function getHereEvents (devices, routes, threshold) {
|
|
|
287
287
|
cur.position = positions.find(p => new Date(p.fixTime).getTime() === cur.timestamp)
|
|
288
288
|
if (previous && previous.speedLimit === cur.speedLimit) {
|
|
289
289
|
previous.eventTime += cur.timestamp - previous.timestamp
|
|
290
|
-
previous.attributes.maxSpeed = Math.max(previous.attributes.maxSpeed, cur.
|
|
290
|
+
previous.attributes.maxSpeed = Math.max(previous.attributes.maxSpeed, cur.position.speed)
|
|
291
291
|
previous.distance += distance.default(point([cur.position.longitude, cur.position.latitude]), point([previous.position.longitude, previous.position.latitude]))
|
|
292
292
|
} else {
|
|
293
293
|
cur.positionId = cur.position && cur.position.id
|
|
294
294
|
cur.roadSpeedLimit = cur.speedLimit
|
|
295
295
|
cur.deviceId = d.id
|
|
296
|
-
cur.attributes = { speedLimit: cur.speedLimit, speed: cur.currentSpeedKmh / 1.85200 }
|
|
296
|
+
cur.attributes = { speedLimit: cur.speedLimit, speed: cur.currentSpeedKmh / 1.85200, maxSpeed: cur.position.speed }
|
|
297
|
+
cur.eventTime = 0
|
|
298
|
+
cur.distance = 0
|
|
297
299
|
return acc.concat(cur)
|
|
298
300
|
}
|
|
299
301
|
}
|
|
@@ -318,7 +320,10 @@ function calculateEventData (positions, pIndex, alert, device, geofence, userDat
|
|
|
318
320
|
let endEventPosition = alert.position
|
|
319
321
|
let maxSpeed = alert.position.speed
|
|
320
322
|
let dist = 0
|
|
321
|
-
if (alert.eventTime) {
|
|
323
|
+
if (alert.eventTime) {
|
|
324
|
+
console.log('ignoring')
|
|
325
|
+
return -1
|
|
326
|
+
}
|
|
322
327
|
while (pIndex + 1 < positions.length) {
|
|
323
328
|
pIndex++
|
|
324
329
|
dist += distance.default(point([endEventPosition.longitude, endEventPosition.latitude]),
|