fleetmap-reports 1.0.865 → 1.0.867

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.865",
3
+ "version": "1.0.867",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -303,7 +303,8 @@ async function getRoadSpeedLimits (devices, routes, threshold, minimumMinutes =
303
303
  const position = routes[0]
304
304
  const country = crg.get_country(position.latitude, position.longitude)
305
305
  const config = {
306
- CHL: getOSMSpeedingEvents
306
+ CHL: getOSMSpeedingEvents,
307
+ MAR: getOSMSpeedingEvents
307
308
  }
308
309
  const method = config[country && country.code] || getHereEvents
309
310
  return method(devices, routes, threshold, minimumMinutes)
@@ -317,38 +318,47 @@ async function getOSMSpeedingEvents (devices, routes, threshold, minimumMinutes
317
318
  const results = []
318
319
  for (let i = 0; i < route.length; i += chunk) {
319
320
  const slice = route.slice(i, i + chunk)
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
341
- }))
342
- }).then(r => r.data)
343
-
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 })
350
- }
351
- })
321
+ try {
322
+ const {
323
+ // eslint-disable-next-line camelcase
324
+ matched_points,
325
+ edges
326
+ } = await axios.post(`${process.env.VALHALLA_BASEURL}/trace_attributes`,
327
+ {
328
+ costing: 'auto',
329
+ shape_match: 'map_snap',
330
+ filters: {
331
+ attributes: [
332
+ 'admin.country_code',
333
+ 'admin.country_text',
334
+ 'admin.state_code',
335
+ 'admin.state_text',
336
+ 'edge.names',
337
+ 'edge.way_id',
338
+ 'edge.speed_limit',
339
+ 'matched.point',
340
+ 'matched.type',
341
+ 'matched.edge_index'
342
+ ],
343
+ action: 'include'
344
+ },
345
+ shape: slice.map(p => ({
346
+ lon: p.longitude,
347
+ lat: p.latitude
348
+ }))
349
+ })
350
+ .then(r => r.data)
351
+ // eslint-disable-next-line camelcase
352
+ matched_points.forEach((mp, mIndex) => {
353
+ const edge = edges[mp.edge_index]
354
+ const position = route[mIndex + i]
355
+ if (edge && (edge.speed_limit + (threshold || 0)) < position.speed * 1.852) {
356
+ results.push({ ...mp, ...edge, ...position })
357
+ }
358
+ })
359
+ } catch (e) {
360
+ console.error(e.message, e.response && e.response.data, slice)
361
+ }
352
362
  }
353
363
  const reduced = results.reduce((acc, cur, idx, src) => {
354
364
  const last = acc.length && acc.slice(-1)[0]