fleetmap-reports 1.0.734 → 1.0.736

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.734",
3
+ "version": "1.0.736",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -1,25 +1,57 @@
1
- async function createPerformanceReport (from, to, userData, traccarInstance) {
1
+ const automaticReports = require('../automaticReports')
2
+ const traccarHelper = require('../util/traccar')
3
+ const { getUncompletedTrip } = require('../util/trips')
4
+ const { getEndTripMessage, getCanDriverStyleMessage, parseEndTripMessage, parseCanDriverStyleMessage } = require('../util/xpert')
5
+
6
+ async function createPerformanceReport (from, to, userData, traccar) {
2
7
  const reportData = []
3
- userData.devices.forEach(d => {
4
- const deviceData = {
5
- device: d.name,
6
- drivingTime: 850000,
7
- idleTime: 200000,
8
- drivingConsumption: 20,
9
- idleConsumption: 10,
10
- drivingDistance: 10000,
11
- economicTime: 265000,
12
- economicConsumption: 5,
13
- economicDistance: 99000,
14
- cruiseControlTime: 0,
15
- cruiseControlConsumption: 0,
16
- cruiseControlDistance: 0,
17
- highMotorRPM: 66000,
18
- hardBreaking: 10,
19
- hardAcceleration: 5
20
- }
21
- reportData.push(deviceData)
22
- })
8
+
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
+ deviceTrips.forEach(t => {
26
+ const endTripData = getEndTripMessage(t, deviceRoute)
27
+ const canDriverStyle = getCanDriverStyleMessage(t, deviceRoute)
28
+
29
+ t.endTripData = endTripData && parseEndTripMessage(endTripData.xpertString)
30
+ t.canDriverStyle = canDriverStyle && parseCanDriverStyleMessage(canDriverStyle.xpertString)
31
+ })
32
+
33
+ const deviceData = {
34
+ device: d.name,
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.totalDistanceInEcoRange : 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)
49
+ }
50
+ reportData.push(deviceData)
51
+ })
52
+
53
+ deviceCount = deviceCount + slice.length
54
+ }
23
55
  return reportData
24
56
  }
25
57
 
@@ -0,0 +1,17 @@
1
+ const { getReports } = require('./index')
2
+ const { createPerformanceReport } = require('../partnerReports/performance-report')
3
+ // eslint-disable-next-line no-undef
4
+ describe('performance', function () {
5
+ // eslint-disable-next-line no-undef
6
+ it('performance report', async () => {
7
+ const report = await getReports()
8
+ const userData = await report.getUserData()
9
+ userData.devices = userData.devices.filter(d => d.attributes.xpert)
10
+ const data = await createPerformanceReport(
11
+ new Date(Date.UTC(2023, 5, 10, 0, 0, 0, 0)),
12
+ new Date(Date.UTC(2023, 5, 20, 23, 59, 59, 0)),
13
+ userData,
14
+ report.traccar)
15
+ console.log(data)
16
+ })
17
+ })
@@ -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 { isInsideTimetable, isPartialInsideTimetable, calculateTrip, getTripIdleTime, calculateStopDuration } = require('./util/trips')
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
- if (deviceRoute.length && deviceTrips.length && deviceRoute[deviceRoute.length - 1].attributes.ignition) {
156
- const uncompletedTripRoute = deviceRoute.filter(p => p.attributes.ignition && new Date(p.fixTime).getTime() > new Date(deviceTrips[deviceTrips.length - 1].endTime).getTime())
157
- if (uncompletedTripRoute.length) {
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
@@ -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
+ p.attributes.xpert.find(x => x.type === '3'))
49
+
50
+ return p && p.attributes.xpert.find(x => x.type === '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
+ p.attributes.xpert.find(x => x.type === '4'))
57
+
58
+ return p && p.attributes.xpert.find(x => x.type === '4')
59
+ }
60
+
61
+ exports.parseEndTripMessage = parseEndTripMessage
62
+ exports.getEndTripMessage = getEndTripMessage
63
+ exports.parseCanDriverStyleMessage = parseCanDriverStyleMessage
64
+ exports.getCanDriverStyleMessage = getCanDriverStyleMessage