fleetmap-reports 2.0.245 → 2.0.248

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": "2.0.245",
3
+ "version": "2.0.248",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -8,7 +8,6 @@ const { headerFromUser, AmiriRegular } = require('./util/pdfDocument')
8
8
  require('jspdf-autotable')
9
9
  const { getStyle } = require('./reportStyle')
10
10
  const drivers = require('./util/driver')
11
- const here = require('./here')
12
11
  const {
13
12
  getUserPartner
14
13
  } = require('fleetmap-partners')
@@ -310,14 +309,7 @@ async function getCustomSpeedLimitEvents (devices, routes, customSpeed) {
310
309
  async function getRoadSpeedLimits (devices, routes, threshold, minimumMinutes = 0) {
311
310
  const position = routes.find(p => getCountry(p))
312
311
  const country = position && getCountry(position)
313
- const config = {
314
- Chile: getOSMSpeedingEvents,
315
- CL: getOSMSpeedingEvents,
316
- Brazil: getOSMSpeedingEvents,
317
- BR: getOSMSpeedingEvents
318
- }
319
- const method = config[country] || getHereEvents
320
- return method(devices, routes, threshold, minimumMinutes, country)
312
+ return getOSMSpeedingEvents(devices, routes, threshold, minimumMinutes, country)
321
313
  }
322
314
 
323
315
  exports.getRoadSpeedLimits = getRoadSpeedLimits
@@ -418,63 +410,6 @@ async function getOSMSpeedingEvents (devices, routes, threshold, minimumMinutes
418
410
  return events.filter(e => e.eventTime >= minimumMinutes * 60 * 1000)
419
411
  }
420
412
 
421
- async function getHereEvents (devices, routes, threshold, minimumMinutes = 0) {
422
- try {
423
- console.log('PROCESS_HERE_EVENTS', process.env.PROCESS_HERE_EVENTS)
424
- console.log('here speed limit events', devices.length, 'devices')
425
- const events = []
426
- const promises = devices.map(d => new Promise((resolve) => {
427
- const positions = routes.filter(p => p.deviceId === d.id)
428
- if (!positions.length) {
429
- console.log('no positions on device', d.name)
430
- resolve()
431
- }
432
- console.log(d.name, 'sending', positions.length, 'to here')
433
- here.routeMatch(positions).then(results => {
434
- console.log(d.name, 'got', results.length, 'from here')
435
- const timestamps = []
436
- for (const p of positions) {
437
- timestamps[new Date(p.fixTime).getTime()] = p
438
- }
439
- const reduced = results.reduce((acc, cur, idx, src) => {
440
- cur.overSpeeding = cur.currentSpeedKmh > parseInt(cur.speedLimit) + (threshold || 0)
441
- const last = acc.length && acc.slice(-1)[0]
442
- cur.position = timestamps[cur.timestamp]
443
- if (cur.overSpeeding && last && src[idx - 1].overSpeeding && last.speedLimit === cur.speedLimit) {
444
- last.eventTime = cur.timestamp - last.timestamp
445
- last.attributes.maxSpeed = Math.max(last.attributes.maxSpeed, cur.position.speed)
446
- last.distance = distance.default(point([cur.position.longitude, cur.position.latitude]), point([last.position.longitude, last.position.latitude]))
447
- } else if (cur.overSpeeding) {
448
- cur.positionId = cur.position && cur.position.id
449
- cur.roadSpeedLimit = cur.speedLimit
450
- cur.deviceId = d.id
451
- cur.attributes = { speedLimit: cur.speedLimit, speed: cur.currentSpeedKmh / 1.85200, maxSpeed: cur.position.speed }
452
- cur.eventTime = 0
453
- cur.distance = 0
454
- acc.push(cur)
455
- }
456
- return acc
457
- }, [])
458
- if (!reduced.length) {
459
- console.log('empty array after filter on device', d.name)
460
- resolve()
461
- } else {
462
- console.log(d.name, 'reduced to', reduced.length)
463
- }
464
- events.push(...reduced)
465
- resolve()
466
- }).catch(e => {
467
- console.warn('route match, moving on', e.message, e.response && e.response.data)
468
- resolve()
469
- })
470
- }))
471
- await Promise.all(promises)
472
- return events.filter(e => e.eventTime >= minimumMinutes * 60 * 1000)
473
- } catch (e) {
474
- console.error(e)
475
- }
476
- }
477
-
478
413
  function calculateEventData (positions, pIndex, alert, device, geofence) {
479
414
  let endEventPosition = alert.position
480
415
  let maxSpeed = alert.position.speed
@@ -485,7 +420,7 @@ function calculateEventData (positions, pIndex, alert, device, geofence) {
485
420
  point([positions[pIndex].longitude, positions[pIndex].latitude]))
486
421
  endEventPosition = positions[pIndex]
487
422
  if (endEventPosition.speed <= alert.attributes.speedLimit || (geofence && !insideGeofence(endEventPosition, geofence))) {
488
- alert.eventTime = new Date(endEventPosition.fixTime) - new Date(alert.position.fixTime) + (device.attributes.overspeedMinimalDuration || 0)*1000
423
+ alert.eventTime = new Date(endEventPosition.fixTime) - new Date(alert.position.fixTime) + (device.attributes.overspeedMinimalDuration || 0) * 1000
489
424
  alert.attributes.maxSpeed = maxSpeed
490
425
  alert.distance = dist
491
426
  break
@@ -4,8 +4,8 @@ const { getCountry } = require('../util/utils')
4
4
 
5
5
  async function getSpeedingReport (report, userData) {
6
6
  const data = await report.speedingReport(
7
- new Date(Date.UTC(2023, 9, 4, 0, 0, 0, 0)),
8
- new Date(Date.UTC(2023, 9, 4, 23, 59, 59, 0)),
7
+ new Date(Date.UTC(2025, 4, 5, 0, 0, 0, 0)),
8
+ new Date(Date.UTC(2025, 4, 5, 23, 59, 59, 0)),
9
9
  userData)
10
10
 
11
11
  const device = data[0].devices[0]
@@ -101,7 +101,7 @@ async function getItems (traccar, u, _chunk, counter, devicesPerRequest, ignoreP
101
101
  }
102
102
 
103
103
  function streamJson (traccar, u, filter) {
104
- const cookie = traccar.axios.defaults.headers?.cookie || traccar.axios.defaults.headers?.common?.cookie || require('axios').defaults.headers.cookie
104
+ const cookie = traccar.axios.defaults.headers?.cookie || traccar.axios.defaults.headers?.common?.cookie || require('axios').defaults.headers?.common?.cookie
105
105
  return piscina.run({
106
106
  url: traccar.axios.defaults.baseURL + u,
107
107
  cookie,