fleetmap-reports 1.0.621 → 1.0.622
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
CHANGED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const traccar = require('../util/traccar')
|
|
2
|
+
|
|
3
|
+
async function createActivityReport (from, to, userData, traccarInstance) {
|
|
4
|
+
const allInOne = await traccar.getAllInOne(traccarInstance, from, to, userData.devices, false, true, true, false)
|
|
5
|
+
|
|
6
|
+
const reportData = []
|
|
7
|
+
userData.devices.forEach(d => {
|
|
8
|
+
const trips = allInOne.trips.filter(t => t.deviceId === d.id)
|
|
9
|
+
const stops = allInOne.stops.filter(s => s.deviceId === d.id)
|
|
10
|
+
const group = userData.groups.find(g => g.id === d.groupId)
|
|
11
|
+
|
|
12
|
+
const totalDistance = trips.reduce((a, b) => a + b.distance, 0)
|
|
13
|
+
const idleTime = stops.reduce((a, b) => a + b.engineHours, 0)
|
|
14
|
+
|
|
15
|
+
const deviceData = {
|
|
16
|
+
device: d.name,
|
|
17
|
+
group: group ? group.name : '',
|
|
18
|
+
startAddress: trips.length ? trips[0].startAddress : '',
|
|
19
|
+
startTime: trips.length ? trips[0].startTime : '',
|
|
20
|
+
endAddress: trips.length ? trips[trips.length - 1].endAddress : '',
|
|
21
|
+
endTime: trips.length ? trips[trips.length - 1].endTime : '',
|
|
22
|
+
drivingTime: trips.reduce((a, b) => a + b.duration, 0),
|
|
23
|
+
stopTime: stops.reduce((a, b) => a + b.duration, 0) - idleTime,
|
|
24
|
+
idleTime,
|
|
25
|
+
distance: totalDistance,
|
|
26
|
+
averageSpeed: totalDistance > 0 ? ((trips.reduce((a, b) => a + (b.averageSpeed * b.distance), 0)) / totalDistance) : 0,
|
|
27
|
+
maxSpeed: trips.reduce((a, b) => {
|
|
28
|
+
return a > b.maxSpeed ? a : b.maxSpeed
|
|
29
|
+
}, 0)
|
|
30
|
+
}
|
|
31
|
+
reportData.push(deviceData)
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
return reportData
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
exports.createActivityReport = createActivityReport
|