fleetmap-reports 1.0.431 → 1.0.434
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/index.test.js +2 -1
- package/src/speeding-report.js +45 -39
package/package.json
CHANGED
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
|
package/src/speeding-report.js
CHANGED
|
@@ -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,
|
|
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,
|
|
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 (
|
|
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
|
|
|
@@ -276,42 +275,48 @@ async function getCustomSpeedLimitEvents (devices, routes, customSpeed) {
|
|
|
276
275
|
async function getHereEvents (devices, routes, threshold) {
|
|
277
276
|
console.log('here speed limit events')
|
|
278
277
|
const events = []
|
|
279
|
-
|
|
278
|
+
const promises = devices.map(d => new Promise((resolve) => {
|
|
280
279
|
const positions = routes.filter(p => p.deviceId === d.id)
|
|
281
280
|
if (!positions.length) {
|
|
282
281
|
console.log('no positions on device', d.name)
|
|
283
|
-
|
|
282
|
+
resolve()
|
|
284
283
|
}
|
|
285
284
|
let hereAlerts = null
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
}
|
|
297
|
-
})
|
|
298
|
-
if (!hereAlerts.length) {
|
|
299
|
-
console.log('empty array after filter on device', d.name)
|
|
300
|
-
continue
|
|
301
|
-
}
|
|
302
|
-
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)
|
|
285
|
+
here.routeMatch(positions).then(results => {
|
|
286
|
+
hereAlerts = results.filter(r => r.currentSpeedKmh > (parseInt(r.speedLimit) + threshold)).map(r => {
|
|
287
|
+
const position = positions.find(p => new Date(p.fixTime).getTime() === r.timestamp)
|
|
288
|
+
return {
|
|
289
|
+
...r,
|
|
290
|
+
roadSpeedLimit: r.speedLimit,
|
|
291
|
+
deviceId: d.id,
|
|
292
|
+
position,
|
|
293
|
+
positionId: position && position.id,
|
|
294
|
+
attributes: { speedLimit: r.speedLimit, speed: r.currentSpeedKmh / 1.85200 }
|
|
310
295
|
}
|
|
311
|
-
return acc
|
|
312
296
|
})
|
|
313
|
-
|
|
314
|
-
|
|
297
|
+
if (!hereAlerts.length) {
|
|
298
|
+
console.log('empty array after filter on device', d.name)
|
|
299
|
+
resolve()
|
|
300
|
+
}
|
|
301
|
+
const reduced = hereAlerts.length < 2
|
|
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
|
+
})
|
|
312
|
+
events.push(...reduced)
|
|
313
|
+
resolve()
|
|
314
|
+
}).catch(e => {
|
|
315
|
+
console.error(e)
|
|
316
|
+
resolve()
|
|
317
|
+
})
|
|
318
|
+
}))
|
|
319
|
+
await Promise.all(promises)
|
|
315
320
|
return events
|
|
316
321
|
}
|
|
317
322
|
|
|
@@ -376,6 +381,7 @@ async function exportSpeedingReportToPDF (userData, reportData) {
|
|
|
376
381
|
|
|
377
382
|
if (overspeedData) {
|
|
378
383
|
let first = true
|
|
384
|
+
// eslint-disable-next-line new-cap
|
|
379
385
|
const doc = new jsPDF.jsPDF('l', undefined, undefined, true)
|
|
380
386
|
await headerFromUser(doc, translations.report.titleSpeedingReport, userData.user)
|
|
381
387
|
|
|
@@ -399,7 +405,7 @@ async function exportSpeedingReportToPDF (userData, reportData) {
|
|
|
399
405
|
doc.text(group ? translations.report.group + ': ' + group.name : '', 150, space + 20)
|
|
400
406
|
doc.text(convertToLocaleString(d.from, lang, timezone) + ' - ' + convertToLocaleString(d.to, lang, timezone), 20, space + 25)
|
|
401
407
|
if (d.alerts[0] && !userData.byDriver) {
|
|
402
|
-
doc.text(translations.report.speedLimit + ': ' + ((userData.useVehicleSpeedLimit || !userData.customSpeed) ? Math.round(d.alerts[0].attributes.speedLimit * 1.85200) : userData.customSpeed
|
|
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)
|
|
403
409
|
}
|
|
404
410
|
d.alerts.forEach(a => {
|
|
405
411
|
const temp = [
|