fleetmap-reports 1.0.734 → 1.0.735
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/partnerReports/performance-report.js +46 -21
- package/src/trip-report.js +7 -6
- package/src/util/trips.js +10 -0
package/package.json
CHANGED
|
@@ -1,25 +1,50 @@
|
|
|
1
|
-
|
|
1
|
+
const automaticReports = require('../automaticReports')
|
|
2
|
+
const traccarHelper = require('../util/traccar')
|
|
3
|
+
const { getUncompletedTrip } = require('../util/trips')
|
|
4
|
+
|
|
5
|
+
async function createPerformanceReport (from, to, userData, traccar) {
|
|
2
6
|
const reportData = []
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
7
|
+
|
|
8
|
+
const devices = userData.devices
|
|
9
|
+
const sliced = automaticReports.sliceArray(devices, 5)
|
|
10
|
+
|
|
11
|
+
let deviceCount = 0
|
|
12
|
+
for (const slice of sliced) {
|
|
13
|
+
const allInOne = await traccarHelper.getAllInOne(traccar, from, to, slice, true, true, true, false, deviceCount, devices.length)
|
|
14
|
+
|
|
15
|
+
slice.forEach(d => {
|
|
16
|
+
const deviceRoute = allInOne.route.filter(t => t.deviceId === d.id)
|
|
17
|
+
const deviceTrips = allInOne.trips.filter(t => t.deviceId === d.id)
|
|
18
|
+
const deviceStops = allInOne.stops.filter(t => t.deviceId === d.id)
|
|
19
|
+
|
|
20
|
+
const uncompletedTrip = getUncompletedTrip(d, deviceRoute, deviceTrips)
|
|
21
|
+
if (uncompletedTrip) {
|
|
22
|
+
deviceTrips.push(uncompletedTrip)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const deviceData = {
|
|
26
|
+
device: d.name,
|
|
27
|
+
drivingTime: deviceTrips.reduce((a, b) => a + b.duration, 0),
|
|
28
|
+
idleTime: deviceTrips.reduce((a, b) => a + b.idleTime, 0) +
|
|
29
|
+
deviceStops.reduce((a, b) => a + b.engineHours, 0),
|
|
30
|
+
drivingConsumption: 20,
|
|
31
|
+
idleConsumption: 10,
|
|
32
|
+
drivingDistance: deviceTrips.reduce((a, b) => a + b.distance, 0),
|
|
33
|
+
economicTime: 265000,
|
|
34
|
+
economicConsumption: 5,
|
|
35
|
+
economicDistance: 99000,
|
|
36
|
+
cruiseControlTime: 0,
|
|
37
|
+
cruiseControlConsumption: 0,
|
|
38
|
+
cruiseControlDistance: 0,
|
|
39
|
+
highEngineRPM: 66000,
|
|
40
|
+
hardBreaking: 10,
|
|
41
|
+
hardAcceleration: 5
|
|
42
|
+
}
|
|
43
|
+
reportData.push(deviceData)
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
deviceCount = deviceCount + slice.length
|
|
47
|
+
}
|
|
23
48
|
return reportData
|
|
24
49
|
}
|
|
25
50
|
|
package/src/trip-report.js
CHANGED
|
@@ -10,7 +10,10 @@ const { headerFromUser, addTable } = require('./util/pdfDocument')
|
|
|
10
10
|
const { getStyle } = require('./reportStyle')
|
|
11
11
|
const traccarHelper = require('./util/traccar')
|
|
12
12
|
const trips = require('./util/trips')
|
|
13
|
-
const {
|
|
13
|
+
const {
|
|
14
|
+
isInsideTimetable, isPartialInsideTimetable, getTripIdleTime, calculateStopDuration,
|
|
15
|
+
getUncompletedTrip
|
|
16
|
+
} = require('./util/trips')
|
|
14
17
|
const { devicesToProcess, deviceName } = require('./util/device')
|
|
15
18
|
const { getIdleEvents } = require('./util/route')
|
|
16
19
|
const { reportByDriver, getDriverName, getDriverData } = require('./util/driver')
|
|
@@ -152,11 +155,9 @@ function processDevices (from, to, devices, data, userData, traccar) {
|
|
|
152
155
|
const deviceRoute = data.route.filter(t => t.deviceId === d.id)
|
|
153
156
|
const deviceTrips = data.trips.filter(t => t.deviceId === d.id)
|
|
154
157
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
deviceTrips.push(calculateTrip(d, uncompletedTripRoute))
|
|
159
|
-
}
|
|
158
|
+
const uncompletedTrip = getUncompletedTrip(d, deviceRoute, deviceTrips)
|
|
159
|
+
if (uncompletedTrip) {
|
|
160
|
+
deviceTrips.push(uncompletedTrip)
|
|
160
161
|
}
|
|
161
162
|
|
|
162
163
|
const trips = deviceTrips.filter(t => userData.allWeek || !userData.weekDays || isInsideTimetable(t, userData) || isPartialInsideTimetable(t, userData, deviceRoute))
|
package/src/util/trips.js
CHANGED
|
@@ -104,6 +104,15 @@ function updateTrip (t, route) {
|
|
|
104
104
|
t.averageSpeed = distance > 0 ? ((route.reduce((a, b) => a + b.speed, 0)) / route.length) : 0
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
+
function getUncompletedTrip (device, deviceRoute, deviceTrips) {
|
|
108
|
+
if (deviceRoute.length && deviceTrips.length && deviceRoute[deviceRoute.length - 1].attributes.ignition) {
|
|
109
|
+
const uncompletedTripRoute = deviceRoute.filter(p => p.attributes.ignition && new Date(p.fixTime).getTime() > new Date(deviceTrips[deviceTrips.length - 1].endTime).getTime())
|
|
110
|
+
if (uncompletedTripRoute.length) {
|
|
111
|
+
return calculateTrip(device, uncompletedTripRoute)
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
107
116
|
function calculateTrip (device, route) {
|
|
108
117
|
const startPos = route[0]
|
|
109
118
|
const endPos = route[route.length - 1]
|
|
@@ -153,3 +162,4 @@ exports.isPartialInsideTimetable = isPartialInsideTimetable
|
|
|
153
162
|
exports.calculateTrip = calculateTrip
|
|
154
163
|
exports.getTripIdleTime = getTripIdleTime
|
|
155
164
|
exports.calculateStopDuration = calculateStopDuration
|
|
165
|
+
exports.getUncompletedTrip = getUncompletedTrip
|