fleetmap-reports 2.0.139 → 2.0.141
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
|
@@ -7,7 +7,7 @@ const jsPDF = require('jspdf')
|
|
|
7
7
|
const { headerFromUser, addTable } = require('../util/pdfDocument')
|
|
8
8
|
const { getStyle } = require('../reportStyle')
|
|
9
9
|
const { getUserPartner } = require('fleetmap-partners')
|
|
10
|
-
const {
|
|
10
|
+
const { getOverspeedEvents } = require('../speeding-report')
|
|
11
11
|
const { calculateConsumption } = require('../util/fuel')
|
|
12
12
|
const { getCanAvgConsumption } = require('../fuel-consumption-report')
|
|
13
13
|
|
|
@@ -49,25 +49,30 @@ async function create (from, to, userData, traccar) {
|
|
|
49
49
|
|
|
50
50
|
const drivers = userData.drivers
|
|
51
51
|
const devices = userData.devices
|
|
52
|
+
userData.geofences = []
|
|
53
|
+
userData.roadSpeedLimits = true
|
|
52
54
|
|
|
53
55
|
let deviceCount = 0
|
|
54
56
|
const driversData = new Map()
|
|
57
|
+
const overspeedEvents = await getOverspeedEvents(from, to, userData, devices, userData, traccar)
|
|
58
|
+
|
|
55
59
|
for (const device of devices) {
|
|
56
60
|
const allInOne = await traccarHelper.getAllInOne(traccar, from, to, [device], true, true, false, false, deviceCount, devices.length)
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
// getEvents
|
|
60
|
-
const geofenceAlarm = 0
|
|
61
|
-
const continuesDrivingAlarm = 0
|
|
62
|
-
const reverseAlarm = 0
|
|
63
|
-
const otherAlarm = 0
|
|
61
|
+
const deviceOverspeedEvents = overspeedEvents.find(e => e.device.id === device.id)
|
|
62
|
+
const { data } = await traccar.reports.reportsEventsGet(from, to, [device.id], null, ['alarm'])
|
|
64
63
|
|
|
65
64
|
for (const d of drivers) {
|
|
66
65
|
const { trips, route } = await getDriverData(d, allInOne, userData)
|
|
67
|
-
const
|
|
68
|
-
const
|
|
66
|
+
const positionsIds = route.map(p => p.id)
|
|
67
|
+
const events = data.filter(e => positionsIds.includes(e.positionId))
|
|
68
|
+
const driverOverSpeedEvents = deviceOverspeedEvents ? deviceOverspeedEvents.alerts.filter(e => positionsIds.includes(e.position.id)) : []
|
|
69
69
|
const spentFuel = calculateConsumption(device, { trips, route })
|
|
70
70
|
|
|
71
|
+
const geofenceAlarm = events.filter(e => e.attributes.alarm === 'la ceinture').length
|
|
72
|
+
const continuesDrivingAlarm = events.filter(e => e.attributes.alarm === 'Conduite continue').length
|
|
73
|
+
const reverseAlarm = events.filter(e => e.attributes.alarm === 'MARCHE ARIERRE').length
|
|
74
|
+
const otherAlarm = events.length - (geofenceAlarm + continuesDrivingAlarm + reverseAlarm)
|
|
75
|
+
|
|
71
76
|
let driverData = driversData.get(d.id)
|
|
72
77
|
if (!driverData) {
|
|
73
78
|
driverData = {
|
package/src/speeding-report.js
CHANGED
|
@@ -79,20 +79,13 @@ function processServerSide () {
|
|
|
79
79
|
return (process.env.PROCESS_HERE_EVENTS && process.env.PROCESS_HERE_EVENTS === 'server')
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
async function
|
|
83
|
-
const devices = devicesToProcess(userData)
|
|
84
|
-
|
|
85
|
-
const allData = {
|
|
86
|
-
devices: [],
|
|
87
|
-
xpert: devices.filter(d => d && d.attributes && d.attributes.xpert).length > 0
|
|
88
|
-
}
|
|
89
|
-
|
|
82
|
+
async function getOverspeedEvents (from, to, userData, devices, allData, traccarInstance) {
|
|
90
83
|
const _sliced = automaticReports.sliceArray(automaticReports.sliceArray(devices, 5), 5)
|
|
91
|
-
|
|
92
84
|
let deviceCount = 0
|
|
85
|
+
const overspeedEvents = []
|
|
93
86
|
for (const sliced of _sliced) {
|
|
94
87
|
await Promise.all(sliced.map(async slice => {
|
|
95
|
-
|
|
88
|
+
overspeedEvents.push(...await getEvents(traccarInstance, from, to, slice, userData, deviceCount, devices.length, slice.length))
|
|
96
89
|
deviceCount = deviceCount + slice.length
|
|
97
90
|
if (processServerSide()) {
|
|
98
91
|
console.log('LOADING_MESSAGE:' + slice[0].name)
|
|
@@ -100,6 +93,18 @@ async function createSpeedingReportByDevice (from, to, userData, traccarInstance
|
|
|
100
93
|
}
|
|
101
94
|
}))
|
|
102
95
|
}
|
|
96
|
+
return overspeedEvents
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
async function createSpeedingReportByDevice (from, to, userData, traccarInstance) {
|
|
100
|
+
const devices = devicesToProcess(userData)
|
|
101
|
+
|
|
102
|
+
const allData = {
|
|
103
|
+
devices: [],
|
|
104
|
+
xpert: devices.filter(d => d && d.attributes && d.attributes.xpert).length > 0
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
allData.devices = await getOverspeedEvents(from, to, userData, devices, allData, traccarInstance)
|
|
103
108
|
|
|
104
109
|
return allData
|
|
105
110
|
}
|
|
@@ -351,7 +356,7 @@ async function invokeValhalla (route, i, chunk, country, threshold, results, ret
|
|
|
351
356
|
lon: p.longitude,
|
|
352
357
|
lat: p.latitude
|
|
353
358
|
}))
|
|
354
|
-
}, { timeout:
|
|
359
|
+
}, { timeout: 50000 })
|
|
355
360
|
.then(r => r.data)
|
|
356
361
|
countSuccess++
|
|
357
362
|
lastSuccessDuration = new Date() - now
|
|
@@ -703,4 +708,4 @@ exports.exportSpeedingReportToExcel = exportSpeedingReportToExcel
|
|
|
703
708
|
exports.create = createSpeedingReport
|
|
704
709
|
exports.exportToPDF = exportSpeedingReportToPDF
|
|
705
710
|
exports.exportToExcel = exportSpeedingReportToExcel
|
|
706
|
-
exports.
|
|
711
|
+
exports.getOverspeedEvents = getOverspeedEvents
|
package/src/util/utils.js
CHANGED
|
@@ -320,7 +320,7 @@ exports.convertFromUTCDate = (value, user) => {
|
|
|
320
320
|
return convertFromUTC(value, user.attributes.timezone || getUserPartner(user).timezone)
|
|
321
321
|
}
|
|
322
322
|
|
|
323
|
-
exports.getCountry = position => position && position.
|
|
323
|
+
exports.getCountry = position => position && position.address && position.address.split(',').slice(-1)[0].trim()
|
|
324
324
|
|
|
325
325
|
exports.processServerSide = (userData) => {
|
|
326
326
|
const devices = devicesToProcess(userData)
|