fleetmap-reports 1.0.773 → 1.0.775

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.773",
3
+ "version": "1.0.775",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -36,8 +36,8 @@ async function createPerformanceReport (from, to, userData, traccar) {
36
36
  const totalTime = drivingTime + idleTime
37
37
  const totalConsumption = drivingConsumption + idleConsumption
38
38
 
39
- const totalIndicator = (drivingDistance > 0 ? (totalConsumption * 0.1) * 100 / drivingDistance : 0).toFixed(1) + ' L/100'
40
- const drivingIndicator = (drivingDistance > 0 ? (drivingConsumption * 0.1) * 100 / drivingDistance : 0).toFixed(1) + ' L/100'
39
+ const totalIndicator = (drivingDistance > 0 ? totalConsumption * 100 / drivingDistance : 0).toFixed(1) + ' L/100'
40
+ const drivingIndicator = (drivingDistance > 0 ? drivingConsumption * 100 / drivingDistance : 0).toFixed(1) + ' L/100'
41
41
  const idleIndicator = (totalConsumption > 0 ? idleConsumption * 100 / totalConsumption : 0).toFixed(1) + ' %'
42
42
  const economicIndicator = (totalTime > 0 ? economicTime * 100 / totalTime : 0).toFixed(1) + ' %'
43
43
  const cruiseControlIndicator = (totalTime > 0 ? cruiseControlTime * 100 / totalTime : 0).toFixed(1) + ' %'
@@ -98,10 +98,10 @@ function getDeviceData (allInOne, d) {
98
98
  const hardBreaking = canDriverStyle.length > 1 ? canDriverStyle[canDriverStyle.length - 1].totalNumberOfHarshBrakes - canDriverStyle[0].totalNumberOfHarshBrakes : 0
99
99
  const hardAcceleration = canDriverStyle.length > 1 ? canDriverStyle[canDriverStyle.length - 1].totalNumberOfHarshAccelerations - canDriverStyle[0].totalNumberOfHarshAccelerations : 0
100
100
 
101
- const drivingConsumption = endTripData.length > 1 ? endTripData[endTripData.length - 1].totalFuelConsumptionDriving - endTripData[0].totalFuelConsumptionDriving : 0
102
- const idleConsumption = endTripData.length > 1 ? endTripData[endTripData.length - 1].totalFuelConsumptionInIdle - endTripData[0].totalFuelConsumptionInIdle : 0
103
- const cruiseControlConsumption = endTripData.length > 1 ? endTripData[endTripData.length - 1].totalFuelConsumptionWithCruiseControl - endTripData[0].totalFuelConsumptionWithCruiseControl : 0
104
- const economicConsumption = canDriverStyle.length > 1 ? canDriverStyle[canDriverStyle.length - 1].totalFuelConsumptionInEcoRange - canDriverStyle[0].totalFuelConsumptionInEcoRange : 0
101
+ const drivingConsumption = endTripData.length > 1 ? (endTripData[endTripData.length - 1].totalFuelConsumptionDriving - endTripData[0].totalFuelConsumptionDriving) * 0.1 : 0
102
+ const idleConsumption = endTripData.length > 1 ? (endTripData[endTripData.length - 1].totalFuelConsumptionInIdle - endTripData[0].totalFuelConsumptionInIdle) * 0.1 : 0
103
+ const cruiseControlConsumption = endTripData.length > 1 ? (endTripData[endTripData.length - 1].totalFuelConsumptionWithCruiseControl - endTripData[0].totalFuelConsumptionWithCruiseControl) * 0.1 : 0
104
+ const economicConsumption = canDriverStyle.length > 1 ? (canDriverStyle[canDriverStyle.length - 1].totalFuelConsumptionInEcoRange - canDriverStyle[0].totalFuelConsumptionInEcoRange) * 0.1 : 0
105
105
 
106
106
  const drivingDistance = endTripData.length > 1 ? endTripData[endTripData.length - 1].totalDistanceTravelled - endTripData[0].totalDistanceTravelled : 0
107
107
  const cruiseControlDistance = endTripData.length > 1 ? endTripData[endTripData.length - 1].totalDistanceTravelledWithCruiseControl - endTripData[0].totalDistanceTravelledWithCruiseControl : 0
@@ -124,13 +124,13 @@ function getDeviceData (allInOne, d) {
124
124
  economicDistance
125
125
  }
126
126
  } else {
127
- const deviceSummary = allInOne.summary.filter(t => t.deviceId === d.id)
127
+ const deviceSummary = allInOne.summary.filter(t => t.deviceId === d.id)[0]
128
128
 
129
129
  const drivingTime = deviceTrips.reduce((a, b) => a + b.duration, 0)
130
130
  const drivingConsumption = deviceTrips.reduce((a, b) => a + b.spentFuel, 0)
131
- const drivingDistance = deviceSummary.distance
132
- const idleTime = deviceSummary.engineHours - drivingTime
133
- const idleConsumption = deviceSummary.spentFuel - drivingConsumption
131
+ const drivingDistance = deviceSummary ? deviceSummary.distance / 1000 : 0
132
+ const idleTime = deviceSummary && deviceSummary.engineHours > drivingTime ? deviceSummary.engineHours - drivingTime : 0
133
+ const idleConsumption = deviceSummary && deviceSummary.spentFuel > drivingConsumption ? deviceSummary.spentFuel - drivingConsumption : 0
134
134
 
135
135
  const hardBreaking = deviceRoute.filter(p => p.attributes.io253 === 2).length
136
136
  const hardAcceleration = deviceRoute.filter(p => p.attributes.io253 === 1).length
@@ -27,6 +27,6 @@ describe('performance', function () {
27
27
  userData,
28
28
  report.traccar)
29
29
  console.log(data)
30
- assert.equal(data[0].consumption, 1685.1989999999996)
30
+ assert.equal(data[0].consumption, 168.51989999999998)
31
31
  }, 8000000)
32
32
  })