fleetmap-reports 1.0.859 → 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 +32 -27
- package/src/tests/speeding.test.js +1 -1
package/package.json
CHANGED
package/src/speeding-report.js
CHANGED
|
@@ -299,7 +299,7 @@ async function getCustomSpeedLimitEvents (devices, routes, customSpeed) {
|
|
|
299
299
|
return events
|
|
300
300
|
}
|
|
301
301
|
|
|
302
|
-
async function getRoadSpeedLimits(devices, routes, threshold, minimumMinutes = 0) {
|
|
302
|
+
async function getRoadSpeedLimits (devices, routes, threshold, minimumMinutes = 0) {
|
|
303
303
|
const position = routes[0]
|
|
304
304
|
const country = crg.get_country(position.latitude, position.longitude)
|
|
305
305
|
const config = {
|
|
@@ -309,41 +309,46 @@ async function getRoadSpeedLimits(devices, routes, threshold, minimumMinutes = 0
|
|
|
309
309
|
return method(devices, routes, threshold, minimumMinutes)
|
|
310
310
|
}
|
|
311
311
|
|
|
312
|
-
async function getOSMSpeedingEvents(devices, routes, threshold, minimumMinutes = 0) {
|
|
312
|
+
async function getOSMSpeedingEvents (devices, routes, threshold, minimumMinutes = 0) {
|
|
313
313
|
const chunk = 1000
|
|
314
314
|
const events = []
|
|
315
315
|
for (const d of devices) {
|
|
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)
|
|
@@ -359,7 +364,7 @@ async function getOSMSpeedingEvents(devices, routes, threshold, minimumMinutes =
|
|
|
359
364
|
cur.attributes = { speedLimit: cur.speed_limit, speed: cur.speed, maxSpeed: cur.speed }
|
|
360
365
|
cur.eventTime = 0
|
|
361
366
|
cur.distance = 0
|
|
362
|
-
cur.position = {...cur}
|
|
367
|
+
cur.position = { ...cur }
|
|
363
368
|
acc.push(cur)
|
|
364
369
|
}
|
|
365
370
|
return acc
|
|
@@ -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
|