fleetmap-reports 1.0.779 → 1.0.781

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/util/fuel.js +14 -17
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fleetmap-reports",
3
- "version": "1.0.779",
3
+ "version": "1.0.781",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
package/src/util/fuel.js CHANGED
@@ -23,24 +23,21 @@ function getRefuelingLiters (d, position, diff) {
23
23
  }
24
24
 
25
25
  function calculateConsumption (d, data, avgConsumption) {
26
- if (useOdooFuelData(d, data.route)) {
27
- return (avgConsumption.byKms * (data.trips.reduce((a, b) => a + b.distance, 0) / 1000) / 100)
28
- }
29
-
30
- const withFuelUsed = data.route && data.route.find(p => p.attributes.fuelUsed)
31
-
32
- if (data.summary) {
33
- return calculateSpentFuel(data.summary.spentFuel, d, withFuelUsed)
34
- }
35
-
36
- if (data.trips && data.stops) {
37
- const spentFuel = data.trips.reduce((a, b) => a + b.spentFuel, 0) + data.stops.reduce((a, b) => a + b.spentFuel, 0)
38
- return calculateSpentFuel(spentFuel, d, withFuelUsed)
39
- }
40
-
41
- if (data.route && data.route.length > 1 && data.route[0].attributes.fuelUsed) {
42
- return data.route[data.route.length - 1].attributes.fuelUsed - data.route[0].attributes.fuelUsed
26
+ let fuelConsumption = 0
27
+ if (useOdooFuelData(d, data.route) && avgConsumption) {
28
+ fuelConsumption = (avgConsumption.byKms * (data.trips.reduce((a, b) => a + b.distance, 0) / 1000) / 100)
29
+ } else {
30
+ const withFuelUsed = data.route && data.route.find(p => p.attributes.fuelUsed)
31
+ if (data.summary) {
32
+ fuelConsumption = calculateSpentFuel(data.summary.spentFuel, d, withFuelUsed)
33
+ } else if (data.trips && data.stops) {
34
+ const spentFuel = data.trips.reduce((a, b) => a + b.spentFuel, 0) + data.stops.reduce((a, b) => a + b.spentFuel, 0)
35
+ fuelConsumption = calculateSpentFuel(spentFuel, d, withFuelUsed)
36
+ } else if (data.route && data.route.length > 1 && data.route[0].attributes.fuelUsed) {
37
+ fuelConsumption = data.route[data.route.length - 1].attributes.fuelUsed - data.route[0].attributes.fuelUsed
38
+ }
43
39
  }
40
+ return fuelConsumption > 0 ? fuelConsumption : 0
44
41
  }
45
42
 
46
43
  function calculateSpentFuel (value, device, withFuelUsed) {