fleetmap-reports 1.0.735 → 1.0.737
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
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const automaticReports = require('../automaticReports')
|
|
2
2
|
const traccarHelper = require('../util/traccar')
|
|
3
3
|
const { getUncompletedTrip } = require('../util/trips')
|
|
4
|
+
const { getEndTripMessage, getCanDriverStyleMessage, parseEndTripMessage, parseCanDriverStyleMessage } = require('../util/xpert')
|
|
4
5
|
|
|
5
6
|
async function createPerformanceReport (from, to, userData, traccar) {
|
|
6
7
|
const reportData = []
|
|
@@ -10,35 +11,41 @@ async function createPerformanceReport (from, to, userData, traccar) {
|
|
|
10
11
|
|
|
11
12
|
let deviceCount = 0
|
|
12
13
|
for (const slice of sliced) {
|
|
13
|
-
const allInOne = await traccarHelper.getAllInOne(traccar, from, to, slice, true, true,
|
|
14
|
+
const allInOne = await traccarHelper.getAllInOne(traccar, from, to, slice, true, true, false, false, deviceCount, devices.length)
|
|
14
15
|
|
|
15
16
|
slice.forEach(d => {
|
|
16
17
|
const deviceRoute = allInOne.route.filter(t => t.deviceId === d.id)
|
|
17
18
|
const deviceTrips = allInOne.trips.filter(t => t.deviceId === d.id)
|
|
18
|
-
const deviceStops = allInOne.stops.filter(t => t.deviceId === d.id)
|
|
19
19
|
|
|
20
20
|
const uncompletedTrip = getUncompletedTrip(d, deviceRoute, deviceTrips)
|
|
21
21
|
if (uncompletedTrip) {
|
|
22
22
|
deviceTrips.push(uncompletedTrip)
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
deviceTrips.forEach(t => {
|
|
26
|
+
const endTripData = getEndTripMessage(t, deviceRoute)
|
|
27
|
+
const canDriverStyle = getCanDriverStyleMessage(t, deviceRoute)
|
|
28
|
+
|
|
29
|
+
t.endTripData = endTripData && parseEndTripMessage(endTripData.xpertString || endTripData)
|
|
30
|
+
t.canDriverStyle = canDriverStyle && parseCanDriverStyleMessage(canDriverStyle.xpertString || canDriverStyle)
|
|
31
|
+
})
|
|
32
|
+
|
|
25
33
|
const deviceData = {
|
|
26
34
|
device: d.name,
|
|
27
|
-
drivingTime: deviceTrips.reduce((a, b) => a + b.
|
|
28
|
-
idleTime: deviceTrips.reduce((a, b) => a + b.
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
hardAcceleration: 5
|
|
35
|
+
drivingTime: deviceTrips.reduce((a, b) => a + (b.endTripData ? b.endTripData.totalTimeDriving : 0), 0),
|
|
36
|
+
idleTime: deviceTrips.reduce((a, b) => a + (b.endTripData ? b.endTripData.totalTimeInIdle : 0), 0),
|
|
37
|
+
drivingConsumption: deviceTrips.reduce((a, b) => a + (b.endTripData ? b.endTripData.totalFuelConsumptionDriving : 0), 0),
|
|
38
|
+
idleConsumption: deviceTrips.reduce((a, b) => a + (b.endTripData ? b.endTripData.totalFuelConsumptionInIdle : 0), 0),
|
|
39
|
+
drivingDistance: deviceTrips.reduce((a, b) => a + (b.endTripData ? b.endTripData.totalDistanceTravelled : 0), 0),
|
|
40
|
+
cruiseControlTime: deviceTrips.reduce((a, b) => a + (b.endTripData ? b.endTripData.totalTimeWithCruiseControl : 0), 0),
|
|
41
|
+
cruiseControlConsumption: deviceTrips.reduce((a, b) => a + (b.endTripData ? b.endTripData.totalFuelConsumptionWithCruiseControl : 0), 0),
|
|
42
|
+
cruiseControlDistance: deviceTrips.reduce((a, b) => a + (b.endTripData ? b.endTripData.totalDistanceTravelledWithCruiseControl : 0), 0),
|
|
43
|
+
economicTime: deviceTrips.reduce((a, b) => a + (b.canDriverStyle ? b.canDriverStyle.totalTimeInEcoRange : 0), 0),
|
|
44
|
+
economicConsumption: deviceTrips.reduce((a, b) => a + (b.canDriverStyle ? b.canDriverStyle.totalFuelConsumptionInEcoRange : 0), 0),
|
|
45
|
+
economicDistance: deviceTrips.reduce((a, b) => a + (b.canDriverStyle ? b.canDriverStyle.totalDistanceInEcoRange : 0), 0),
|
|
46
|
+
highEngineRPM: deviceTrips.reduce((a, b) => a + (b.canDriverStyle ? b.canDriverStyle.totalTimeWithHighRpmAndTorque : 0), 0),
|
|
47
|
+
hardBreaking: deviceTrips.reduce((a, b) => a + (b.canDriverStyle ? b.canDriverStyle.totalNumberOfHarshBrakes : 0), 0),
|
|
48
|
+
hardAcceleration: deviceTrips.reduce((a, b) => a + (b.canDriverStyle ? b.canDriverStyle.totalNumberOfHarshAccelerations : 0), 0)
|
|
42
49
|
}
|
|
43
50
|
reportData.push(deviceData)
|
|
44
51
|
})
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const { getReports } = require('./index')
|
|
2
|
+
const { createPerformanceReport } = require('../partnerReports/performance-report')
|
|
3
|
+
// eslint-disable-next-line no-undef
|
|
4
|
+
describe('performance', function () {
|
|
5
|
+
this.timeout(500000)
|
|
6
|
+
// eslint-disable-next-line no-undef
|
|
7
|
+
it('performance report', async () => {
|
|
8
|
+
const report = await getReports()
|
|
9
|
+
const userData = await report.getUserData()
|
|
10
|
+
userData.devices = userData.devices.filter(d => d.attributes.xpert)
|
|
11
|
+
const data = await createPerformanceReport(
|
|
12
|
+
new Date(Date.UTC(2023, 5, 10, 0, 0, 0, 0)),
|
|
13
|
+
new Date(Date.UTC(2023, 5, 20, 23, 59, 59, 0)),
|
|
14
|
+
userData,
|
|
15
|
+
report.traccar)
|
|
16
|
+
console.log(data)
|
|
17
|
+
})
|
|
18
|
+
})
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
function parseEndTripMessage (xpertMessage) {
|
|
2
|
+
const data = xpertMessage.split(',')
|
|
3
|
+
|
|
4
|
+
return {
|
|
5
|
+
totalDistanceTravelled: Number(data[2]),
|
|
6
|
+
totalDistanceTravelledWithCruiseControl: Number(data[3]),
|
|
7
|
+
totalFuelConsumption: Number(data[4]),
|
|
8
|
+
totalFuelConsumptionInPTO: Number(data[5]),
|
|
9
|
+
totalFuelConsumptionInIdle: Number(data[6]),
|
|
10
|
+
totalFuelConsumptionDriving: Number(data[7]),
|
|
11
|
+
totalFuelConsumptionWithCruiseControl: Number(data[8]),
|
|
12
|
+
totalTimeWithCruiseControl: Number(data[9]),
|
|
13
|
+
totalTimeInPTO: Number(data[10]),
|
|
14
|
+
totalTimeInIdle: Number(data[11]),
|
|
15
|
+
totalTimeDriving: Number(data[12]),
|
|
16
|
+
totalTimeWithIgnitionKeyOnly: Number(data[13]),
|
|
17
|
+
totalEngineHours: Number(data[14])
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function parseCanDriverStyleMessage (xpertMessage) {
|
|
22
|
+
const data = xpertMessage.split(',')
|
|
23
|
+
|
|
24
|
+
return {
|
|
25
|
+
totalFuelConsumptionInEcoRange: Number(data[2]),
|
|
26
|
+
totalTimeInEcoRange: Number(data[3]),
|
|
27
|
+
totalDistanceInEcoRange: Number(data[4]),
|
|
28
|
+
totalFuelConsumptionWithClutchPressed2: Number(data[5]),
|
|
29
|
+
totalTimeWithClutchPressed2: Number(data[6]),
|
|
30
|
+
totalDistanceWithClutchPressed2: Number(data[7]),
|
|
31
|
+
totalFuelConsumptionWithCruiseControlAndAccelerator2: Number(data[8]),
|
|
32
|
+
totalTimeWithCruiseControlAndAccelerator2: Number(data[9]),
|
|
33
|
+
totalDistanceWithCruiseControlAndAccelerator2: Number(data[10]),
|
|
34
|
+
totalNumberOfBrakes: Number(data[11]),
|
|
35
|
+
totalNumberOfHarshBrakes: Number(data[12]),
|
|
36
|
+
totalNumberOfHarshAccelerations: Number(data[13]),
|
|
37
|
+
totalTimeWithHighRpmAndTorque: Number(data[14]),
|
|
38
|
+
totalTimeWithHighTorque: Number(data[15]),
|
|
39
|
+
totalTimeWithHighEngineTemperature: Number(data[16]),
|
|
40
|
+
totalFuelConsumptionWithHighRpmAndTorque: Number(data[17]),
|
|
41
|
+
totalDistanceWithHighRpmAndTorque: Number(data[18])
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function getEndTripMessage (trip, route) {
|
|
46
|
+
const p = route.find(p => new Date(p.fixTime).getTime() > new Date(trip.endTime).getTime() &&
|
|
47
|
+
p.attributes.xpert &&
|
|
48
|
+
(Array.isArray(p.attributes.xpert) ? p.attributes.xpert.find(x => x.type === '3') : p.attributes.xpert.split(';').find(m => m.startsWith('3'))))
|
|
49
|
+
|
|
50
|
+
return p && (Array.isArray(p.attributes.xpert) ? p.attributes.xpert.find(x => x.type === '3') : p.attributes.xpert.split(';').find(m => m.startsWith('3')))
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function getCanDriverStyleMessage (trip, route) {
|
|
54
|
+
const p = route.find(p => new Date(p.fixTime).getTime() > new Date(trip.endTime).getTime() &&
|
|
55
|
+
p.attributes.xpert &&
|
|
56
|
+
(Array.isArray(p.attributes.xpert) ? p.attributes.xpert.find(x => x.type === '4') : p.attributes.xpert.split(';').find(m => m.startsWith('4'))))
|
|
57
|
+
|
|
58
|
+
return p && (Array.isArray(p.attributes.xpert) ? p.attributes.xpert.find(x => x.type === '4') : p.attributes.xpert.split(';').find(m => m.startsWith('4')))
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
exports.parseEndTripMessage = parseEndTripMessage
|
|
62
|
+
exports.getEndTripMessage = getEndTripMessage
|
|
63
|
+
exports.parseCanDriverStyleMessage = parseCanDriverStyleMessage
|
|
64
|
+
exports.getCanDriverStyleMessage = getCanDriverStyleMessage
|