fleetmap-reports 1.0.431 → 1.0.432

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.431",
3
+ "version": "1.0.432",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -276,42 +276,45 @@ async function getCustomSpeedLimitEvents (devices, routes, customSpeed) {
276
276
  async function getHereEvents (devices, routes, threshold) {
277
277
  console.log('here speed limit events')
278
278
  const events = []
279
- for (const d of devices) {
279
+ const promises = devices.map(d => new Promise((resolve) => {
280
280
  const positions = routes.filter(p => p.deviceId === d.id)
281
281
  if (!positions.length) {
282
282
  console.log('no positions on device', d.name)
283
- continue
283
+ resolve()
284
284
  }
285
285
  let hereAlerts = null
286
- const results = await here.routeMatch(positions)
287
- hereAlerts = results.filter(r => r.currentSpeedKmh > (parseInt(r.speedLimit) + threshold)).map(r => {
288
- const position = positions.find(p => new Date(p.fixTime).getTime() === r.timestamp)
289
- return {
290
- ...r,
291
- roadSpeedLimit: r.speedLimit,
292
- deviceId: d.id,
293
- position,
294
- positionId: position && position.id,
295
- attributes: { speedLimit: r.speedLimit, speed: r.currentSpeedKmh / 1.85200 }
296
- }
297
- })
298
- if (!hereAlerts.length) {
299
- console.log('empty array after filter on device', d.name)
300
- continue
301
- }
302
- const reduced = hereAlerts.length < 2
303
- ? hereAlerts
304
- : hereAlerts.reduce((acc, cur, idx, src) => {
305
- if (idx === 1) {
306
- return [cur]
307
- }
308
- if (cur.timestamp - src[idx - 1].timestamp > 300000 || cur.roadSpeedLimit !== src[idx - 1].roadSpeedLimit) {
309
- return acc.concat(cur)
286
+ here.routeMatch(positions).then(results => {
287
+ hereAlerts = results.filter(r => r.currentSpeedKmh > (parseInt(r.speedLimit) + threshold)).map(r => {
288
+ const position = positions.find(p => new Date(p.fixTime).getTime() === r.timestamp)
289
+ return {
290
+ ...r,
291
+ roadSpeedLimit: r.speedLimit,
292
+ deviceId: d.id,
293
+ position,
294
+ positionId: position && position.id,
295
+ attributes: {speedLimit: r.speedLimit, speed: r.currentSpeedKmh / 1.85200}
310
296
  }
311
- return acc
312
297
  })
313
- events.push(...reduced)
314
- }
298
+ if (!hereAlerts.length) {
299
+ console.log('empty array after filter on device', d.name)
300
+ resolve()
301
+ }
302
+ const reduced = hereAlerts.length < 2
303
+ ? hereAlerts
304
+ : hereAlerts.reduce((acc, cur, idx, src) => {
305
+ if (idx === 1) {
306
+ return [cur]
307
+ }
308
+ if (cur.timestamp - src[idx - 1].timestamp > 300000 || cur.roadSpeedLimit !== src[idx - 1].roadSpeedLimit) {
309
+ return acc.concat(cur)
310
+ }
311
+ return acc
312
+ })
313
+ events.push(...reduced)
314
+ resolve()
315
+ })
316
+ }))
317
+ await Promise.all(promises)
315
318
  return events
316
319
  }
317
320