fleetmap-reports 1.0.431 → 1.0.432
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 +32 -29
package/package.json
CHANGED
package/src/speeding-report.js
CHANGED
|
@@ -276,42 +276,45 @@ async function getCustomSpeedLimitEvents (devices, routes, customSpeed) {
|
|
|
276
276
|
async function getHereEvents (devices, routes, threshold) {
|
|
277
277
|
console.log('here speed limit events')
|
|
278
278
|
const events = []
|
|
279
|
-
|
|
279
|
+
const promises = devices.map(d => new Promise((resolve) => {
|
|
280
280
|
const positions = routes.filter(p => p.deviceId === d.id)
|
|
281
281
|
if (!positions.length) {
|
|
282
282
|
console.log('no positions on device', d.name)
|
|
283
|
-
|
|
283
|
+
resolve()
|
|
284
284
|
}
|
|
285
285
|
let hereAlerts = null
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
}
|
|
297
|
-
})
|
|
298
|
-
if (!hereAlerts.length) {
|
|
299
|
-
console.log('empty array after filter on device', d.name)
|
|
300
|
-
continue
|
|
301
|
-
}
|
|
302
|
-
const reduced = hereAlerts.length < 2
|
|
303
|
-
? hereAlerts
|
|
304
|
-
: hereAlerts.reduce((acc, cur, idx, src) => {
|
|
305
|
-
if (idx === 1) {
|
|
306
|
-
return [cur]
|
|
307
|
-
}
|
|
308
|
-
if (cur.timestamp - src[idx - 1].timestamp > 300000 || cur.roadSpeedLimit !== src[idx - 1].roadSpeedLimit) {
|
|
309
|
-
return acc.concat(cur)
|
|
286
|
+
here.routeMatch(positions).then(results => {
|
|
287
|
+
hereAlerts = results.filter(r => r.currentSpeedKmh > (parseInt(r.speedLimit) + threshold)).map(r => {
|
|
288
|
+
const position = positions.find(p => new Date(p.fixTime).getTime() === r.timestamp)
|
|
289
|
+
return {
|
|
290
|
+
...r,
|
|
291
|
+
roadSpeedLimit: r.speedLimit,
|
|
292
|
+
deviceId: d.id,
|
|
293
|
+
position,
|
|
294
|
+
positionId: position && position.id,
|
|
295
|
+
attributes: {speedLimit: r.speedLimit, speed: r.currentSpeedKmh / 1.85200}
|
|
310
296
|
}
|
|
311
|
-
return acc
|
|
312
297
|
})
|
|
313
|
-
|
|
314
|
-
|
|
298
|
+
if (!hereAlerts.length) {
|
|
299
|
+
console.log('empty array after filter on device', d.name)
|
|
300
|
+
resolve()
|
|
301
|
+
}
|
|
302
|
+
const reduced = hereAlerts.length < 2
|
|
303
|
+
? hereAlerts
|
|
304
|
+
: hereAlerts.reduce((acc, cur, idx, src) => {
|
|
305
|
+
if (idx === 1) {
|
|
306
|
+
return [cur]
|
|
307
|
+
}
|
|
308
|
+
if (cur.timestamp - src[idx - 1].timestamp > 300000 || cur.roadSpeedLimit !== src[idx - 1].roadSpeedLimit) {
|
|
309
|
+
return acc.concat(cur)
|
|
310
|
+
}
|
|
311
|
+
return acc
|
|
312
|
+
})
|
|
313
|
+
events.push(...reduced)
|
|
314
|
+
resolve()
|
|
315
|
+
})
|
|
316
|
+
}))
|
|
317
|
+
await Promise.all(promises)
|
|
315
318
|
return events
|
|
316
319
|
}
|
|
317
320
|
|