fleetmap-reports 1.0.570 → 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/zone-report.js +7 -46
package/package.json
CHANGED
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
|
|