fleetmap-reports 2.0.28 → 2.0.30
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/RapportPerformance.xlsx +0 -0
- package/package.json +1 -1
- package/src/index.js +21 -0
- package/src/kms-report.js +34 -20
- package/src/partnerReports/dailyuse-report.js +73 -1
- package/src/partnerReports/delayedstart-report.js +69 -0
- package/src/partnerReports/passenger-report.js +46 -0
- package/src/speeding-report.js +1 -1
- package/src/temperature-report.js +11 -0
- package/src/tests/dailyuse.test.js +19 -0
- package/src/tests/gpsjump.test.js +23 -0
- package/src/tests/kms.test.js +9 -0
- package/src/util/driver.js +6 -1
- package/src/util/utils.js +18 -11
|
Binary file
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -18,6 +18,7 @@ function Reports (config, axios) {
|
|
|
18
18
|
drivers: await this.traccar.drivers.driversGet().then(d => d.data),
|
|
19
19
|
geofences: await this.traccar.geofences.geofencesGet().then(d => d.data),
|
|
20
20
|
byGroup: false,
|
|
21
|
+
allWeek: true,
|
|
21
22
|
dayHours: { startTime: '00:00', endTime: '23:59' }
|
|
22
23
|
}
|
|
23
24
|
}
|
|
@@ -182,5 +183,25 @@ function Reports (config, axios) {
|
|
|
182
183
|
this.stopReportToExcel = (userData, reportData) => {
|
|
183
184
|
return require('./stop-report').exportStopReportToExcel(userData, reportData)
|
|
184
185
|
}
|
|
186
|
+
|
|
187
|
+
this.performanceReport = (from, to, userData) => {
|
|
188
|
+
return require('./partnerReports/performance-report').createPerformanceReport(from, to, userData, this.traccar)
|
|
189
|
+
}
|
|
190
|
+
this.performanceReportToPDF = (userData, reportData) => {
|
|
191
|
+
return require('./partnerReports/performance-report').exportPerformanceReportToPDF(userData, reportData)
|
|
192
|
+
}
|
|
193
|
+
this.performanceReportToExcel = (userData, reportData) => {
|
|
194
|
+
return require('./partnerReports/performance-report').exportPerformanceReportToExcel(userData, reportData)
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
this.dailyUseReport = (from, to, userData) => {
|
|
198
|
+
return require('./partnerReports/dailyuse-report').createDailyUseReport(from, to, userData, this.traccar)
|
|
199
|
+
}
|
|
200
|
+
this.dailyUseReportToPDF = (userData, reportData) => {
|
|
201
|
+
return require('./partnerReports/dailyuse-report').exportDailyUseReportToPDF(userData, reportData)
|
|
202
|
+
}
|
|
203
|
+
this.dailyUseReportToExcel = (userData, reportData) => {
|
|
204
|
+
return require('./partnerReports/dailyuse-report').exportDailyUseReportToExcel(userData, reportData)
|
|
205
|
+
}
|
|
185
206
|
}
|
|
186
207
|
module.exports = Reports
|
package/src/kms-report.js
CHANGED
|
@@ -8,7 +8,7 @@ const {
|
|
|
8
8
|
const { getUserPartner } = require('fleetmap-partners')
|
|
9
9
|
const traccar = require('./util/traccar')
|
|
10
10
|
const { getDates, getTranslations, isClientSide, executeServerSide } = require('./util/utils')
|
|
11
|
-
const
|
|
11
|
+
const driversUtil = require('./util/driver')
|
|
12
12
|
const { isInsideTimetable, isPartialInsideTimetable, calculateTrip, getDataByDay, checkTripsKms, getKms } = require('./util/trips')
|
|
13
13
|
const { devicesToProcess } = require('./util/device')
|
|
14
14
|
const { getDriverData, reportByDriver } = require('./util/driver')
|
|
@@ -45,7 +45,9 @@ async function createKmsReportByDevice (from, to, userData, traccarInstance) {
|
|
|
45
45
|
|
|
46
46
|
if (isClientSide() && (allDevices.length > 50 || ((new Date(to).getTime() - new Date(from).getTime()) > (1000 * 60 * 60 * 24 * 15))) && userData.groupByDay) {
|
|
47
47
|
const sliced = automaticReports.sliceArray(allDevices, 1)
|
|
48
|
-
await executeServerSide('kms-report',
|
|
48
|
+
await executeServerSide('kms-report', sliced, from, to, userData, allDevices.length, traccarInstance).then(devices => {
|
|
49
|
+
allData.devices = devices
|
|
50
|
+
})
|
|
49
51
|
} else {
|
|
50
52
|
if (userData.allWeek && userData.groupByDay) {
|
|
51
53
|
const dates = getDates(from, to, userData.user.attributes.timezone || getUserPartner(userData.user).timezone)
|
|
@@ -100,29 +102,41 @@ async function createKmsReportByDevice (from, to, userData, traccarInstance) {
|
|
|
100
102
|
}
|
|
101
103
|
|
|
102
104
|
async function createKmsReportByDriver (from, to, userData, traccarInstance) {
|
|
103
|
-
const
|
|
105
|
+
const report = { drivers: [] }
|
|
104
106
|
|
|
105
|
-
const
|
|
107
|
+
const { devices, drivers } = await driversUtil.devicesByDriver(traccarInstance, from, to, userData.drivers, userData.devices)
|
|
106
108
|
|
|
107
|
-
|
|
109
|
+
console.log(drivers.length, devices.length)
|
|
108
110
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
111
|
+
userData.devices = devices
|
|
112
|
+
userData.drivers = drivers
|
|
113
|
+
|
|
114
|
+
if (isClientSide() && (userData.drivers.length > 50 || ((new Date(to).getTime() - new Date(from).getTime()) > (1000 * 60 * 60 * 24 * 15))) && userData.groupByDay) {
|
|
115
|
+
const sliced = automaticReports.sliceArray(userData.drivers, 10)
|
|
116
|
+
await executeServerSide('kms-report', sliced, from, to, userData, userData.drivers.length, traccarInstance, 5).then(drivers => {
|
|
117
|
+
report.drivers = drivers
|
|
118
|
+
})
|
|
119
|
+
} else {
|
|
120
|
+
const results = await reportByDriver(userData.devices, traccarInstance, from, to, userData, processDrivers)
|
|
121
|
+
|
|
122
|
+
results.drivers.forEach(result => {
|
|
123
|
+
const driver = report.drivers.find(d => d.driver.id === result.driver.id)
|
|
124
|
+
if (driver) {
|
|
125
|
+
if (userData.groupByDay) {
|
|
126
|
+
driver.days.forEach(day => {
|
|
127
|
+
const resultDay = result.days.find(d => d.date === day.date)
|
|
128
|
+
if (resultDay) {
|
|
129
|
+
day.kms = day.kms + resultDay.kms
|
|
130
|
+
}
|
|
131
|
+
})
|
|
132
|
+
} else {
|
|
133
|
+
driver.summary.distance = driver.summary.distance + result.summary.distance
|
|
134
|
+
}
|
|
119
135
|
} else {
|
|
120
|
-
|
|
136
|
+
report.drivers.push(result)
|
|
121
137
|
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
}
|
|
125
|
-
})
|
|
138
|
+
})
|
|
139
|
+
}
|
|
126
140
|
|
|
127
141
|
return report
|
|
128
142
|
}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
const traccarHelper = require('../util/traccar')
|
|
2
2
|
const { isInsideTimetable } = require('../util/trips')
|
|
3
|
-
const { convertFromUTCDate } = require('../util/utils')
|
|
3
|
+
const { convertFromUTCDate, getTranslations, convertMS, convertToLocaleTimeString, isClientSide } = require('../util/utils')
|
|
4
4
|
const automaticReports = require('../automaticReports')
|
|
5
|
+
const jsPDF = require('jspdf')
|
|
6
|
+
const { getStyle } = require('../reportStyle')
|
|
7
|
+
const { getUserPartner } = require('fleetmap-partners')
|
|
8
|
+
const { addTable, headerFromUser } = require('../util/pdfDocument')
|
|
5
9
|
|
|
6
10
|
async function createDailyUseReport (from, to, userData, traccar) {
|
|
7
11
|
const reportData = []
|
|
@@ -77,4 +81,72 @@ function processDeviceData (allInOne, d, userData) {
|
|
|
77
81
|
}
|
|
78
82
|
}
|
|
79
83
|
|
|
84
|
+
async function exportDailyUseReportToPDF (userData, reportData) {
|
|
85
|
+
const translations = getTranslations(userData)
|
|
86
|
+
const timezone = userData.user.attributes.timezone
|
|
87
|
+
const lang = userData.user.attributes.lang || (isClientSide() && navigator.language)
|
|
88
|
+
|
|
89
|
+
const headers = [
|
|
90
|
+
translations.report.vehicle,
|
|
91
|
+
'Immatriculation',
|
|
92
|
+
'Groupe',
|
|
93
|
+
'Matin départ',
|
|
94
|
+
'Matin arrêt',
|
|
95
|
+
'Matin temps',
|
|
96
|
+
'Déjeuner',
|
|
97
|
+
'Après-midi départ',
|
|
98
|
+
'Après-midi arrêt',
|
|
99
|
+
'Après-midi temps',
|
|
100
|
+
'Total temps',
|
|
101
|
+
'Total conduit',
|
|
102
|
+
'Total arrêts',
|
|
103
|
+
'Total kms'
|
|
104
|
+
]
|
|
105
|
+
|
|
106
|
+
const data = []
|
|
107
|
+
reportData.forEach(d => {
|
|
108
|
+
const row = [
|
|
109
|
+
d.device,
|
|
110
|
+
d.licensePlate,
|
|
111
|
+
d.group,
|
|
112
|
+
convertToLocaleTimeString(d.morningStart, lang, timezone, userData.user),
|
|
113
|
+
convertToLocaleTimeString(d.morningEnd, lang, timezone, userData.user),
|
|
114
|
+
convertMS(d.morningTime),
|
|
115
|
+
convertMS(d.lunch),
|
|
116
|
+
convertToLocaleTimeString(d.afternoonStart, lang, timezone, userData.user),
|
|
117
|
+
convertToLocaleTimeString(d.afternoonEnd, lang, timezone, userData.user),
|
|
118
|
+
convertMS(d.afternoonTime),
|
|
119
|
+
convertMS(d.totalTime),
|
|
120
|
+
convertMS(d.totalDrivingTime),
|
|
121
|
+
d.totalStops,
|
|
122
|
+
(d.totalDistance / 100).toFixed(1)
|
|
123
|
+
]
|
|
124
|
+
data.push(row)
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
const doc = new jsPDF.jsPDF('l')
|
|
128
|
+
await headerFromUser(doc, 'Rapport de Performance', userData.user)
|
|
129
|
+
const style = getStyle(getUserPartner(userData.user))
|
|
130
|
+
|
|
131
|
+
const footValues = []
|
|
132
|
+
|
|
133
|
+
doc.setFontSize(11)
|
|
134
|
+
doc.text(new Date(userData.from).toLocaleString() + ' - ' + new Date(userData.to).toLocaleString(), 20, 33)
|
|
135
|
+
|
|
136
|
+
style.headerFontSize = 8
|
|
137
|
+
style.bodyFontSize = 7
|
|
138
|
+
const columnStyles = {}
|
|
139
|
+
for (let i = 3; i < 14; i++) {
|
|
140
|
+
columnStyles[i] = { halign: 'right' }
|
|
141
|
+
}
|
|
142
|
+
addTable(doc, headers, data, footValues, style, 40, columnStyles)
|
|
143
|
+
return doc
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function exportDailyUseReportToExcel (userData, reportData) {
|
|
147
|
+
|
|
148
|
+
}
|
|
149
|
+
|
|
80
150
|
exports.createDailyUseReport = createDailyUseReport
|
|
151
|
+
exports.exportDailyUseReportToPDF = exportDailyUseReportToPDF
|
|
152
|
+
exports.exportDailyUseReportToExcel = exportDailyUseReportToExcel
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
const automaticReports = require('../automaticReports')
|
|
2
|
+
const traccarHelper = require('../util/traccar')
|
|
3
|
+
const { getDates, getTranslations } = require('../util/utils')
|
|
4
|
+
const { getUserPartner } = require('fleetmap-partners')
|
|
5
|
+
const { getDataByDay } = require('../util/trips')
|
|
6
|
+
|
|
7
|
+
async function createDelayedStartReport (from, to, userData, traccar) {
|
|
8
|
+
const reportData = []
|
|
9
|
+
|
|
10
|
+
const devices = userData.devices
|
|
11
|
+
|
|
12
|
+
const sliced = automaticReports.sliceArray(devices, 5)
|
|
13
|
+
let deviceCount = 0
|
|
14
|
+
for (const slice of sliced) {
|
|
15
|
+
const allInOne = await traccarHelper.getAllInOne(traccar, from, to, slice, false, true, true, false, deviceCount, devices.length)
|
|
16
|
+
|
|
17
|
+
for (const d of slice) {
|
|
18
|
+
const deviceData = await processDeviceData(from, to, allInOne, d, userData, traccar)
|
|
19
|
+
reportData.push(deviceData)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
deviceCount = deviceCount + slice.length
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return reportData
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async function processDeviceData (from, to, allInOne, d, userData, traccar) {
|
|
29
|
+
const group = userData.groups.find(g => g.id === d.groupId)
|
|
30
|
+
const trips = allInOne.trips.filter(t => t.deviceId === d.id)
|
|
31
|
+
const translations = getTranslations(userData)
|
|
32
|
+
|
|
33
|
+
const weekDays = [
|
|
34
|
+
translations.report.sunday,
|
|
35
|
+
translations.report.monday,
|
|
36
|
+
translations.report.tuesday,
|
|
37
|
+
translations.report.wednesday,
|
|
38
|
+
translations.report.thursday,
|
|
39
|
+
translations.report.friday,
|
|
40
|
+
translations.report.saturday
|
|
41
|
+
]
|
|
42
|
+
|
|
43
|
+
const dates = getDates(from, to, userData.user.attributes.timezone || getUserPartner(userData.user).timezone)
|
|
44
|
+
|
|
45
|
+
const deviceData = {
|
|
46
|
+
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
for (const date of dates) {
|
|
50
|
+
const { tripsByDay } = await getDataByDay(d, date, { trips }, userData, traccar)
|
|
51
|
+
|
|
52
|
+
if (tripsByDay.length > 0) {
|
|
53
|
+
const startTime = tripsByDay[0].startTime
|
|
54
|
+
const stopTime = tripsByDay[tripsByDay.length].endTime
|
|
55
|
+
|
|
56
|
+
const deviceDayData = {
|
|
57
|
+
device: d.name,
|
|
58
|
+
licensePlate: d.attributes.license_plate,
|
|
59
|
+
group: group ? group.name : '',
|
|
60
|
+
driver: '',
|
|
61
|
+
weekDay: weekDays[new Date(date).getDay()],
|
|
62
|
+
startDate: '',
|
|
63
|
+
startTime: '',
|
|
64
|
+
delayDescription: '',
|
|
65
|
+
stopTime: ''
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
async function createPassengerReport (from, to, userData, traccar) {
|
|
2
|
+
//const allDevices = await traccar.axios.get('/devices').then(d => d.data)
|
|
3
|
+
const devices = userData.devices
|
|
4
|
+
const drivers = await traccar.axios.get('/drivers').then(d => d.data)
|
|
5
|
+
const groups = await traccar.axios.get('/groups').then(d => d.data)
|
|
6
|
+
await Promise.all(groups.map(async g => {
|
|
7
|
+
const driversByGroup = await traccar.axios.get(`/drivers?groupId=${g.id}`).then(d => d.data)
|
|
8
|
+
driversByGroup.forEach(d => {
|
|
9
|
+
const _driver = drivers.find(a => a.id === d.id)
|
|
10
|
+
if (_driver) {
|
|
11
|
+
_driver.groupName = g.name
|
|
12
|
+
}
|
|
13
|
+
})
|
|
14
|
+
}))
|
|
15
|
+
const eventsUrl = `/reports/events?${devices.map(d => 'deviceId=' + d.id).join('&')
|
|
16
|
+
}&from=${from.toISOString()
|
|
17
|
+
}&to=${to.toISOString()
|
|
18
|
+
}`
|
|
19
|
+
const positionsUrl = `/reports/route?${devices.map(d => 'deviceId=' + d.id).join('&')
|
|
20
|
+
}&from=${from.toISOString()
|
|
21
|
+
}&to=${to.toISOString()
|
|
22
|
+
}`
|
|
23
|
+
const events = await traccar.axios.get(eventsUrl).then(d => d.data)
|
|
24
|
+
const positions = await traccar.axios.get(positionsUrl).then(d => d.data)
|
|
25
|
+
events.forEach(e => {
|
|
26
|
+
delete e.attributes
|
|
27
|
+
const driver = getDriver(e, positions, drivers)
|
|
28
|
+
const position = positions.find(p => p.id === e.positionId)
|
|
29
|
+
e.deviceName = devices.find(d => d.id === e.deviceId).name
|
|
30
|
+
e.groupName = driver.groupName || ''
|
|
31
|
+
e.fixtime = position && new Date(position.fixTime)
|
|
32
|
+
e.notes = driver && driver.attributes.notes
|
|
33
|
+
e.driverName = (driver && driver.name) || (position && position.attributes.driverUniqueId)
|
|
34
|
+
})
|
|
35
|
+
return events
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function getDriver (event, positions, drivers) {
|
|
39
|
+
const p = positions.find(p => p.id === event.positionId)
|
|
40
|
+
if (!p) { return '' }
|
|
41
|
+
const d = drivers.find(d => d.uniqueId === p.attributes.driverUniqueId)
|
|
42
|
+
if (!d) { return '' }
|
|
43
|
+
return d
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
exports.createPassengerReport = createPassengerReport
|
package/src/speeding-report.js
CHANGED
|
@@ -102,7 +102,7 @@ async function createSpeedingReportByDevice (from, to, userData, traccarInstance
|
|
|
102
102
|
}
|
|
103
103
|
|
|
104
104
|
async function createSpeedingReportByDriver (from, to, userData, traccarInstance) {
|
|
105
|
-
const devices = await drivers.devicesByDriver(traccarInstance, from, to, userData.drivers, userData.devices)
|
|
105
|
+
const { devices } = await drivers.devicesByDriver(traccarInstance, from, to, userData.drivers, userData.devices)
|
|
106
106
|
console.log('Devices with driver', devices.length)
|
|
107
107
|
const _drivers = []
|
|
108
108
|
const sliced = automaticReports.sliceArray(devices, 5)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const traccarHelper = require('./util/traccar')
|
|
2
|
+
const { devicesToProcess } = require('./util/device')
|
|
3
|
+
|
|
4
|
+
async function createTemperatureReport (from, to, userData, traccar) {
|
|
5
|
+
const devices = devicesToProcess(userData)
|
|
6
|
+
|
|
7
|
+
const allInOne = await traccarHelper.getAllInOne(traccar, from, to, devices, true, false, false, false)
|
|
8
|
+
const routeData = allInOne.route
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const { getReports } = require('./index')
|
|
2
|
+
const assert = require('assert')
|
|
3
|
+
const { createDailyUseReport } = require('../partnerReports/dailyuse-report')
|
|
4
|
+
|
|
5
|
+
describe('dailyuse', function () {
|
|
6
|
+
// eslint-disable-next-line no-undef
|
|
7
|
+
it('dailyuse report', async () => {
|
|
8
|
+
const report = await getReports()
|
|
9
|
+
const userData = await report.getUserData()
|
|
10
|
+
|
|
11
|
+
const data = await createDailyUseReport(
|
|
12
|
+
new Date(Date.UTC(2023, 10, 1, 0, 0, 0, 0)),
|
|
13
|
+
new Date(Date.UTC(2023, 10, 6, 23, 59, 59, 0)),
|
|
14
|
+
userData,
|
|
15
|
+
report.traccar)
|
|
16
|
+
console.log(data)
|
|
17
|
+
assert.equal(data[0].consumption, 19.799999999999997)
|
|
18
|
+
}, 8000000)
|
|
19
|
+
})
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const { getReports } = require('./index')
|
|
2
|
+
const assert = require('assert')
|
|
3
|
+
const { convertMS } = require('../util/utils')
|
|
4
|
+
const { createGPSJumpReport } = require('../partnerReports/gpsjump-report')
|
|
5
|
+
|
|
6
|
+
// eslint-disable-next-line no-undef
|
|
7
|
+
describe('gpsjump', function () {
|
|
8
|
+
// eslint-disable-next-line no-undef
|
|
9
|
+
it('gpsjump report', async () => {
|
|
10
|
+
const report = await getReports()
|
|
11
|
+
const userData = await report.getUserData()
|
|
12
|
+
userData.devices = userData.devices.filter(d => d.id === 22326)
|
|
13
|
+
const data = await createGPSJumpReport(
|
|
14
|
+
new Date(Date.UTC(2023, 6, 1, 0, 0, 0, 0)),
|
|
15
|
+
new Date(Date.UTC(2023, 6, 17, 23, 59, 59, 0)),
|
|
16
|
+
userData,
|
|
17
|
+
report.traccar)
|
|
18
|
+
console.log(data)
|
|
19
|
+
assert.equal(data[0].consumption, 19.799999999999997)
|
|
20
|
+
assert.equal(data[0].distance, 326.7657)
|
|
21
|
+
assert.equal(convertMS(data[1].time * 1000, false), '08:19')
|
|
22
|
+
}, 8000000)
|
|
23
|
+
})
|
package/src/tests/kms.test.js
CHANGED
|
@@ -52,4 +52,13 @@ describe('Kms_Reports', function () {
|
|
|
52
52
|
assert.equal(device.days.length, 30) // Total Kms
|
|
53
53
|
assert.equal(device.days[29].kms, 136174.93281451002) // Total Kms
|
|
54
54
|
}, 30000)
|
|
55
|
+
it('KmsReport by driver', async () => {
|
|
56
|
+
const reports = await getReports()
|
|
57
|
+
const userData = await reports.getUserData()
|
|
58
|
+
userData.byDriver = true
|
|
59
|
+
console.log(userData.drivers)
|
|
60
|
+
const data = await reports.kmsReport(new Date(2024, 0, 24, 0, 0, 0), new Date(2024, 0, 24, 23, 59, 59),
|
|
61
|
+
userData)
|
|
62
|
+
assert.equal(data.length, 1)
|
|
63
|
+
}, 3000000)
|
|
55
64
|
})
|
package/src/util/driver.js
CHANGED
|
@@ -7,14 +7,19 @@ const { isInsideTimetable, isPartialInsideTimetable } = require('./trips')
|
|
|
7
7
|
async function devicesByDriver (traccarInstance, from, to, drivers, devices) {
|
|
8
8
|
const eventsData = await traccar.getEvents(traccarInstance, from, to, devices, ['driverChanged'])
|
|
9
9
|
const deviceIds = []
|
|
10
|
+
const driversIds = []
|
|
10
11
|
for (const d of drivers) {
|
|
11
12
|
const events = eventsData.filter(e => {
|
|
12
13
|
return !d.uniqueId.localeCompare(e.attributes.driverUniqueId, undefined, { sensitivity: 'base' })
|
|
13
14
|
})
|
|
14
15
|
|
|
16
|
+
if (events.length) {
|
|
17
|
+
driversIds.push(d.id)
|
|
18
|
+
}
|
|
19
|
+
|
|
15
20
|
deviceIds.push(...events.map(e => e.deviceId))
|
|
16
21
|
}
|
|
17
|
-
return devices.filter(d => deviceIds.includes(d.id))
|
|
22
|
+
return { devices: devices.filter(d => deviceIds.includes(d.id)), drivers: drivers.filter(d => driversIds.includes(d.id)) }
|
|
18
23
|
}
|
|
19
24
|
|
|
20
25
|
async function reportByDriver (devices, traccar, from, to, userData, processor) {
|
package/src/util/utils.js
CHANGED
|
@@ -227,31 +227,38 @@ function weekDaySelected (date, weekDays) {
|
|
|
227
227
|
(date.getDay() === 6 && weekDays.saturday))
|
|
228
228
|
}
|
|
229
229
|
|
|
230
|
-
async function executeServerSide (type,
|
|
231
|
-
let
|
|
230
|
+
async function executeServerSide (type, sliced, from, to, userData, totalItems, { axios }, maxRequests = 10) {
|
|
231
|
+
let itemsCount = 0
|
|
232
232
|
console.log('PROGRESS_PERC:1')
|
|
233
|
-
const
|
|
233
|
+
const reportData = []
|
|
234
234
|
for (let i = 0; i < sliced.length; i += maxRequests) {
|
|
235
235
|
const _sliced = sliced.slice(i, i + maxRequests)
|
|
236
|
-
await Promise.all(_sliced.map(async
|
|
236
|
+
await Promise.all(_sliced.map(async items => {
|
|
237
237
|
const url = `https://${process.env.SERVER_HOST}/reports/${type}`
|
|
238
238
|
try {
|
|
239
239
|
const data = await axios.post(url, {
|
|
240
240
|
from,
|
|
241
241
|
to,
|
|
242
|
-
userData:
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
242
|
+
userData: userData.byDriver
|
|
243
|
+
? {
|
|
244
|
+
...userData,
|
|
245
|
+
drivers: items
|
|
246
|
+
}
|
|
247
|
+
: {
|
|
248
|
+
...userData,
|
|
249
|
+
devices: items
|
|
250
|
+
}
|
|
246
251
|
}, { withCredentials: true }).then(d => d.data)
|
|
247
|
-
|
|
248
|
-
|
|
252
|
+
reportData.push(...(userData.byDriver ? data[0].drivers : data[0].devices))
|
|
253
|
+
itemsCount = itemsCount + items.length
|
|
249
254
|
} catch (e) {
|
|
250
255
|
console.error(e)
|
|
251
256
|
}
|
|
252
|
-
console.log(`PROGRESS_PERC:${
|
|
257
|
+
console.log(`PROGRESS_PERC:${itemsCount / totalItems * 100}`)
|
|
253
258
|
}))
|
|
254
259
|
}
|
|
260
|
+
|
|
261
|
+
return reportData
|
|
255
262
|
}
|
|
256
263
|
|
|
257
264
|
exports.executeServerSide = executeServerSide
|