fleetmap-reports 1.0.482 → 1.0.484

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.482",
3
+ "version": "1.0.484",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -291,22 +291,21 @@ async function getHereEvents (devices, routes, threshold) {
291
291
  }
292
292
  here.routeMatch(positions).then(results => {
293
293
  const reduced = results.reduce((acc, cur, idx, src) => {
294
- const previous = acc.length && acc.slice(-1)[0]
295
- if (cur.currentSpeedKmh > parseInt(cur.speedLimit) + (threshold || 0)) {
296
- cur.position = positions.find(p => new Date(p.fixTime).getTime() === cur.timestamp)
297
- if (previous && previous.speedLimit === cur.speedLimit) {
298
- previous.eventTime = cur.timestamp - previous.timestamp
299
- previous.attributes.maxSpeed = Math.max(previous.attributes.maxSpeed, cur.position.speed)
300
- previous.distance += distance.default(point([cur.position.longitude, cur.position.latitude]), point([previous.position.longitude, previous.position.latitude]))
301
- } else {
302
- cur.positionId = cur.position && cur.position.id
303
- cur.roadSpeedLimit = cur.speedLimit
304
- cur.deviceId = d.id
305
- cur.attributes = { speedLimit: cur.speedLimit, speed: cur.currentSpeedKmh / 1.85200, maxSpeed: cur.position.speed }
306
- cur.eventTime = 0
307
- cur.distance = 0
308
- return acc.concat(cur)
309
- }
294
+ cur.overSpeeding = cur.currentSpeedKmh > parseInt(cur.speedLimit) + (threshold || 0)
295
+ const last = acc.length && acc.slice(-1)[0]
296
+ cur.position = positions.find(p => new Date(p.fixTime).getTime() === cur.timestamp)
297
+ if (cur.overSpeeding && last && src[idx - 1].overSpeeding && last.speedLimit === cur.speedLimit) {
298
+ last.eventTime = cur.timestamp - last.timestamp
299
+ last.attributes.maxSpeed = Math.max(last.attributes.maxSpeed, cur.position.speed)
300
+ last.distance = distance.default(point([cur.position.longitude, cur.position.latitude]), point([last.position.longitude, last.position.latitude]))
301
+ } else if (cur.overSpeeding) {
302
+ cur.positionId = cur.position && cur.position.id
303
+ cur.roadSpeedLimit = cur.speedLimit
304
+ cur.deviceId = d.id
305
+ cur.attributes = { speedLimit: cur.speedLimit, speed: cur.currentSpeedKmh / 1.85200, maxSpeed: cur.position.speed }
306
+ cur.eventTime = 0
307
+ cur.distance = 0
308
+ acc.push(cur)
310
309
  }
311
310
  return acc
312
311
  }, [])