fleetmap-reports 1.0.867 → 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.867",
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) {
@@ -323,7 +328,7 @@ async function getOSMSpeedingEvents (devices, routes, threshold, minimumMinutes
323
328
  // eslint-disable-next-line camelcase
324
329
  matched_points,
325
330
  edges
326
- } = await axios.post(`${process.env.VALHALLA_BASEURL}/trace_attributes`,
331
+ } = await axios.post(`http://valhalla-${getCountry(slice[0]) || country}.pinme.io:8002/trace_attributes`,
327
332
  {
328
333
  costing: 'auto',
329
334
  shape_match: 'map_snap',
@@ -357,7 +362,7 @@ async function getOSMSpeedingEvents (devices, routes, threshold, minimumMinutes
357
362
  }
358
363
  })
359
364
  } catch (e) {
360
- console.error(e.message, e.response && e.response.data, slice)
365
+ console.error(e.message, e.response && e.response.data, slice[0])
361
366
  }
362
367
  }
363
368
  const reduced = results.reduce((acc, cur, idx, src) => {
@@ -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