fleetmap-reports 1.0.862 → 1.0.863
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 +29 -24
- package/src/tests/speeding.test.js +1 -1
package/package.json
CHANGED
package/src/speeding-report.js
CHANGED
|
@@ -316,34 +316,39 @@ async function getOSMSpeedingEvents (devices, routes, threshold, minimumMinutes
|
|
|
316
316
|
const route = routes.filter(r => r.deviceId === d.id)
|
|
317
317
|
const results = []
|
|
318
318
|
for (let i = 0; i < route.length; i += chunk) {
|
|
319
|
-
const apiKey = process.env.geoapifyKey
|
|
320
319
|
const slice = route.slice(i, i + chunk)
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
320
|
+
// eslint-disable-next-line camelcase
|
|
321
|
+
const { matched_points, edges } = await axios.post('https://valhalla1.openstreetmap.de/trace_attributes', {
|
|
322
|
+
costing: 'auto',
|
|
323
|
+
'shape_match type': 'map_snap',
|
|
324
|
+
filters: {
|
|
325
|
+
attributes: [
|
|
326
|
+
'admin.country_code',
|
|
327
|
+
'admin.country_text',
|
|
328
|
+
'admin.state_code',
|
|
329
|
+
'admin.state_text',
|
|
330
|
+
'edge.names',
|
|
331
|
+
'edge.way_id',
|
|
332
|
+
'edge.speed_limit',
|
|
333
|
+
'matched.point',
|
|
334
|
+
'matched.type',
|
|
335
|
+
'matched.edge_index'
|
|
336
|
+
],
|
|
337
|
+
action: 'include'
|
|
338
|
+
},
|
|
339
|
+
shape: slice.map(p => ({
|
|
340
|
+
lon: p.longitude, lat: p.latitude
|
|
327
341
|
}))
|
|
328
342
|
}).then(r => r.data)
|
|
329
343
|
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
const
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
344
|
+
// eslint-disable-next-line camelcase
|
|
345
|
+
matched_points.forEach((mp, mIndex) => {
|
|
346
|
+
const edge = edges[mp.edge_index]
|
|
347
|
+
const position = route[mIndex + i]
|
|
348
|
+
if (edge && edge.speed_limit < position.speed * 1.852) {
|
|
349
|
+
results.push({ ...mp, ...edge, ...position })
|
|
336
350
|
}
|
|
337
|
-
|
|
338
|
-
const position = route[wp.original_index + i]
|
|
339
|
-
if (!step) {
|
|
340
|
-
console.log('ignoring', wp.step_index, wp.leg_index, properties.legs[0].steps[wp.step_index], properties.legs[0].steps.length)
|
|
341
|
-
continue
|
|
342
|
-
}
|
|
343
|
-
if (wp.match_type !== 'unmatched' && step.speed_limit < position.speed * 1.852) {
|
|
344
|
-
results.push({ ...wp, ...step, ...position })
|
|
345
|
-
}
|
|
346
|
-
}
|
|
351
|
+
})
|
|
347
352
|
}
|
|
348
353
|
const reduced = results.reduce((acc, cur, idx, src) => {
|
|
349
354
|
cur.overSpeeding = cur.speed * 1.852 > cur.speed_limit + (threshold || 0)
|
|
@@ -415,7 +420,7 @@ async function getHereEvents (devices, routes, threshold, minimumMinutes = 0) {
|
|
|
415
420
|
events.push(...reduced)
|
|
416
421
|
resolve()
|
|
417
422
|
}).catch(e => {
|
|
418
|
-
console.warn('route match, moving on', e.message)
|
|
423
|
+
console.warn('route match, moving on', e.message, e.response && e.response.data)
|
|
419
424
|
resolve()
|
|
420
425
|
})
|
|
421
426
|
}))
|
|
@@ -26,7 +26,7 @@ describe('speeding tests', function () {
|
|
|
26
26
|
userData.minimumIdleMinutes = 1
|
|
27
27
|
const r = await getSpeedingReport(report, userData)
|
|
28
28
|
r.device.alerts.forEach(a => assert.equal(true, a.eventTime >= 60000))
|
|
29
|
-
assert.equal(r.device.alerts.length,
|
|
29
|
+
assert.equal(r.device.alerts.length, 2) // Total Alerts
|
|
30
30
|
}, 200000)
|
|
31
31
|
|
|
32
32
|
// eslint-disable-next-line no-undef
|