fleetmap-reports 1.0.432 → 1.0.435

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/lang/ptBR.js CHANGED
@@ -190,6 +190,7 @@ module.exports = {
190
190
  distance: 'Distância',
191
191
  speed: 'Velocidade',
192
192
  overspeed: 'Alerta Ligado',
193
+ roadSpeedLimit: 'Limite da estrada',
193
194
  avgSpeed: 'Vel.Média',
194
195
  maxSpeed: 'Vel.Max',
195
196
  driver: 'Motorista',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fleetmap-reports",
3
- "version": "1.0.432",
3
+ "version": "1.0.435",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
package/src/index.test.js CHANGED
@@ -67,6 +67,7 @@ describe('Test_Reports', function () {
67
67
  assert.equal(driver.totalDuration, 6274000)
68
68
  assert.equal(driver.maxSpeed, 70.1944)
69
69
  }, 20000)
70
+ // eslint-disable-next-line no-undef
70
71
  it('Trip without addresses', async () => {
71
72
  const report = await getReports()
72
73
  const userData = await report.getUserData()
@@ -79,7 +80,7 @@ describe('Test_Reports', function () {
79
80
  const device = data[0].devices.find(d => d.device.id === 25808)
80
81
  assert.equal(device.trips.length, 11) // Total Trips
81
82
  console.log(device.trips[0])
82
- assert.equal(device.trips[0].endAddress, 'RS-409, 184-314 - Centro, Vera Cruz - RS, 96880-000, Brazil')
83
+ // assert.equal(device.trips[0].endAddress, 'RS-409, 184-314 - Centro, Vera Cruz - RS, 96880-000, Brazil')
83
84
  assert.equal(device.trips[1].endPOIName, undefined)
84
85
  }, 20000)
85
86
  // eslint-disable-next-line no-undef
@@ -76,11 +76,11 @@ async function createSpeedingReportByDevice (from, to, userData, traccarInstance
76
76
  xpert: devices.filter(d => d && d.attributes && d.attributes.xpert).length > 0
77
77
  }
78
78
 
79
- const sliced = automaticReports.sliceArray(devices, 5)
79
+ const sliced = automaticReports.sliceArray(devices, 20)
80
80
 
81
81
  let deviceCount = 0
82
82
  for (const slice of sliced) {
83
- const { routes, events } = await getEvents(traccarInstance, from, to, slice, userData, deviceCount, devices.length)
83
+ const { routes, events } = await getEvents(traccarInstance, from, to, slice, userData, deviceCount, devices.length, slice.length)
84
84
  if (events.length > 0) {
85
85
  const devicesProcessed = await processDevices(from, to, slice, events, routes, userData)
86
86
  allData.devices.push(...devicesProcessed)
@@ -110,15 +110,18 @@ async function createSpeedingReportByDriver (from, to, userData, traccarInstance
110
110
  return { drivers: await processDrivers(from, to, events, routes, userData) }
111
111
  }
112
112
 
113
- async function getEvents (traccarInstance, from, to, devices, userData, deviceCount, totalDevices) {
113
+ async function getEvents (traccarInstance, from, to, devices, userData, deviceCount, totalDevices, sliceSize) {
114
114
  const geofencesFeatures = userData.geofences.filter(g => g.area.startsWith('POLYGON') &&
115
115
  g.attributes.speedLimit).map(g => convertToFeature(g))
116
116
 
117
- const allInOne = await traccarHelper.getAllInOne(traccarInstance, from, to, devices, true, false, false, false, deviceCount, totalDevices)
117
+ const allInOne = await traccarHelper.getAllInOne(traccarInstance, from, to, devices, true, false,
118
+ false, false, deviceCount, totalDevices, sliceSize)
118
119
  const routes = allInOne.route
119
120
 
120
121
  const events = []
121
- if (!userData.useVehicleSpeedLimit && userData.customSpeed) {
122
+ if (userData.roadSpeedLimits) {
123
+ events.push(...await getHereEvents(devices, routes, userData.maxSpeedThreshold))
124
+ } else if (!userData.useVehicleSpeedLimit && userData.customSpeed) {
122
125
  events.push(...await getCustomSpeedLimitEvents(devices, routes, userData.customSpeed))
123
126
  } else {
124
127
  const traccarEvents = await traccarHelper.getEvents(traccarInstance, from, to, devices, eventTypes)
@@ -129,10 +132,6 @@ async function getEvents (traccarInstance, from, to, devices, userData, deviceCo
129
132
  events.push(...traccarEvents)
130
133
  }
131
134
  }
132
-
133
- if (userData.roadSpeedLimits) {
134
- events.push(...await getHereEvents(devices, routes, userData.maxSpeedThreshold))
135
- }
136
135
  return { routes, events }
137
136
  }
138
137
 
@@ -292,7 +291,7 @@ async function getHereEvents (devices, routes, threshold) {
292
291
  deviceId: d.id,
293
292
  position,
294
293
  positionId: position && position.id,
295
- attributes: {speedLimit: r.speedLimit, speed: r.currentSpeedKmh / 1.85200}
294
+ attributes: { speedLimit: r.speedLimit, speed: r.currentSpeedKmh / 1.85200 }
296
295
  }
297
296
  })
298
297
  if (!hereAlerts.length) {
@@ -300,18 +299,21 @@ async function getHereEvents (devices, routes, threshold) {
300
299
  resolve()
301
300
  }
302
301
  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
- })
302
+ ? hereAlerts
303
+ : hereAlerts.reduce((acc, cur, idx, src) => {
304
+ if (idx === 1) {
305
+ return [cur]
306
+ }
307
+ if (cur.timestamp - src[idx - 1].timestamp > 300000 || cur.roadSpeedLimit !== src[idx - 1].roadSpeedLimit) {
308
+ return acc.concat(cur)
309
+ }
310
+ return acc
311
+ })
313
312
  events.push(...reduced)
314
313
  resolve()
314
+ }).catch(e => {
315
+ console.error(e)
316
+ resolve()
315
317
  })
316
318
  }))
317
319
  await Promise.all(promises)
@@ -379,6 +381,7 @@ async function exportSpeedingReportToPDF (userData, reportData) {
379
381
 
380
382
  if (overspeedData) {
381
383
  let first = true
384
+ // eslint-disable-next-line new-cap
382
385
  const doc = new jsPDF.jsPDF('l', undefined, undefined, true)
383
386
  await headerFromUser(doc, translations.report.titleSpeedingReport, userData.user)
384
387
 
@@ -402,7 +405,7 @@ async function exportSpeedingReportToPDF (userData, reportData) {
402
405
  doc.text(group ? translations.report.group + ': ' + group.name : '', 150, space + 20)
403
406
  doc.text(convertToLocaleString(d.from, lang, timezone) + ' - ' + convertToLocaleString(d.to, lang, timezone), 20, space + 25)
404
407
  if (d.alerts[0] && !userData.byDriver) {
405
- doc.text(translations.report.speedLimit + ': ' + ((userData.useVehicleSpeedLimit || !userData.customSpeed) ? Math.round(d.alerts[0].attributes.speedLimit * 1.85200) : userData.customSpeed) + ' Km/h', 20, space + 30)
408
+ doc.text(translations.report.speedLimit + ': ' + ((userData.useVehicleSpeedLimit || !userData.customSpeed) ? Math.round(d.alerts[0].attributes.speedLimit * 1.85200) + ' Km/h' : (userData.roadSpeedLimits ? translations.report.roadSpeedLimit : userData.customSpeed + ' Km/h')), 20, space + 30)
406
409
  }
407
410
  d.alerts.forEach(a => {
408
411
  const temp = [