fleetmap-reports 1.0.951 → 1.0.952
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 +14 -4
- package/src/util/traccar.js +4 -2
package/package.json
CHANGED
package/src/activity-report.js
CHANGED
|
@@ -17,6 +17,7 @@ const { devicesToProcess } = require('./util/device')
|
|
|
17
17
|
const { getDriverData } = require('./util/driver')
|
|
18
18
|
const { calculateConsumption } = require('./util/fuel')
|
|
19
19
|
const axios = require('axios')
|
|
20
|
+
const { getSummaryByDay } = require('./util/traccar')
|
|
20
21
|
|
|
21
22
|
const fileName = 'ActivityReport'
|
|
22
23
|
|
|
@@ -101,6 +102,12 @@ async function createActivityReportByDevice (from, to, userData, traccarInstance
|
|
|
101
102
|
const sliced = automaticReports.sliceArray(allDevices, 10)
|
|
102
103
|
await executeServerSide(allData, sliced, from, to, userData, allDevices.length)
|
|
103
104
|
} else {
|
|
105
|
+
let summaryByDay = []
|
|
106
|
+
if (userData.allWeek && userData.groupByDay) {
|
|
107
|
+
const dates = getDates(from, to, userData.user.attributes.timezone || getUserPartner(userData.user).timezone)
|
|
108
|
+
summaryByDay = await getSummaryByDay(dates, userData, traccarInstance, allDevices, true)
|
|
109
|
+
}
|
|
110
|
+
|
|
104
111
|
let deviceCount = 0
|
|
105
112
|
const sliced = automaticReports.sliceArray(allDevices, 20)
|
|
106
113
|
for (const devices of sliced) {
|
|
@@ -113,7 +120,7 @@ async function createActivityReportByDevice (from, to, userData, traccarInstance
|
|
|
113
120
|
|
|
114
121
|
// Process report data
|
|
115
122
|
if (summary.length || trips.length) {
|
|
116
|
-
allData.devices = allData.devices.concat(await processDevices(from, to, devices, { summary, trips, route }, userData, traccarInstance))
|
|
123
|
+
allData.devices = allData.devices.concat(await processDevices(from, to, devices, { summaryByDay, summary, trips, route }, userData, traccarInstance))
|
|
117
124
|
}
|
|
118
125
|
deviceCount += devices.length
|
|
119
126
|
}
|
|
@@ -201,9 +208,12 @@ async function processDevices (from, to, devices, data, userData, traccarInstanc
|
|
|
201
208
|
})
|
|
202
209
|
}
|
|
203
210
|
} else {
|
|
211
|
+
const summaryByDay = data.summaryByDay.find(a => a.date.getTime() === date.getTime())
|
|
212
|
+
const summaryByDevice = summaryByDay.summary.find(a => a.deviceId === d.id)
|
|
213
|
+
|
|
204
214
|
const summaryCurrentDay = { date, deviceId: d.id }
|
|
205
215
|
summaryCurrentDay.engineHours = tripsByDay.reduce((a, b) => a + b.duration, 0)
|
|
206
|
-
summaryCurrentDay.distance = distance
|
|
216
|
+
summaryCurrentDay.distance = summaryByDevice.distance
|
|
207
217
|
summaryCurrentDay.averageSpeed = distance > 0 ? ((tripsByDay.reduce((a, b) => a + (b.averageSpeed * b.distance), 0)) / distance) : 0
|
|
208
218
|
summaryCurrentDay.maxSpeed = tripsByDay.reduce((a, b) => { return a > b.maxSpeed ? a : b.maxSpeed }, 0)
|
|
209
219
|
summaryCurrentDay.convertedSpentFuel = calculateConsumption(d, { route: routeByDay })
|
|
@@ -211,8 +221,8 @@ async function processDevices (from, to, devices, data, userData, traccarInstanc
|
|
|
211
221
|
summaryCurrentDay.startAddress = tripsByDay.length && tripsByDay[0].startAddress
|
|
212
222
|
summaryCurrentDay.endTime = tripsByDay.length && tripsByDay[tripsByDay.length - 1].endTime
|
|
213
223
|
summaryCurrentDay.endAddress = tripsByDay.length && tripsByDay[tripsByDay.length - 1].endAddress
|
|
214
|
-
summaryCurrentDay.startOdometer =
|
|
215
|
-
summaryCurrentDay.endOdometer =
|
|
224
|
+
summaryCurrentDay.startOdometer = summaryByDevice.startOdometer
|
|
225
|
+
summaryCurrentDay.endOdometer = summaryByDevice.endOdometer
|
|
216
226
|
summaryCurrentDay.startTimeIsOut = tripsByDay.some(t => t.startTimeIsOut)
|
|
217
227
|
summaryCurrentDay.endTimeIsOut = tripsByDay.some(t => t.endTimeIsOut)
|
|
218
228
|
summary.push(summaryCurrentDay)
|
package/src/util/traccar.js
CHANGED
|
@@ -129,7 +129,7 @@ async function getAllInOne (
|
|
|
129
129
|
}
|
|
130
130
|
}
|
|
131
131
|
|
|
132
|
-
async function getSummaryByDay (dates, userData, traccarInstance, allDevices) {
|
|
132
|
+
async function getSummaryByDay (dates, userData, traccarInstance, allDevices, ignorePercentage = false) {
|
|
133
133
|
const days = []
|
|
134
134
|
let counter = 0
|
|
135
135
|
for (const date of dates) {
|
|
@@ -143,7 +143,9 @@ async function getSummaryByDay (dates, userData, traccarInstance, allDevices) {
|
|
|
143
143
|
} = await getAllInOne(traccarInstance, startDate, endDate, allDevices, false, false, false, true, 0, allDevices.length, allDevices.length, allDevices.length, undefined, true)
|
|
144
144
|
|
|
145
145
|
counter = counter + 1
|
|
146
|
-
|
|
146
|
+
if (!ignorePercentage) {
|
|
147
|
+
console.log(`PROGRESS_PERC:${counter / dates.length * 100}`)
|
|
148
|
+
}
|
|
147
149
|
days.push({
|
|
148
150
|
date,
|
|
149
151
|
summary
|