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 +1 -1
- package/src/events-report.js +8 -2
- package/src/zone-report.js +7 -46
package/package.json
CHANGED
package/src/events-report.js
CHANGED
|
@@ -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
|
-
?
|
|
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
|
-
?
|
|
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 : ''),
|
package/src/zone-report.js
CHANGED
|
@@ -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
|
|
69
|
+
deviceCount, devices.length, sliceSize, deviceChunk, undefined)
|
|
69
70
|
|
|
70
|
-
|
|
71
|
+
const alerts = getInAndOutEvents(slice, data.route, userData)
|
|
72
|
+
console.log('Geofence Enter/Exit Alerts:' + alerts.length)
|
|
71
73
|
|
|
72
|
-
if (
|
|
73
|
-
allData.devices.push(...await processDevices(from, to, devices, userData.drivers, userData.geofences,
|
|
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
|
|