fleetmap-reports 1.0.862 → 1.0.864
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 +31 -27
- package/src/tests/speeding.test.js +1 -1
package/package.json
CHANGED
package/src/speeding-report.js
CHANGED
|
@@ -316,42 +316,46 @@ 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 + (threshold || 0)) < 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
|
-
cur.overSpeeding = cur.speed * 1.852 > cur.speed_limit + (threshold || 0)
|
|
350
354
|
const last = acc.length && acc.slice(-1)[0]
|
|
351
|
-
if (cur.
|
|
355
|
+
if (last && new Date(cur.fixTime) - new Date(src[idx - 1]) < 1000 * 60 * 2) {
|
|
352
356
|
last.eventTime = new Date(cur.fixTime) - new Date(last.fixTime)
|
|
353
357
|
last.attributes.maxSpeed = Math.max(last.attributes.maxSpeed, cur.speed)
|
|
354
|
-
last.distance
|
|
358
|
+
last.distance += distance.default(point([cur.longitude, cur.latitude]), point([src[idx - 1].longitude, src[idx - 1].latitude]))
|
|
355
359
|
} else if (cur.overSpeeding) {
|
|
356
360
|
cur.positionId = cur && cur.id
|
|
357
361
|
cur.roadSpeedLimit = cur.speed_limit
|
|
@@ -415,7 +419,7 @@ async function getHereEvents (devices, routes, threshold, minimumMinutes = 0) {
|
|
|
415
419
|
events.push(...reduced)
|
|
416
420
|
resolve()
|
|
417
421
|
}).catch(e => {
|
|
418
|
-
console.warn('route match, moving on', e.message)
|
|
422
|
+
console.warn('route match, moving on', e.message, e.response && e.response.data)
|
|
419
423
|
resolve()
|
|
420
424
|
})
|
|
421
425
|
}))
|
|
@@ -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
|