fleetmap-reports 1.0.290 → 1.0.295

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.290",
3
+ "version": "1.0.295",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -242,9 +242,10 @@ async function getHereEvents(devices, routes, threshold){
242
242
  console.log('no positions on device', d.name)
243
243
  continue
244
244
  }
245
+ let hereAlerts = null
245
246
  try {
246
247
  const results = await here.routeMatch(positions)
247
- const hereAlerts = results.filter(r => r.currentSpeedKmh > (parseInt(r.speedLimit) + threshold)).map(r => {
248
+ hereAlerts = results.filter(r => r.currentSpeedKmh > (parseInt(r.speedLimit) + threshold)).map(r => {
248
249
  const position = positions.find(p => new Date(p.fixTime).getTime() === r.timestamp)
249
250
  return {
250
251
  ...r,
@@ -255,7 +256,11 @@ async function getHereEvents(devices, routes, threshold){
255
256
  attributes: {speedLimit: r.speedLimit, speed: r.currentSpeedKmh / 1.85200}
256
257
  }
257
258
  })
258
- const reduced = hereAlerts.reduce((acc, cur, idx, src) => {
259
+ if (!hereAlerts.length) {
260
+ console.log('empty array after filter on device', d.name)
261
+ continue
262
+ }
263
+ const reduced = hereAlerts.length < 2 ? hereAlerts : hereAlerts.reduce((acc, cur, idx, src) => {
259
264
  if (idx === 1) {
260
265
  return [cur]
261
266
  }
@@ -266,7 +271,7 @@ async function getHereEvents(devices, routes, threshold){
266
271
  })
267
272
  events.push(...reduced)
268
273
  } catch (e) {
269
- console.error(e)
274
+ console.error(hereAlerts, 'threshold', threshold, e)
270
275
  }
271
276
  }
272
277
  return events