fleetmap-reports 1.0.426 → 1.0.427
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/index.test.js +15 -0
- package/src/trip-report.js +33 -10
package/package.json
CHANGED
package/src/index.test.js
CHANGED
|
@@ -52,6 +52,21 @@ describe('Test_Reports', function () {
|
|
|
52
52
|
assert.equal(device.trips[1].endPOIName, undefined)
|
|
53
53
|
assert.equal(device.totalDistance, 339204.53999999166) // Total Kms
|
|
54
54
|
}, 20000)
|
|
55
|
+
// eslint-disable-next-line no-undef
|
|
56
|
+
it('Trip by driver', async () => {
|
|
57
|
+
const report = await getReports()
|
|
58
|
+
const userData = await report.getUserData()
|
|
59
|
+
userData.byDriver = true
|
|
60
|
+
const data = await report.tripReport(new Date(2022, 1, 1, 0, 0, 0, 0),
|
|
61
|
+
new Date(2022, 1, 10, 23, 59, 59, 0),
|
|
62
|
+
userData)
|
|
63
|
+
assert.equal(data.length, 1)
|
|
64
|
+
console.log(data[0].drivers)
|
|
65
|
+
const driver = data[0].drivers.find(d => d.driver.id === 14020)
|
|
66
|
+
assert.equal(driver.trips.length, 9) // Total Trips
|
|
67
|
+
assert.equal(driver.totalDuration, 6274000)
|
|
68
|
+
assert.equal(driver.maxSpeed, 70.1944)
|
|
69
|
+
}, 20000)
|
|
55
70
|
it('Trip without addresses', async () => {
|
|
56
71
|
const report = await getReports()
|
|
57
72
|
const userData = await report.getUserData()
|
package/src/trip-report.js
CHANGED
|
@@ -114,11 +114,40 @@ async function createTripReportByDriver (from, to, userData, traccar) {
|
|
|
114
114
|
return { drivers: [] }
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
-
const
|
|
118
|
-
|
|
119
|
-
|
|
117
|
+
const allData = {
|
|
118
|
+
drivers: []
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const sliced = automaticReports.sliceArray(devices, 5)
|
|
122
|
+
|
|
123
|
+
let deviceCount = 0
|
|
124
|
+
for (const slice of sliced) {
|
|
125
|
+
const allInOne = await traccarHelper.getAllInOne(traccar, from, to, slice, true, true, false, false, deviceCount, devices.length)
|
|
126
|
+
const tripsData = allInOne.trips
|
|
127
|
+
const routeData = allInOne.route
|
|
120
128
|
|
|
121
|
-
|
|
129
|
+
const results = processDrivers(from, to, userData, { trips: tripsData, route: routeData })
|
|
130
|
+
|
|
131
|
+
results.forEach(result => {
|
|
132
|
+
const driver = allData.drivers.find(d => d.driver.id === result.driver.id)
|
|
133
|
+
if (driver) {
|
|
134
|
+
driver.trips.push(...result.trips)
|
|
135
|
+
} else {
|
|
136
|
+
allData.drivers.push(result)
|
|
137
|
+
}
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
deviceCount = deviceCount + slice.length
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
allData.drivers.forEach(d => {
|
|
144
|
+
d.totalDuration = d.trips.reduce((a, b) => a + b.duration, 0)
|
|
145
|
+
d.totalDistance = d.trips.reduce((a, b) => a + b.distance, 0)
|
|
146
|
+
d.maxSpeed = d.trips.reduce((a, b) => { return a > b.maxSpeed ? a : b.maxSpeed }, 0)
|
|
147
|
+
d.trips = d.trips.sort((a, b) => new Date(a.startTime).getTime() - new Date(b.startTime).getTime())
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
return allData
|
|
122
151
|
}
|
|
123
152
|
|
|
124
153
|
function processDevices (from, to, devices, data, userData, traccar) {
|
|
@@ -195,8 +224,6 @@ function processDrivers (from, to, userData, data) {
|
|
|
195
224
|
const trips = data.trips.filter(t => t.driverUniqueId === d.uniqueId &&
|
|
196
225
|
(userData.allWeek || !userData.weekDays || isInsideTimetable(t, userData) || isPartialInsideTimetable(t, userData, route)))
|
|
197
226
|
|
|
198
|
-
trips.sort((a, b) => new Date(a.startTime).getTime() - new Date(b.startTime).getTime())
|
|
199
|
-
|
|
200
227
|
const idleEvents = getIdleEvents(data.route, d)
|
|
201
228
|
|
|
202
229
|
trips.forEach(function (trip, i) {
|
|
@@ -211,15 +238,11 @@ function processDrivers (from, to, userData, data) {
|
|
|
211
238
|
driver: d,
|
|
212
239
|
from,
|
|
213
240
|
to,
|
|
214
|
-
totalDuration: trips.reduce((a, b) => a + b.duration, 0),
|
|
215
|
-
totalDistance: trips.reduce((a, b) => a + b.distance, 0),
|
|
216
|
-
maxSpeed: trips.reduce((a, b) => { return a > b.maxSpeed ? a : b.maxSpeed }, 0),
|
|
217
241
|
trips
|
|
218
242
|
}
|
|
219
243
|
driversResult.push(driverData)
|
|
220
244
|
}
|
|
221
245
|
})
|
|
222
|
-
console.log(driversResult)
|
|
223
246
|
|
|
224
247
|
return driversResult
|
|
225
248
|
}
|