fleetmap-reports 2.0.109 → 2.0.110

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": "2.0.109",
3
+ "version": "2.0.110",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -98,10 +98,11 @@ function getDeviceData (allInOne, d) {
98
98
  deviceTrips.push(uncompletedTrip)
99
99
  }
100
100
 
101
- if (deviceRoute.find(p => p.attributes.xpert)) {
101
+ if (deviceRoute.find(p => p.attributes.rawXpert)) {
102
102
  // Inofleet unit with xpert data
103
- const endTripData = getEndTripMessages(deviceRoute).map(m => parseEndTripMessage(m.xpertString || m)).sort((a, b) => a.date.localeCompare(b.date))
104
- const canDriverStyle = getCanDriverStyleMessages(deviceRoute).map(m => parseCanDriverStyleMessage(m.xpertString || m)).sort((a, b) => a.date.localeCompare(b.date))
103
+ const xpertMessages = deviceRoute.map(p => p.attributes.rawXpert).filter(a => a)
104
+ const endTripData = getEndTripMessages(xpertMessages).map(m => parseEndTripMessage(m.xpertString || m)).sort((a, b) => a.date.localeCompare(b.date))
105
+ const canDriverStyle = getCanDriverStyleMessages(xpertMessages).map(m => parseCanDriverStyleMessage(m.xpertString || m)).sort((a, b) => a.date.localeCompare(b.date))
105
106
 
106
107
  const drivingTime = endTripData.length > 1 ? endTripData[endTripData.length - 1].totalTimeDriving - endTripData[0].totalTimeDriving : 0
107
108
  const idleTime = endTripData.length > 1 ? (endTripData[endTripData.length - 1].totalTimeInIdle || 0) - (endTripData[0].totalTimeInIdle || 0) : 0
@@ -145,7 +146,7 @@ function getDeviceData (allInOne, d) {
145
146
  const drivingTime = deviceTrips.reduce((a, b) => a + b.duration, 0)
146
147
  const drivingConsumption = calculateConsumption(d, { trips: deviceTrips, stops: [], route: deviceRoute, summary: deviceSummary }, undefined)
147
148
  const drivingDistance = deviceSummary ? deviceSummary.distance / 1000 : 0
148
- const idleTime = deviceTrips.reduce((a, b) => a + b.idleTime, 0) + deviceStops.reduce((a, b) => a + b.engineHours, 0)
149
+ const idleTime = deviceTrips.reduce((a, b) => a + (b.idleTime ? b.idleTime : 0), 0) + deviceStops.reduce((a, b) => a + b.engineHours, 0)
149
150
  const idleConsumption = deviceSummary && deviceSummary.spentFuel > drivingConsumption ? deviceSummary.spentFuel - drivingConsumption : 0
150
151
 
151
152
  const highEngineRPMSections = calculateRPMSections(deviceRoute, d.attributes.highRPM || 1300)
package/src/util/xpert.js CHANGED
@@ -44,18 +44,12 @@ function parseCanDriverStyleMessage (xpertMessage) {
44
44
  }
45
45
  }
46
46
 
47
- function getEndTripMessages (route) {
48
- const positions = route.filter(p => p.attributes.xpert &&
49
- (Array.isArray(p.attributes.xpert) ? p.attributes.xpert.find(x => x.type === '3') : p.attributes.xpert.split(';').find(m => m.startsWith('3'))))
50
-
51
- 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'))))
47
+ function getEndTripMessages (xpertMessages) {
48
+ return xpertMessages.map(xpert => (Array.isArray(xpert) ? xpert.find(x => x.type === '3') : xpert.split(';').find(m => m.startsWith('3')))).filter(a => a)
52
49
  }
53
50
 
54
- function getCanDriverStyleMessages (route) {
55
- const positions = route.filter(p => 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 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'))))
51
+ function getCanDriverStyleMessages (xpertMessages) {
52
+ return xpertMessages.map(xpert => (Array.isArray(xpert) ? xpert.find(x => x.type === '4') : xpert.split(';').find(m => m.startsWith('4')))).filter(a => a)
59
53
  }
60
54
 
61
55
  exports.parseEndTripMessage = parseEndTripMessage