fleetmap-reports 1.0.764 → 1.0.765

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,6 @@
1
1
  {
2
2
  "name": "fleetmap-reports",
3
- "version": "1.0.764",
3
+ "version": "1.0.765",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -7,47 +7,108 @@ async function createPerformanceReport (from, to, userData, traccar) {
7
7
  const reportData = []
8
8
 
9
9
  const devices = userData.devices
10
- const sliced = automaticReports.sliceArray(devices, 5)
11
-
12
- let deviceCount = 0
13
- for (const slice of sliced) {
14
- const allInOne = await traccarHelper.getAllInOne(traccar, from, to, slice, true, true, false, false, deviceCount, devices.length)
15
-
16
- slice.forEach(d => {
17
- const deviceRoute = allInOne.route.filter(t => t.deviceId === d.id)
18
- const deviceTrips = allInOne.trips.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 endTripData = getEndTripMessages(deviceRoute).map(m => parseEndTripMessage(m.xpertString || m)).sort((a, b) => a.date.localeCompare(b.date))
26
- const canDriverStyle = getCanDriverStyleMessages(deviceRoute).map(m => parseCanDriverStyleMessage(m.xpertString || m)).sort((a, b) => a.date.localeCompare(b.date))
27
-
28
- const deviceData = {
29
- device: d.name,
30
- drivingTime: endTripData.length > 1 ? endTripData[endTripData.length - 1].totalTimeDriving - endTripData[0].totalTimeDriving : 0,
31
- idleTime: endTripData.length > 1 ? endTripData[endTripData.length - 1].totalTimeInIdle - endTripData[0].totalTimeInIdle : 0,
32
- drivingConsumption: endTripData.length > 1 ? endTripData[endTripData.length - 1].totalFuelConsumptionDriving - endTripData[0].totalFuelConsumptionDriving : 0,
33
- idleConsumption: endTripData.length > 1 ? endTripData[endTripData.length - 1].totalFuelConsumptionInIdle - endTripData[0].totalFuelConsumptionInIdle : 0,
34
- drivingDistance: endTripData.length > 1 ? endTripData[endTripData.length - 1].totalDistanceTravelled - endTripData[0].totalDistanceTravelled : 0,
35
- cruiseControlTime: endTripData.length > 1 ? endTripData[endTripData.length - 1].totalTimeWithCruiseControl - endTripData[0].totalTimeWithCruiseControl : 0,
36
- cruiseControlConsumption: endTripData.length > 1 ? endTripData[endTripData.length - 1].totalFuelConsumptionWithCruiseControl - endTripData[0].totalFuelConsumptionWithCruiseControl : 0,
37
- cruiseControlDistance: endTripData.length > 1 ? endTripData[endTripData.length - 1].totalDistanceTravelledWithCruiseControl - endTripData[0].totalDistanceTravelledWithCruiseControl : 0,
38
- economicTime: canDriverStyle.length > 1 ? canDriverStyle[canDriverStyle.length - 1].totalTimeInEcoRange - canDriverStyle[0].totalTimeInEcoRange : 0,
39
- economicConsumption: canDriverStyle.length > 1 ? canDriverStyle[canDriverStyle.length - 1].totalFuelConsumptionInEcoRange - canDriverStyle[0].totalFuelConsumptionInEcoRange : 0,
40
- economicDistance: canDriverStyle.length > 1 ? canDriverStyle[canDriverStyle.length - 1].totalDistanceInEcoRange - canDriverStyle[0].totalDistanceInEcoRange : 0,
41
- highEngineRPM: canDriverStyle.length > 1 ? canDriverStyle[canDriverStyle.length - 1].totalTimeWithHighRpmAndTorque - canDriverStyle[0].totalTimeWithHighRpmAndTorque : 0,
42
- hardBreaking: canDriverStyle.length > 1 ? canDriverStyle[canDriverStyle.length - 1].totalNumberOfHarshBrakes - canDriverStyle[0].totalNumberOfHarshBrakes : 0,
43
- hardAcceleration: canDriverStyle.length > 1 ? canDriverStyle[canDriverStyle.length - 1].totalNumberOfHarshAccelerations - canDriverStyle[0].totalNumberOfHarshAccelerations : 0
44
- }
45
- reportData.push(deviceData)
46
- })
47
-
48
- deviceCount = deviceCount + slice.length
10
+
11
+ if (devices.length !== 1) {
12
+ const sliced = automaticReports.sliceArray(devices, 5)
13
+ let deviceCount = 0
14
+ for (const slice of sliced) {
15
+ const allInOne = await traccarHelper.getAllInOne(traccar, from, to, slice, true, true, false, false, deviceCount, devices.length)
16
+
17
+ slice.forEach(d => {
18
+ const { endTripData, canDriverStyle } = getDeviceXpertData(allInOne, d)
19
+
20
+ const deviceData = {
21
+ device: d.name,
22
+ drivingTime: endTripData.length > 1 ? endTripData[endTripData.length - 1].totalTimeDriving - endTripData[0].totalTimeDriving : 0,
23
+ idleTime: endTripData.length > 1 ? endTripData[endTripData.length - 1].totalTimeInIdle - endTripData[0].totalTimeInIdle : 0,
24
+ drivingConsumption: endTripData.length > 1 ? endTripData[endTripData.length - 1].totalFuelConsumptionDriving - endTripData[0].totalFuelConsumptionDriving : 0,
25
+ idleConsumption: endTripData.length > 1 ? endTripData[endTripData.length - 1].totalFuelConsumptionInIdle - endTripData[0].totalFuelConsumptionInIdle : 0,
26
+ drivingDistance: endTripData.length > 1 ? endTripData[endTripData.length - 1].totalDistanceTravelled - endTripData[0].totalDistanceTravelled : 0,
27
+ cruiseControlTime: endTripData.length > 1 ? endTripData[endTripData.length - 1].totalTimeWithCruiseControl - endTripData[0].totalTimeWithCruiseControl : 0,
28
+ cruiseControlConsumption: endTripData.length > 1 ? endTripData[endTripData.length - 1].totalFuelConsumptionWithCruiseControl - endTripData[0].totalFuelConsumptionWithCruiseControl : 0,
29
+ cruiseControlDistance: endTripData.length > 1 ? endTripData[endTripData.length - 1].totalDistanceTravelledWithCruiseControl - endTripData[0].totalDistanceTravelledWithCruiseControl : 0,
30
+ economicTime: canDriverStyle.length > 1 ? canDriverStyle[canDriverStyle.length - 1].totalTimeInEcoRange - canDriverStyle[0].totalTimeInEcoRange : 0,
31
+ economicConsumption: canDriverStyle.length > 1 ? canDriverStyle[canDriverStyle.length - 1].totalFuelConsumptionInEcoRange - canDriverStyle[0].totalFuelConsumptionInEcoRange : 0,
32
+ economicDistance: canDriverStyle.length > 1 ? canDriverStyle[canDriverStyle.length - 1].totalDistanceInEcoRange - canDriverStyle[0].totalDistanceInEcoRange : 0,
33
+ highEngineRPM: canDriverStyle.length > 1 ? canDriverStyle[canDriverStyle.length - 1].totalTimeWithHighRpmAndTorque - canDriverStyle[0].totalTimeWithHighRpmAndTorque : 0,
34
+ hardBreaking: canDriverStyle.length > 1 ? canDriverStyle[canDriverStyle.length - 1].totalNumberOfHarshBrakes - canDriverStyle[0].totalNumberOfHarshBrakes : 0,
35
+ hardAcceleration: canDriverStyle.length > 1 ? canDriverStyle[canDriverStyle.length - 1].totalNumberOfHarshAccelerations - canDriverStyle[0].totalNumberOfHarshAccelerations : 0
36
+ }
37
+ reportData.push(deviceData)
38
+ })
39
+
40
+ deviceCount = deviceCount + slice.length
41
+ }
42
+ } else {
43
+ const allInOne = await traccarHelper.getAllInOne(traccar, from, to, userData.devices, true, true, false, false)
44
+
45
+ const device = userData.devices[0]
46
+ const { endTripData, canDriverStyle } = getDeviceXpertData(allInOne, device)
47
+
48
+ const drivingTime = endTripData.length > 1 ? endTripData[endTripData.length - 1].totalTimeDriving - endTripData[0].totalTimeDriving : 0
49
+ const idleTime = endTripData.length > 1 ? endTripData[endTripData.length - 1].totalTimeInIdle - endTripData[0].totalTimeInIdle : 0
50
+ const cruiseControlTime = endTripData.length > 1 ? endTripData[endTripData.length - 1].totalTimeWithCruiseControl - endTripData[0].totalTimeWithCruiseControl : 0
51
+ const economicTime = canDriverStyle.length > 1 ? canDriverStyle[canDriverStyle.length - 1].totalTimeInEcoRange - canDriverStyle[0].totalTimeInEcoRange : 0
52
+ const highEngineRPM = canDriverStyle.length > 1 ? canDriverStyle[canDriverStyle.length - 1].totalTimeWithHighRpmAndTorque - canDriverStyle[0].totalTimeWithHighRpmAndTorque : 0
53
+ const hardBreaking = canDriverStyle.length > 1 ? canDriverStyle[canDriverStyle.length - 1].totalNumberOfHarshBrakes - canDriverStyle[0].totalNumberOfHarshBrakes : 0
54
+ const hardAcceleration = canDriverStyle.length > 1 ? canDriverStyle[canDriverStyle.length - 1].totalNumberOfHarshAccelerations - canDriverStyle[0].totalNumberOfHarshAccelerations : 0
55
+
56
+ const drivingConsumption = endTripData.length > 1 ? endTripData[endTripData.length - 1].totalFuelConsumptionDriving - endTripData[0].totalFuelConsumptionDriving : 0
57
+ const idleConsumption = endTripData.length > 1 ? endTripData[endTripData.length - 1].totalFuelConsumptionInIdle - endTripData[0].totalFuelConsumptionInIdle : 0
58
+ const cruiseControlConsumption = endTripData.length > 1 ? endTripData[endTripData.length - 1].totalFuelConsumptionWithCruiseControl - endTripData[0].totalFuelConsumptionWithCruiseControl : 0
59
+ const economicConsumption = canDriverStyle.length > 1 ? canDriverStyle[canDriverStyle.length - 1].totalFuelConsumptionInEcoRange - canDriverStyle[0].totalFuelConsumptionInEcoRange : 0
60
+
61
+ const drivingDistance = endTripData.length > 1 ? endTripData[endTripData.length - 1].totalDistanceTravelled - endTripData[0].totalDistanceTravelled : 0
62
+ const cruiseControlDistance = endTripData.length > 1 ? endTripData[endTripData.length - 1].totalDistanceTravelledWithCruiseControl - endTripData[0].totalDistanceTravelledWithCruiseControl : 0
63
+ const economicDistance = canDriverStyle.length > 1 ? canDriverStyle[canDriverStyle.length - 1].totalDistanceInEcoRange - canDriverStyle[0].totalDistanceInEcoRange : 0
64
+
65
+ const totalTime = drivingTime + idleTime
66
+ const totalConsumption = drivingConsumption + idleConsumption
67
+
68
+ const totalData = getRowData(device, 'Totale', totalTime, totalConsumption, drivingDistance, drivingDistance > 0 ? totalConsumption * 100 / drivingDistance : 0)
69
+ const drivingData = getRowData(device, 'Conduite', drivingTime, drivingConsumption, drivingDistance, drivingDistance > 0 ? drivingConsumption * 100 / drivingDistance : 0)
70
+ const idleData = getRowData(device, 'Ralenti', idleTime, idleConsumption, '', totalConsumption > 0 ? idleConsumption * 100 / totalConsumption : 0)
71
+ const economicData = getRowData(device, 'Économique', economicTime, economicConsumption, economicDistance, totalTime > 0 ? economicTime * 100 / totalTime : 0)
72
+ const cruiseControlData = getRowData(device, 'Économique', cruiseControlTime, cruiseControlConsumption, cruiseControlDistance, totalTime > 0 ? cruiseControlTime * 100 / totalTime : 0)
73
+ const highEngineRPMData = getRowData(device, 'Tour moteur élevé', highEngineRPM, '', '', totalTime > 0 ? highEngineRPM * 100 / totalTime : 0)
74
+ const hardBreakingData = getRowData(device, 'Freinage brusque', hardBreaking, '', '', drivingDistance > 0 ? hardBreaking * 100 / drivingDistance : 0)
75
+ const hardAccelerationData = getRowData(device, 'Accéleration brusque', hardAcceleration, '', '', drivingDistance > 0 ? hardAcceleration * 100 / drivingDistance : 0)
76
+
77
+ reportData.push(totalData)
78
+ reportData.push(drivingData)
79
+ reportData.push(idleData)
80
+ reportData.push(economicData)
81
+ reportData.push(cruiseControlData)
82
+ reportData.push(highEngineRPMData)
83
+ reportData.push(hardBreakingData)
84
+ reportData.push(hardAccelerationData)
49
85
  }
50
86
  return reportData
51
87
  }
52
88
 
89
+ function getDeviceXpertData (allInOne, d) {
90
+ const deviceRoute = allInOne.route.filter(t => t.deviceId === d.id)
91
+ const deviceTrips = allInOne.trips.filter(t => t.deviceId === d.id)
92
+
93
+ const uncompletedTrip = getUncompletedTrip(d, deviceRoute, deviceTrips)
94
+ if (uncompletedTrip) {
95
+ deviceTrips.push(uncompletedTrip)
96
+ }
97
+
98
+ const endTripData = getEndTripMessages(deviceRoute).map(m => parseEndTripMessage(m.xpertString || m)).sort((a, b) => a.date.localeCompare(b.date))
99
+ const canDriverStyle = getCanDriverStyleMessages(deviceRoute).map(m => parseCanDriverStyleMessage(m.xpertString || m)).sort((a, b) => a.date.localeCompare(b.date))
100
+ return { endTripData, canDriverStyle }
101
+ }
102
+
103
+ function getRowData (device, description, time, consumption, economicDistance, totalTime) {
104
+ return {
105
+ device: device.name,
106
+ description,
107
+ time,
108
+ consumption,
109
+ distance: economicDistance,
110
+ indicator: totalTime > 0 ? time * 100 / totalTime : 0
111
+ }
112
+ }
113
+
53
114
  exports.createPerformanceReport = createPerformanceReport