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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fleetmap-reports",
3
- "version": "1.0.866",
3
+ "version": "1.0.868",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -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 = crg.get_country(position.latitude, position.longitude)
309
+ const country = getCountry(position)
305
310
  const config = {
306
311
  CHL: getOSMSpeedingEvents,
307
312
  MAR: getOSMSpeedingEvents
308
313
  }
309
- const method = config[country && country.code] || getHereEvents
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
- // eslint-disable-next-line camelcase
322
- const { matched_points, edges } = await axios.post('https://valhalla1.openstreetmap.de/trace_attributes', {
323
- costing: 'auto',
324
- 'shape_match type': 'map_snap',
325
- filters: {
326
- attributes: [
327
- 'admin.country_code',
328
- 'admin.country_text',
329
- 'admin.state_code',
330
- 'admin.state_text',
331
- 'edge.names',
332
- 'edge.way_id',
333
- 'edge.speed_limit',
334
- 'matched.point',
335
- 'matched.type',
336
- 'matched.edge_index'
337
- ],
338
- action: 'include'
339
- },
340
- shape: slice.map(p => ({
341
- lon: p.longitude, lat: p.latitude
342
- }))
343
- }).then(r => r.data)
344
-
345
- // eslint-disable-next-line camelcase
346
- matched_points.forEach((mp, mIndex) => {
347
- const edge = edges[mp.edge_index]
348
- const position = route[mIndex + i]
349
- if (edge && (edge.speed_limit + (threshold || 0)) < position.speed * 1.852) {
350
- results.push({ ...mp, ...edge, ...position })
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, 9) // Total Alerts
23
+ assert.equal(device.alerts.length, 6) // Total Alerts
24
24
  console.log(device.alerts)
25
25
 
26
26
  userData.minimumIdleMinutes = 1