fleetmap-reports 1.0.629 → 1.0.630
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/idle-report.js +22 -3
package/package.json
CHANGED
package/src/idle-report.js
CHANGED
|
@@ -8,6 +8,7 @@ const automaticReports = require('./automaticReports')
|
|
|
8
8
|
const traccarHelper = require('./util/traccar')
|
|
9
9
|
const { getIdleEvents } = require('./util/route')
|
|
10
10
|
const { reportByDriver } = require('./util/driver')
|
|
11
|
+
const { getNearestPOIs, insideGeofence } = require('./util/geofence')
|
|
11
12
|
|
|
12
13
|
const fileName = 'IdleReport'
|
|
13
14
|
|
|
@@ -143,6 +144,8 @@ function processDrivers (from, to, userData, data) {
|
|
|
143
144
|
|
|
144
145
|
if (filteredEvents.length) {
|
|
145
146
|
filteredEvents.forEach(e => {
|
|
147
|
+
findGeofenceData(e, userData)
|
|
148
|
+
|
|
146
149
|
const device = userData.devices.find(d => d.id === e.position.deviceId)
|
|
147
150
|
e.deviceName = device ? device.name : ''
|
|
148
151
|
})
|
|
@@ -170,6 +173,8 @@ function processDevices (from, to, devices, routes, userData) {
|
|
|
170
173
|
|
|
171
174
|
if (filteredEvents.length) {
|
|
172
175
|
filteredEvents.forEach(e => {
|
|
176
|
+
findGeofenceData(e, userData)
|
|
177
|
+
|
|
173
178
|
const driver = userData.drivers.find(d => d.id === e.position.attributes.driverUniqueId)
|
|
174
179
|
e.driver = driver ? driver.name : ''
|
|
175
180
|
})
|
|
@@ -185,6 +190,20 @@ function processDevices (from, to, devices, routes, userData) {
|
|
|
185
190
|
return devicesResult
|
|
186
191
|
}
|
|
187
192
|
|
|
193
|
+
function findGeofenceData (event, userData) {
|
|
194
|
+
const nearestPOIs = getNearestPOIs(event.position.longitude, event.position.latitude, userData.geofences)
|
|
195
|
+
if (nearestPOIs.length > 0) {
|
|
196
|
+
event.endPOIName = nearestPOIs[0].p.name
|
|
197
|
+
} else {
|
|
198
|
+
const geofence = userData.geofences.filter(g => g && g.area.startsWith('POLYGON')).some(g =>
|
|
199
|
+
insideGeofence({ latitude: event.position.latitude, longitude: event.position.longitude }, g)
|
|
200
|
+
)
|
|
201
|
+
if (geofence) {
|
|
202
|
+
event.endPOIName = geofence.name
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
188
207
|
async function exportIdleReportToPDF (userData, reportData) {
|
|
189
208
|
console.log('Export to PDF')
|
|
190
209
|
|
|
@@ -248,7 +267,7 @@ async function exportIdleReportToPDF (userData, reportData) {
|
|
|
248
267
|
|
|
249
268
|
const footValues = [
|
|
250
269
|
'Total:' + d.idleEvents.length,
|
|
251
|
-
'',
|
|
270
|
+
'', '', '',
|
|
252
271
|
convertMS(d.idleEvents.reduce((a, b) => a + b.idleTime, 0), true)
|
|
253
272
|
]
|
|
254
273
|
|
|
@@ -351,11 +370,11 @@ function deviceName (device) {
|
|
|
351
370
|
return device.name + (device.attributes.license_plate ? ', ' + device.attributes.license_plate : '') + (device.model ? ', ' + device.model : '')
|
|
352
371
|
}
|
|
353
372
|
|
|
354
|
-
function getIdleEventDate (
|
|
373
|
+
function getIdleEventDate (position, user) {
|
|
355
374
|
return convertToLocaleDateString(position.fixTime, user.attributes.lang, user.attributes.timezone)
|
|
356
375
|
}
|
|
357
376
|
|
|
358
|
-
function getIdleEventTime (
|
|
377
|
+
function getIdleEventTime (position, user) {
|
|
359
378
|
return convertToLocaleTimeString(position.fixTime, user.attributes.lang, user.attributes.timezone)
|
|
360
379
|
}
|
|
361
380
|
|