fleetmap-reports 1.0.785 → 1.0.787
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/activity-report.js +58 -34
- package/src/util/traccar.js +5 -1
package/package.json
CHANGED
package/src/activity-report.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const automaticReports = require('./automaticReports')
|
|
2
|
-
const { convertMS, getDates, getTranslations, weekDaySelected, convertToLocaleString } = require('./util/utils')
|
|
2
|
+
const { convertMS, getDates, getTranslations, weekDaySelected, convertToLocaleString, isClientSide } = require('./util/utils')
|
|
3
3
|
const jsPDF = require('jspdf')
|
|
4
4
|
require('jspdf-autotable')
|
|
5
5
|
const {
|
|
@@ -14,6 +14,7 @@ const tripHelper = require('./util/trips')
|
|
|
14
14
|
const { devicesToProcess } = require('./util/device')
|
|
15
15
|
const { getDriverData } = require('./util/driver')
|
|
16
16
|
const { calculateConsumption } = require('./util/fuel')
|
|
17
|
+
const { default: axios } = require('axios')
|
|
17
18
|
|
|
18
19
|
const fileName = 'ActivityReport'
|
|
19
20
|
|
|
@@ -73,6 +74,25 @@ async function createActivityReportByGroup (from, to, userData, traccarInstance)
|
|
|
73
74
|
return reportData
|
|
74
75
|
}
|
|
75
76
|
|
|
77
|
+
async function executeServerSide (allData, sliced, from, to, userData, totalDevices) {
|
|
78
|
+
let deviceCount = 0
|
|
79
|
+
for (const devices of sliced) {
|
|
80
|
+
const url = `https://${process.env.SERVER_HOST}/reports/activity-report`
|
|
81
|
+
const data = await axios.post(url, {
|
|
82
|
+
from,
|
|
83
|
+
to,
|
|
84
|
+
sliced,
|
|
85
|
+
userData,
|
|
86
|
+
deviceCount,
|
|
87
|
+
totalDevices,
|
|
88
|
+
sliceSize: 50
|
|
89
|
+
}, { withCredentials: true }).then(d => d.data)
|
|
90
|
+
|
|
91
|
+
allData.devices.push(data.devices)
|
|
92
|
+
deviceCount += devices.length
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
76
96
|
async function createActivityReportByDevice (from, to, userData, traccarInstance) {
|
|
77
97
|
const allDevices = devicesToProcess(userData)
|
|
78
98
|
|
|
@@ -83,48 +103,52 @@ async function createActivityReportByDevice (from, to, userData, traccarInstance
|
|
|
83
103
|
to
|
|
84
104
|
}
|
|
85
105
|
|
|
86
|
-
const sliced = automaticReports.sliceArray(allDevices,
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
const {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
106
|
+
const sliced = automaticReports.sliceArray(allDevices, 50)
|
|
107
|
+
if (isClientSide() && allDevices.length > 200) {
|
|
108
|
+
await executeServerSide(allData, sliced, from, to, userData, allDevices.length)
|
|
109
|
+
} else {
|
|
110
|
+
let deviceCount = 0
|
|
111
|
+
for (const devices of sliced) {
|
|
112
|
+
let summaries = []
|
|
113
|
+
const needRoute = userData.groupByDay || !userData.allWeek
|
|
114
|
+
const {
|
|
115
|
+
trips,
|
|
116
|
+
route,
|
|
117
|
+
summary
|
|
118
|
+
} = await traccar.getAllInOne(traccarInstance, from, to, devices, needRoute, true, false, !userData.groupByDay, deviceCount, allDevices.length)
|
|
96
119
|
|
|
97
|
-
|
|
98
|
-
|
|
120
|
+
if (userData.groupByDay) {
|
|
121
|
+
console.log('trips:' + trips.length)
|
|
99
122
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
123
|
+
if (trips.length) {
|
|
124
|
+
tripHelper.checkTripsKms(traccarInstance, from, to, devices, { trips, route })
|
|
125
|
+
}
|
|
103
126
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
127
|
+
const dates = getDates(from, to)
|
|
128
|
+
for (const date of dates) {
|
|
129
|
+
if (userData.allWeek || !userData.weekDays || !userData.dayHours) {
|
|
130
|
+
const fromByDay = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0)
|
|
131
|
+
const toByDay = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 23, 59, 59)
|
|
109
132
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
133
|
+
const summary = await traccar.getSummary(traccarInstance, fromByDay, toByDay, devices)
|
|
134
|
+
summary.forEach(s => {
|
|
135
|
+
s.date = date
|
|
136
|
+
})
|
|
137
|
+
summaries = summaries.concat(summary)
|
|
138
|
+
}
|
|
115
139
|
}
|
|
140
|
+
} else {
|
|
141
|
+
summaries = summary
|
|
116
142
|
}
|
|
117
|
-
} else {
|
|
118
|
-
summaries = summary
|
|
119
|
-
}
|
|
120
143
|
|
|
121
|
-
|
|
144
|
+
console.log('Summary:' + summaries.length)
|
|
122
145
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
146
|
+
// Process report data
|
|
147
|
+
if (summaries.length || trips.length) {
|
|
148
|
+
allData.devices = allData.devices.concat(processDevices(from, to, devices, { summaries, trips, route }, userData))
|
|
149
|
+
}
|
|
150
|
+
deviceCount += devices.length
|
|
126
151
|
}
|
|
127
|
-
deviceCount += devices.length
|
|
128
152
|
}
|
|
129
153
|
|
|
130
154
|
return allData
|
package/src/util/traccar.js
CHANGED
|
@@ -112,7 +112,11 @@ async function getAllInOne (
|
|
|
112
112
|
}
|
|
113
113
|
const now = new Date()
|
|
114
114
|
console.log('parallel', requests.length)
|
|
115
|
-
|
|
115
|
+
try {
|
|
116
|
+
result.push(...(await Promise.all(requests)))
|
|
117
|
+
} catch (e) {
|
|
118
|
+
console.log(e)
|
|
119
|
+
}
|
|
116
120
|
console.log('took', new Date() - now, 'ms')
|
|
117
121
|
}
|
|
118
122
|
return {
|