fleetmap-reports 1.0.475 → 1.0.477

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.475",
3
+ "version": "1.0.477",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
package/src/index.test.js CHANGED
@@ -24,9 +24,9 @@ describe('Test_Reports', function () {
24
24
  userData.roadSpeedLimits = true
25
25
  const { device, totalDistance, totalEventTime } = await getSpeedingReport(report, userData)
26
26
  assert.equal(device.alerts.length, 11) // Total Alerts
27
- console.log(device.alerts[0])
28
- assert.equal(totalDistance, 74.71054403083238) // Total Kms
29
- assert.equal(totalEventTime, 562000) // Total Duration
27
+ console.log(device.alerts)
28
+ assert.equal(totalDistance, 113.82700635835963) // Total Kms
29
+ assert.equal(totalEventTime, 5258000) // Total Duration
30
30
  }, 200000)
31
31
  // eslint-disable-next-line no-undef
32
32
  it('Speeding with custom speed', async () => {
@@ -222,7 +222,7 @@ async function findEventsPosition (from, to, devices, events, routes, userData)
222
222
  const positions = routes.filter(p => p.deviceId === d.id)
223
223
 
224
224
  for (const a of deviceEvents) {
225
- let pIndex = positions.findIndex(p => p.id === a.positionId)
225
+ const pIndex = positions.findIndex(p => p.id === a.positionId)
226
226
  if (pIndex > 0) {
227
227
  let geofence = null
228
228
  if (a.geofenceId) {
@@ -233,8 +233,11 @@ async function findEventsPosition (from, to, devices, events, routes, userData)
233
233
  }
234
234
 
235
235
  a.position = positions[pIndex]
236
- pIndex = calculateEventData(positions, pIndex, a, d, geofence, userData)
237
- positions.slice(pIndex)
236
+ // TODO: we should user something else
237
+ // the linkId property exists when speed events come from here, in that case the data is already calculated
238
+ if (!d.linkId) {
239
+ calculateEventData(positions, pIndex, a, d, geofence, userData)
240
+ }
238
241
  }
239
242
  }
240
243
  }
@@ -294,6 +297,8 @@ async function getHereEvents (devices, routes, threshold) {
294
297
  cur.roadSpeedLimit = cur.speedLimit
295
298
  cur.deviceId = d.id
296
299
  cur.attributes = { speedLimit: cur.speedLimit, speed: cur.currentSpeedKmh / 1.85200, maxSpeed: cur.position.speed }
300
+ cur.eventTime = 0
301
+ cur.distance = 0
297
302
  return acc.concat(cur)
298
303
  }
299
304
  }
@@ -318,7 +323,10 @@ function calculateEventData (positions, pIndex, alert, device, geofence, userDat
318
323
  let endEventPosition = alert.position
319
324
  let maxSpeed = alert.position.speed
320
325
  let dist = 0
321
- if (alert.eventTime) { return -1 }
326
+ if (alert.eventTime) {
327
+ console.log('ignoring')
328
+ return -1
329
+ }
322
330
  while (pIndex + 1 < positions.length) {
323
331
  pIndex++
324
332
  dist += distance.default(point([endEventPosition.longitude, endEventPosition.latitude]),