fleetmap-reports 1.0.569 → 1.0.571

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.569",
3
+ "version": "1.0.571",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -174,7 +174,7 @@ async function exportSpeedingReportToPDF (userData, reportData) {
174
174
  d.alerts.forEach(a => {
175
175
  const temp = [
176
176
  a.type === 'alarm'
177
- ? translations.report['event_' + a.attributes.alarm] || a.attributes.alarm
177
+ ? getEventType(a, translations, d.device)
178
178
  : translations.report['event_' + a.type],
179
179
  getAlertDate(userData.user, a),
180
180
  a.geofenceName || (a.position ? a.position.address : ''),
@@ -216,6 +216,12 @@ async function exportSpeedingReportToPDF (userData, reportData) {
216
216
  }
217
217
  }
218
218
 
219
+ function getEventType (a, translations, device) {
220
+ let sensor
221
+ if (a.attributes.alarm === 'sensor') { sensor = device.attributes.sensor1 }
222
+ return sensor || translations.report['event_' + a.attributes.alarm] || a.attributes.alarm
223
+ }
224
+
219
225
  function exportSpeedingReportToExcel (userData, reportData) {
220
226
  console.log('exportSpeedingReportToExcel')
221
227
 
@@ -242,7 +248,7 @@ function exportSpeedingReportToExcel (userData, reportData) {
242
248
  return {
243
249
  name: d.device.name,
244
250
  eventType: a.type === 'alarm'
245
- ? translations.report['event_' + a.attributes.alarm] || a.attributes.alarm
251
+ ? getEventType(a, translations, d.device)
246
252
  : translations.report['event_' + a.type],
247
253
  fixTime: getAlertDate(userData.user, a),
248
254
  address: a.geofenceName || (a.position ? a.position.address : ''),
@@ -3,6 +3,7 @@ const automaticReports = require('./automaticReports')
3
3
  const { convertMS, convertToLocaleString, getTranslations, convertToFeature, convertPositionToFeature } = require('./util/utils')
4
4
  const jsPDF = require('jspdf')
5
5
  require('jspdf-autotable')
6
+ const traccarHelper = require('./util/traccar')
6
7
  const { headerFromUser } = require('./util/pdfDocument')
7
8
  const { getStyle } = require('./reportStyle')
8
9
  const { getUserPartner } = require('fleetmap-partners')
@@ -63,14 +64,15 @@ async function createZoneReport (from, to, userData, traccar) {
63
64
 
64
65
  let deviceCount = 0
65
66
  for (const slice of sliced) {
66
- const data = await getAllInOne(
67
+ const data = await traccarHelper.getAllInOne(
67
68
  traccar, from, to, slice, true, false, false, false,
68
- deviceCount, devices.length, sliceSize, deviceChunk, undefined, userData)
69
+ deviceCount, devices.length, sliceSize, deviceChunk, undefined)
69
70
 
70
- console.log('Geofence Enter/Exit Alerts:' + data.length)
71
+ const alerts = getInAndOutEvents(slice, data.route, userData)
72
+ console.log('Geofence Enter/Exit Alerts:' + alerts.length)
71
73
 
72
- if (data.length) {
73
- allData.devices.push(...await processDevices(from, to, devices, userData.drivers, userData.geofences, data, traccar))
74
+ if (alerts.length) {
75
+ allData.devices.push(...await processDevices(from, to, devices, userData.drivers, userData.geofences, alerts, traccar))
74
76
  }
75
77
  deviceCount = deviceCount + slice.length
76
78
  }
@@ -80,47 +82,6 @@ async function createZoneReport (from, to, userData, traccar) {
80
82
  return reportData
81
83
  }
82
84
 
83
- async function getRoute (
84
- traccar,
85
- from,
86
- to,
87
- devices,
88
- currentDeviceCount = 0,
89
- totalDevices = devices.length,
90
- sliceSize = 5,
91
- devicesPerRequest = 1,
92
- counter = undefined,
93
- userData) {
94
- const url = `/reports/allinone?from=${from.toISOString()}&to=${to.toISOString()}&type=route`
95
- const sliced = automaticReports.sliceArray(devices, sliceSize)
96
- const result = []
97
- console.log('getAll, slicing', sliceSize)
98
- let iteration = 0
99
- for (const chunk of sliced) {
100
- console.log('iteration', ++iteration)
101
- const requests = []
102
- for (const _chunk of automaticReports.sliceArray(chunk, devicesPerRequest)) {
103
- const u = url + '&' + _chunk.map(d => `deviceId=${d.id}`).join('&')
104
- requests.push(
105
- traccar.axios.get(u, {
106
- jar: traccar.cookieJar,
107
- withCredentials: true
108
- }).then(r => r.data).then(x => {
109
- if (counter) {
110
- counter.count += devicesPerRequest
111
- console.log(`PROGRESS_PERC:${counter.count / totalDevices * 100}`)
112
- } else {
113
- currentDeviceCount += devicesPerRequest
114
- console.log(`PROGRESS_PERC:${currentDeviceCount / totalDevices * 100}`)
115
- }
116
- return getInAndOutEvents(devices, x.route, userData)
117
- }))
118
- }
119
- result.push(...(await Promise.all(requests)))
120
- }
121
- return result.flat()
122
- }
123
-
124
85
  async function processDevices (from, to, devices, drivers, geofences, data) {
125
86
  const devicesResult = []
126
87