fleetmap-reports 1.0.919 → 1.0.921
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/kms-report.js +26 -20
- package/src/tests/zones.test.js +9 -8
- package/src/util/utils.js +12 -0
package/package.json
CHANGED
package/src/kms-report.js
CHANGED
|
@@ -7,7 +7,7 @@ const {
|
|
|
7
7
|
} = require('./util/pdfDocument')
|
|
8
8
|
const { getUserPartner } = require('fleetmap-partners')
|
|
9
9
|
const traccar = require('./util/traccar')
|
|
10
|
-
const { getDates, getTranslations } = require('./util/utils')
|
|
10
|
+
const { getDates, getTranslations, isClientSide, executeServerSide } = require('./util/utils')
|
|
11
11
|
const drivers = require('./util/driver')
|
|
12
12
|
const { isInsideTimetable, isPartialInsideTimetable, calculateTrip, getDataByDay, checkTripsKms } = require('./util/trips')
|
|
13
13
|
const traccarHelper = require('./util/traccar')
|
|
@@ -43,21 +43,29 @@ async function createKmsReportByDevice (from, to, userData, traccarInstance) {
|
|
|
43
43
|
to
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
46
|
+
if (isClientSide() && allDevices.length > 50 && userData.groupByDay) {
|
|
47
|
+
const sliced = automaticReports.sliceArray(allDevices, 20)
|
|
48
|
+
await executeServerSide('kms-report', allData, sliced, from, to, userData, allDevices.length)
|
|
49
|
+
} else {
|
|
50
|
+
let deviceCount = 0
|
|
51
|
+
const sliced = automaticReports.sliceArray(allDevices, 20)
|
|
52
|
+
for (const devices of sliced) {
|
|
53
|
+
const needRoute = !userData.allWeek
|
|
54
|
+
const {
|
|
55
|
+
trips,
|
|
56
|
+
route
|
|
57
|
+
} = await traccar.getAllInOne(traccarInstance, from, to, devices, needRoute, true, false, false, deviceCount, allDevices.length, 10, 2)
|
|
58
|
+
|
|
59
|
+
// Process report data
|
|
60
|
+
if (trips.length) {
|
|
61
|
+
checkTripsKms(traccarInstance, from, to, allDevices, { trips, route })
|
|
62
|
+
allData.devices = allData.devices.concat(await processDevices(from, to, allDevices, {
|
|
63
|
+
trips,
|
|
64
|
+
route
|
|
65
|
+
}, userData, traccarInstance))
|
|
66
|
+
}
|
|
67
|
+
deviceCount += devices.length
|
|
59
68
|
}
|
|
60
|
-
deviceCount += devices.length
|
|
61
69
|
}
|
|
62
70
|
|
|
63
71
|
return allData
|
|
@@ -166,17 +174,15 @@ async function processDevices (from, to, devices, data, userData, traccarInstanc
|
|
|
166
174
|
|
|
167
175
|
if (userData.groupByDay) {
|
|
168
176
|
if (trips.length > 0) {
|
|
169
|
-
const days = []
|
|
170
177
|
const trips = deviceTrips.filter(t => userData.allWeek || !userData.weekDays || isInsideTimetable(t, userData) || isPartialInsideTimetable(t, userData, deviceRoute))
|
|
171
178
|
const dates = getDates(from, to, userData.user.attributes.timezone || getUserPartner(userData.user).timezone)
|
|
172
|
-
|
|
179
|
+
const days = await Promise.all(dates.map(async date => {
|
|
173
180
|
const { tripsByDay } = await getDataByDay(d, date, { trips }, userData, traccarInstance)
|
|
174
|
-
|
|
181
|
+
return {
|
|
175
182
|
date,
|
|
176
183
|
kms: tripsByDay.reduce((a, b) => a + b.distance, 0)
|
|
177
184
|
}
|
|
178
|
-
|
|
179
|
-
}
|
|
185
|
+
}))
|
|
180
186
|
|
|
181
187
|
devicesResult.push({
|
|
182
188
|
device: d,
|
package/src/tests/zones.test.js
CHANGED
|
@@ -45,18 +45,19 @@ describe('zones', function () {
|
|
|
45
45
|
|
|
46
46
|
// eslint-disable-next-line no-undef
|
|
47
47
|
it('works with casais zones in columns', async () => {
|
|
48
|
-
const report = await getReports(
|
|
48
|
+
const report = await getReports('fleetmap.joao.penas2@gmail.com', 'penas46881')
|
|
49
49
|
const userData = await report.getUserData()
|
|
50
50
|
userData.zonesByColumn = true
|
|
51
|
-
userData.devices = userData.devices.filter(d => d.
|
|
52
|
-
userData.geofences = userData.geofences.filter(g => g.name === 'baliza 1 - raio verde '
|
|
53
|
-
|
|
51
|
+
userData.devices = userData.devices.filter(d => d.id === 81202)
|
|
52
|
+
userData.geofences = userData.geofences.filter(g => g.name === 'baliza 1 - raio verde ' ||
|
|
53
|
+
g.name === 'baliza 2 - raio amarelo')
|
|
54
|
+
userData.onlyWithKmsOut = false
|
|
54
55
|
const result = await report.zoneReport(
|
|
55
|
-
new Date(Date.UTC(2023,
|
|
56
|
-
new Date(Date.UTC(2023,
|
|
56
|
+
new Date(Date.UTC(2023, 6, 13, 0, 0, 0, 0)),
|
|
57
|
+
new Date(Date.UTC(2023, 6, 13, 23, 59, 59, 0)),
|
|
57
58
|
userData)
|
|
58
|
-
const first = result[0].devices[0]
|
|
59
|
+
const first = result[0].devices[0]
|
|
59
60
|
console.log(first)
|
|
60
|
-
assert.equal(first.distanceOut,
|
|
61
|
+
assert.equal(first.days[0].distanceOut, 28)
|
|
61
62
|
}, 4000000)
|
|
62
63
|
})
|
package/src/util/utils.js
CHANGED
|
@@ -224,6 +224,18 @@ function weekDaySelected (date, weekDays) {
|
|
|
224
224
|
(date.getDay() === 6 && weekDays.saturday))
|
|
225
225
|
}
|
|
226
226
|
|
|
227
|
+
async function executeServerSide (type, allData, sliced, from, to, userData, totalDevices) {
|
|
228
|
+
let deviceCount = 0
|
|
229
|
+
for (const devices of sliced) {
|
|
230
|
+
const url = `https://${process.env.SERVER_HOST}/reports/${type}`
|
|
231
|
+
const data = await axios.post(url, { from, to, userData: { ...userData, devices } }, { withCredentials: true }).then(d => d.data)
|
|
232
|
+
allData.devices.push(...(data[0].devices))
|
|
233
|
+
deviceCount = deviceCount + devices.length
|
|
234
|
+
console.log(`PROGRESS_PERC:${deviceCount / totalDevices * 100}`)
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
exports.executeServerSide = executeServerSide
|
|
227
239
|
exports.getImgFromUrl = getImgFromUrl
|
|
228
240
|
exports.convertMS = convertMS
|
|
229
241
|
exports.coordsDistance = coordsDistance
|