fleetmap-reports 1.0.866 → 1.0.868
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 +50 -36
- package/src/tests/speeding.test.js +1 -1
package/package.json
CHANGED
package/src/speeding-report.js
CHANGED
|
@@ -299,18 +299,23 @@ async function getCustomSpeedLimitEvents (devices, routes, customSpeed) {
|
|
|
299
299
|
return events
|
|
300
300
|
}
|
|
301
301
|
|
|
302
|
+
function getCountry (position) {
|
|
303
|
+
const country = crg.get_country(position.latitude, position.longitude)
|
|
304
|
+
return country && country.code
|
|
305
|
+
}
|
|
306
|
+
|
|
302
307
|
async function getRoadSpeedLimits (devices, routes, threshold, minimumMinutes = 0) {
|
|
303
308
|
const position = routes[0]
|
|
304
|
-
const country =
|
|
309
|
+
const country = getCountry(position)
|
|
305
310
|
const config = {
|
|
306
311
|
CHL: getOSMSpeedingEvents,
|
|
307
312
|
MAR: getOSMSpeedingEvents
|
|
308
313
|
}
|
|
309
|
-
const method = config[country
|
|
310
|
-
return method(devices, routes, threshold, minimumMinutes)
|
|
314
|
+
const method = config[country] || getHereEvents
|
|
315
|
+
return method(devices, routes, threshold, minimumMinutes, country && country.code)
|
|
311
316
|
}
|
|
312
317
|
|
|
313
|
-
async function getOSMSpeedingEvents (devices, routes, threshold, minimumMinutes = 0) {
|
|
318
|
+
async function getOSMSpeedingEvents (devices, routes, threshold, minimumMinutes = 0, country) {
|
|
314
319
|
const chunk = 1000
|
|
315
320
|
const events = []
|
|
316
321
|
for (const d of devices) {
|
|
@@ -318,38 +323,47 @@ async function getOSMSpeedingEvents (devices, routes, threshold, minimumMinutes
|
|
|
318
323
|
const results = []
|
|
319
324
|
for (let i = 0; i < route.length; i += chunk) {
|
|
320
325
|
const slice = route.slice(i, i + chunk)
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
'
|
|
329
|
-
'
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
326
|
+
try {
|
|
327
|
+
const {
|
|
328
|
+
// eslint-disable-next-line camelcase
|
|
329
|
+
matched_points,
|
|
330
|
+
edges
|
|
331
|
+
} = await axios.post(`http://valhalla-${getCountry(slice[0]) || country}.pinme.io:8002/trace_attributes`,
|
|
332
|
+
{
|
|
333
|
+
costing: 'auto',
|
|
334
|
+
shape_match: 'map_snap',
|
|
335
|
+
filters: {
|
|
336
|
+
attributes: [
|
|
337
|
+
'admin.country_code',
|
|
338
|
+
'admin.country_text',
|
|
339
|
+
'admin.state_code',
|
|
340
|
+
'admin.state_text',
|
|
341
|
+
'edge.names',
|
|
342
|
+
'edge.way_id',
|
|
343
|
+
'edge.speed_limit',
|
|
344
|
+
'matched.point',
|
|
345
|
+
'matched.type',
|
|
346
|
+
'matched.edge_index'
|
|
347
|
+
],
|
|
348
|
+
action: 'include'
|
|
349
|
+
},
|
|
350
|
+
shape: slice.map(p => ({
|
|
351
|
+
lon: p.longitude,
|
|
352
|
+
lat: p.latitude
|
|
353
|
+
}))
|
|
354
|
+
})
|
|
355
|
+
.then(r => r.data)
|
|
356
|
+
// eslint-disable-next-line camelcase
|
|
357
|
+
matched_points.forEach((mp, mIndex) => {
|
|
358
|
+
const edge = edges[mp.edge_index]
|
|
359
|
+
const position = route[mIndex + i]
|
|
360
|
+
if (edge && (edge.speed_limit + (threshold || 0)) < position.speed * 1.852) {
|
|
361
|
+
results.push({ ...mp, ...edge, ...position })
|
|
362
|
+
}
|
|
363
|
+
})
|
|
364
|
+
} catch (e) {
|
|
365
|
+
console.error(e.message, e.response && e.response.data, slice[0])
|
|
366
|
+
}
|
|
353
367
|
}
|
|
354
368
|
const reduced = results.reduce((acc, cur, idx, src) => {
|
|
355
369
|
const last = acc.length && acc.slice(-1)[0]
|
|
@@ -20,7 +20,7 @@ describe('speeding tests', function () {
|
|
|
20
20
|
const userData = await report.getUserData()
|
|
21
21
|
userData.roadSpeedLimits = true
|
|
22
22
|
const { device } = await getSpeedingReport(report, userData)
|
|
23
|
-
assert.equal(device.alerts.length,
|
|
23
|
+
assert.equal(device.alerts.length, 6) // Total Alerts
|
|
24
24
|
console.log(device.alerts)
|
|
25
25
|
|
|
26
26
|
userData.minimumIdleMinutes = 1
|