fleetmap-reports 2.0.344 → 2.0.345

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 +9 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fleetmap-reports",
3
- "version": "2.0.344",
3
+ "version": "2.0.345",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
package/src/util/fuel.js CHANGED
@@ -32,6 +32,15 @@ function calculateSpentFuel (value, device, withFuelUsed) {
32
32
  return withFuelUsed ? value : (value * device.attributes.fuel_tank_capacity) / 100
33
33
  }
34
34
 
35
+ const { fuel_low_threshold, fuel_high_threshold, fuel_tank_capacity } = device.attributes
36
+ if (fuel_low_threshold != null && fuel_high_threshold != null && fuel_tank_capacity) {
37
+ const sensorRange = Math.abs(fuel_high_threshold - fuel_low_threshold)
38
+ const rawFuel = fuel_low_threshold > fuel_high_threshold
39
+ ? (value < 0 ? Math.abs(value) : 0)
40
+ : value
41
+ return rawFuel > 0 ? (rawFuel / sensorRange) * fuel_tank_capacity : 0
42
+ }
43
+
35
44
  return value
36
45
  }
37
46