fleetmap-reports 1.0.481 → 1.0.483

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.481",
3
+ "version": "1.0.483",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -233,9 +233,17 @@ async function findEventsPosition (from, to, devices, events, routes, userData)
233
233
  }
234
234
 
235
235
  if (!userData.roadSpeedLimits) {
236
+ console.log('ignorting eventdata')
236
237
  a.position = positions[pIndex]
237
238
  calculateEventData(positions, pIndex, a, d, geofence, userData)
238
239
  }
240
+ if (a.position.attributes.driverUniqueId) {
241
+ const driver = userData.drivers.find(d => d.uniqueId === a.position.attributes.driverUniqueId)
242
+ a.driver = (driver && driver.name) || a.position.attributes.driverUniqueId
243
+ }
244
+ a.deviceName = d.name
245
+
246
+ return pIndex
239
247
  }
240
248
  }
241
249
  }
@@ -283,22 +291,21 @@ async function getHereEvents (devices, routes, threshold) {
283
291
  }
284
292
  here.routeMatch(positions).then(results => {
285
293
  const reduced = results.reduce((acc, cur, idx, src) => {
286
- const previous = acc.length && acc.slice(-1)[0]
287
- if (cur.currentSpeedKmh > parseInt(cur.speedLimit) + (threshold || 0)) {
294
+ cur.overSpeeding = cur.currentSpeedKmh > parseInt(cur.speedLimit) + (threshold || 0)
295
+ const last = acc.length && acc.slice(-1)[0]
296
+ if (cur.overSpeeding && last && src[idx - 1].overSpeeding && last.speedLimit === cur.speedLimit) {
288
297
  cur.position = positions.find(p => new Date(p.fixTime).getTime() === cur.timestamp)
289
- if (previous && previous.speedLimit === cur.speedLimit) {
290
- previous.eventTime += cur.timestamp - previous.timestamp
291
- previous.attributes.maxSpeed = Math.max(previous.attributes.maxSpeed, cur.position.speed)
292
- previous.distance += distance.default(point([cur.position.longitude, cur.position.latitude]), point([previous.position.longitude, previous.position.latitude]))
293
- } else {
294
- cur.positionId = cur.position && cur.position.id
295
- cur.roadSpeedLimit = cur.speedLimit
296
- cur.deviceId = d.id
297
- cur.attributes = { speedLimit: cur.speedLimit, speed: cur.currentSpeedKmh / 1.85200, maxSpeed: cur.position.speed }
298
- cur.eventTime = 0
299
- cur.distance = 0
300
- return acc.concat(cur)
301
- }
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)
302
309
  }
303
310
  return acc
304
311
  }, [])
@@ -337,15 +344,6 @@ function calculateEventData (positions, pIndex, alert, device, geofence, userDat
337
344
  }
338
345
  }
339
346
  }
340
-
341
- if (alert.position.attributes.driverUniqueId) {
342
- const driver = userData.drivers.find(d => d.uniqueId === alert.position.attributes.driverUniqueId)
343
- alert.driver = driver && driver.name
344
- }
345
-
346
- alert.deviceName = device.name
347
-
348
- return pIndex
349
347
  }
350
348
 
351
349
  async function exportSpeedingReportToPDF (userData, reportData) {