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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fleetmap-reports",
3
- "version": "1.0.862",
3
+ "version": "1.0.864",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -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
- const { features } = await axios.post(`https://api.geoapify.com/v1/mapmatching?apiKey=${apiKey}`, {
322
- mode: 'drive',
323
- waypoints: slice.map(p => ({
324
- timestamp: new Date(p.fixTime).toISOString(),
325
- bearing: p.course,
326
- location: [p.longitude, p.latitude]
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
- const { properties } = features[0]
331
- for (const wp of properties.waypoints) {
332
- const leg = properties.legs[wp.leg_index]
333
- if (!leg) {
334
- console.log('ignoring legs (count):', properties.legs.count, wp.leg_index)
335
- continue
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
- const step = leg.steps[wp.step_index]
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.overSpeeding && last && src[idx - 1].overSpeeding && last.speed_limit === cur.speed_limit) {
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 = distance.default(point([cur.longitude, cur.latitude]), point([last.longitude, last.latitude]))
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, 6) // Total Alerts
29
+ assert.equal(r.device.alerts.length, 2) // Total Alerts
30
30
  }, 200000)
31
31
 
32
32
  // eslint-disable-next-line no-undef