fleetmap-reports 1.0.739 → 1.0.740
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/automaticReports.js +2 -0
- package/src/events-report.js +38 -35
- package/src/tests/events.test.js +15 -0
package/package.json
CHANGED
package/src/automaticReports.js
CHANGED
|
@@ -64,3 +64,5 @@ exports.deviceWithFuelInfo = deviceWithFuelInfo
|
|
|
64
64
|
exports.calculateSpentFuel = calculateSpentFuel
|
|
65
65
|
exports.calculateXpertSpentFuel = calculateXpertSpentFuel
|
|
66
66
|
exports.calculateXpertDistance = calculateXpertDistance
|
|
67
|
+
exports.maxParallelRequests = maxParallelRequests
|
|
68
|
+
|
package/src/events-report.js
CHANGED
|
@@ -8,6 +8,7 @@ const { convertToLocaleString, getTranslations } = require('./util/utils')
|
|
|
8
8
|
const { devicesToProcess } = require('./util/device')
|
|
9
9
|
const { isInside } = require('./util/timetable')
|
|
10
10
|
const { getDigitalPortValue } = require('./location-report')
|
|
11
|
+
const { maxParallelRequests } = require('./automaticReports')
|
|
11
12
|
|
|
12
13
|
const fileName = 'EventReport'
|
|
13
14
|
|
|
@@ -41,7 +42,7 @@ async function createEventsReport (from, to, userData, traccar) {
|
|
|
41
42
|
|
|
42
43
|
const devices = devicesToProcess(userData)
|
|
43
44
|
|
|
44
|
-
const data = await getReportData(from, to, devices, userData.eventTypes, traccar)
|
|
45
|
+
const data = await getReportData(from, to, devices, userData.eventTypes || [], traccar)
|
|
45
46
|
|
|
46
47
|
if (data.length > 0) {
|
|
47
48
|
reportData.push({
|
|
@@ -73,45 +74,47 @@ async function getReportData (from, to, devices, types, traccar) {
|
|
|
73
74
|
async function processDevices (from, to, devices, data, traccar, userData) {
|
|
74
75
|
const devicesResult = []
|
|
75
76
|
let i = 0
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
if (
|
|
89
|
-
a.
|
|
90
|
-
|
|
91
|
-
|
|
77
|
+
for (let j = 0; j < devices.length; j += maxParallelRequests) {
|
|
78
|
+
await Promise.all(devices.slice(j, j + maxParallelRequests).map(async d => {
|
|
79
|
+
const deviceAlerts = data.filter(t => t.deviceId === d.id)
|
|
80
|
+
|
|
81
|
+
const response = await traccar.reports.reportsRouteGet(from, to, [d.id])
|
|
82
|
+
const positions = response.data
|
|
83
|
+
|
|
84
|
+
for (const a of deviceAlerts) {
|
|
85
|
+
a.position = positions.find(p => p.id === a.positionId)
|
|
86
|
+
|
|
87
|
+
if (a.geofenceId) {
|
|
88
|
+
const geofence = userData.geofences.find(g => g.id === a.geofenceId)
|
|
89
|
+
if (geofence) {
|
|
90
|
+
if (a.type === 'deviceOverspeed') {
|
|
91
|
+
a.geofenceName = geofence.name + ' (' + Math.round(a.attributes.speedLimit * 1.85200) + ' Km/h)'
|
|
92
|
+
} else {
|
|
93
|
+
a.geofenceName = geofence.name
|
|
94
|
+
}
|
|
92
95
|
}
|
|
93
96
|
}
|
|
94
|
-
}
|
|
95
97
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
98
|
+
if (a.position && a.position.attributes.driverUniqueId) {
|
|
99
|
+
const driver = userData.drivers.find(d => d.uniqueId === a.position.attributes.driverUniqueId)
|
|
100
|
+
a.driver = driver && driver.name
|
|
101
|
+
}
|
|
99
102
|
}
|
|
100
|
-
}
|
|
101
103
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
104
|
+
const alerts = deviceAlerts.filter(a => userData.allWeek || !userData.weekDays || (!a.position || isInside(a.position.fixTime, a.position.fixTime, userData)))
|
|
105
|
+
console.log('LOADING_MESSAGE:' + d.name)
|
|
106
|
+
console.log(`PROGRESS_PERC:${++i / devices.length * 100}`)
|
|
107
|
+
|
|
108
|
+
if (alerts.length > 0) {
|
|
109
|
+
devicesResult.push({
|
|
110
|
+
device: d,
|
|
111
|
+
from,
|
|
112
|
+
to,
|
|
113
|
+
alerts
|
|
114
|
+
})
|
|
115
|
+
}
|
|
116
|
+
}))
|
|
117
|
+
}
|
|
115
118
|
|
|
116
119
|
return devicesResult
|
|
117
120
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const { getReports } = require('./index')
|
|
2
|
+
// eslint-disable-next-line no-undef
|
|
3
|
+
describe('events', function () {
|
|
4
|
+
// eslint-disable-next-line no-undef
|
|
5
|
+
it('works with many devices', async () => {
|
|
6
|
+
const report = await getReports(process.env.USER_NOGARTEL, process.env.PASS_NOGARTEL)
|
|
7
|
+
const userData = await report.getUserData()
|
|
8
|
+
console.log(userData.devices.length)
|
|
9
|
+
const result = await report.eventsReport(
|
|
10
|
+
new Date(Date.UTC(2023, 5, 11, 0, 0, 0, 0)),
|
|
11
|
+
new Date(Date.UTC(2023, 5, 11, 23, 59, 59, 0)),
|
|
12
|
+
userData)
|
|
13
|
+
console.log('result', result)
|
|
14
|
+
}, 4000000)
|
|
15
|
+
})
|