fleetmap-reports 1.0.736 → 1.0.738

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.736",
3
+ "version": "1.0.738",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -1,7 +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
+ const { getEndTripMessages, getCanDriverStyleMessages, parseEndTripMessage, parseCanDriverStyleMessage } = require('../util/xpert')
5
5
 
6
6
  async function createPerformanceReport (from, to, userData, traccar) {
7
7
  const reportData = []
@@ -22,30 +22,25 @@ async function createPerformanceReport (from, to, userData, traccar) {
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)
30
- t.canDriverStyle = canDriverStyle && parseCanDriverStyleMessage(canDriverStyle.xpertString)
31
- })
25
+ const endTripData = getEndTripMessages(deviceRoute).map(m => parseEndTripMessage(m.xpertString || m))
26
+ const canDriverStyle = getCanDriverStyleMessages(deviceRoute).map(m => parseCanDriverStyleMessage(m.xpertString || m))
32
27
 
33
28
  const deviceData = {
34
29
  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)
30
+ drivingTime: endTripData.reduce((a, b) => a + b.totalTimeDriving, 0),
31
+ idleTime: endTripData.reduce((a, b) => a + b.totalTimeInIdle, 0),
32
+ drivingConsumption: endTripData.reduce((a, b) => a + b.totalFuelConsumptionDriving, 0),
33
+ idleConsumption: endTripData.reduce((a, b) => a + b.totalFuelConsumptionInIdle, 0),
34
+ drivingDistance: endTripData.reduce((a, b) => a + b.totalDistanceTravelled, 0),
35
+ cruiseControlTime: endTripData.reduce((a, b) => a + b.totalTimeWithCruiseControl, 0),
36
+ cruiseControlConsumption: endTripData.reduce((a, b) => a + b.totalFuelConsumptionWithCruiseControl, 0),
37
+ cruiseControlDistance: endTripData.reduce((a, b) => a + b.totalDistanceTravelledWithCruiseControl, 0),
38
+ economicTime: canDriverStyle.reduce((a, b) => a + b.totalTimeInEcoRange, 0),
39
+ economicConsumption: canDriverStyle.reduce((a, b) => a + b.totalFuelConsumptionInEcoRange, 0),
40
+ economicDistance: canDriverStyle.reduce((a, b) => a + b.totalDistanceInEcoRange, 0),
41
+ highEngineRPM: canDriverStyle.reduce((a, b) => a + b.totalTimeWithHighRpmAndTorque, 0),
42
+ hardBreaking: canDriverStyle.reduce((a, b) => a + b.totalNumberOfHarshBrakes, 0),
43
+ hardAcceleration: canDriverStyle.reduce((a, b) => a + b.totalNumberOfHarshAccelerations, 0)
49
44
  }
50
45
  reportData.push(deviceData)
51
46
  })
@@ -2,6 +2,7 @@ const { getReports } = require('./index')
2
2
  const { createPerformanceReport } = require('../partnerReports/performance-report')
3
3
  // eslint-disable-next-line no-undef
4
4
  describe('performance', function () {
5
+ this.timeout(500000)
5
6
  // eslint-disable-next-line no-undef
6
7
  it('performance report', async () => {
7
8
  const report = await getReports()
package/src/util/xpert.js CHANGED
@@ -42,23 +42,21 @@ function parseCanDriverStyleMessage (xpertMessage) {
42
42
  }
43
43
  }
44
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'))
45
+ function getEndTripMessages (route) {
46
+ const positions = route.filter(p => p.attributes.xpert &&
47
+ (Array.isArray(p.attributes.xpert) ? p.attributes.xpert.find(x => x.type === '3') : p.attributes.xpert.split(';').find(m => m.startsWith('3'))))
49
48
 
50
- return p && p.attributes.xpert.find(x => x.type === '3')
49
+ return positions.map(p => (Array.isArray(p.attributes.xpert) ? p.attributes.xpert.find(x => x.type === '3') : p.attributes.xpert.split(';').find(m => m.startsWith('3'))))
51
50
  }
52
51
 
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'))
52
+ function getCanDriverStyleMessages (route) {
53
+ const positions = route.filter(p => p.attributes.xpert &&
54
+ (Array.isArray(p.attributes.xpert) ? p.attributes.xpert.find(x => x.type === '4') : p.attributes.xpert.split(';').find(m => m.startsWith('4'))))
57
55
 
58
- return p && p.attributes.xpert.find(x => x.type === '4')
56
+ return positions.map(p => (Array.isArray(p.attributes.xpert) ? p.attributes.xpert.find(x => x.type === '4') : p.attributes.xpert.split(';').find(m => m.startsWith('4'))))
59
57
  }
60
58
 
61
59
  exports.parseEndTripMessage = parseEndTripMessage
62
- exports.getEndTripMessage = getEndTripMessage
60
+ exports.getEndTripMessages = getEndTripMessages
63
61
  exports.parseCanDriverStyleMessage = parseCanDriverStyleMessage
64
- exports.getCanDriverStyleMessage = getCanDriverStyleMessage
62
+ exports.getCanDriverStyleMessages = getCanDriverStyleMessages