fleetmap-reports 2.0.344 → 2.0.346

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 +11 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fleetmap-reports",
3
- "version": "2.0.344",
3
+ "version": "2.0.346",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
package/src/util/fuel.js CHANGED
@@ -15,8 +15,7 @@ function calculateConsumption (d, data) {
15
15
  if (data.summary && withFuelUsed) {
16
16
  fuelConsumption = calculateSpentFuel(data.summary.spentFuel, d, withFuelUsed)
17
17
  } else if (data.trips && data.stops) {
18
- const spentFuel = data.trips.reduce((a, b) => a + (b.spentFuel > 0 ? b.spentFuel : 0), 0) + data.stops.reduce((a, b) => a + (b.spentFuel > 0 ? b.spentFuel : 0), 0)
19
- fuelConsumption = calculateSpentFuel(spentFuel, d, withFuelUsed)
18
+ fuelConsumption = data.trips.reduce((a, b) => a + calculateSpentFuel(b.spentFuel, d, withFuelUsed), 0) + data.stops.reduce((a, b) => a + calculateSpentFuel(b.spentFuel, d, withFuelUsed), 0)
20
19
  } else if (data.route && data.route.length > 1 && data.route[0].attributes.fuelUsed) {
21
20
  fuelConsumption = data.route[data.route.length - 1].attributes.fuelUsed - data.route[0].attributes.fuelUsed
22
21
  } else if (data.summary) {
@@ -32,7 +31,16 @@ function calculateSpentFuel (value, device, withFuelUsed) {
32
31
  return withFuelUsed ? value : (value * device.attributes.fuel_tank_capacity) / 100
33
32
  }
34
33
 
35
- return value
34
+ const { fuel_low_threshold, fuel_high_threshold, fuel_tank_capacity } = device.attributes
35
+ if (fuel_low_threshold != null && fuel_high_threshold != null && fuel_tank_capacity) {
36
+ const sensorRange = Math.abs(fuel_high_threshold - fuel_low_threshold)
37
+ const rawFuel = fuel_low_threshold > fuel_high_threshold
38
+ ? (value < 0 ? Math.abs(value) : 0)
39
+ : value
40
+ return rawFuel > 0 ? (rawFuel / sensorRange) * fuel_tank_capacity : 0
41
+ }
42
+
43
+ return value > 0 ? value : 0
36
44
  }
37
45
 
38
46
  function useOdooFuelData (d, route) {