fleetmap-reports 2.0.136 → 2.0.138

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.136",
3
+ "version": "2.0.138",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -276,3 +276,4 @@ exports.exportFuelConsumptionReportToExcel = exportFuelConsumptionReportToExcel
276
276
  exports.create = createFuelConsumptionReport
277
277
  exports.exportToPDF = exportFuelConsumptionReportToPDF
278
278
  exports.exportToExcel = exportFuelConsumptionReportToExcel
279
+ exports.getCanAvgConsumption = getCanAvgConsumption
@@ -7,6 +7,30 @@ const jsPDF = require('jspdf')
7
7
  const { headerFromUser, addTable } = require('../util/pdfDocument')
8
8
  const { getStyle } = require('../reportStyle')
9
9
  const { getUserPartner } = require('fleetmap-partners')
10
+ const { getRoadSpeedLimits } = require('../speeding-report')
11
+ const { calculateConsumption } = require('../util/fuel')
12
+ const { getCanAvgConsumption } = require('../fuel-consumption-report')
13
+
14
+ const distanceTarget = 10000 // meters
15
+ const distanceCoefficient = 0.9
16
+
17
+ const consumptionTarget = 11.5 // minutes
18
+ const consumptionCoefficient = 0.13
19
+
20
+ const rpmTarget = 60 // minutes
21
+ const rpmCoefficient = 0.13
22
+
23
+ const hardBrakingTarget = 1
24
+ const hardBrakingCoefficient = 0.15
25
+
26
+ const hardAccelerationTarget = 1
27
+ const hardAccelerationCoefficient = 0.15
28
+
29
+ const hardCorneringTarget = 1
30
+ const hardCorneringCoefficient = 0.15
31
+
32
+ const overspeedTarget = 2
33
+ const overspeedCoefficient = 0.2
10
34
 
11
35
  async function create (from, to, userData, traccar) {
12
36
  const reportData = []
@@ -18,9 +42,13 @@ async function create (from, to, userData, traccar) {
18
42
  const driversData = new Map()
19
43
  for (const device of devices) {
20
44
  const allInOne = await traccarHelper.getAllInOne(traccar, from, to, [device], true, true, false, false, deviceCount, devices.length)
45
+ const hereResults = await getRoadSpeedLimits([device], allInOne.route, 5)
21
46
 
22
47
  for (const d of drivers) {
23
48
  const { trips, route } = await getDriverData(d, allInOne, userData)
49
+ const positionIds = route.map(p => p.id)
50
+ const driverOverSpeedEvents = hereResults.filter(e => positionIds.includes(e.positionId))
51
+ const spentFuel = calculateConsumption(d, { trips, route })
24
52
 
25
53
  let driverData = driversData.get(d.id)
26
54
  if (!driverData) {
@@ -30,7 +58,9 @@ async function create (from, to, userData, traccar) {
30
58
  highEngineRPM: 0,
31
59
  hardBraking: 0,
32
60
  hardAcceleration: 0,
33
- hardCornering: 0
61
+ hardCornering: 0,
62
+ overspeed: 0,
63
+ spentFuel: 0
34
64
  }
35
65
  driversData.set(d.id, driverData)
36
66
  }
@@ -61,6 +91,8 @@ async function create (from, to, userData, traccar) {
61
91
  driverData.hardBraking = driverData.hardBraking + hardBraking
62
92
  driverData.hardAcceleration = driverData.hardAcceleration + hardAcceleration
63
93
  driverData.hardCornering = driverData.hardCornering + hardCornering
94
+ driverData.overspeed = driverData.overspeed + driverOverSpeedEvents.length
95
+ driverData.spentFuel = driverData.spentFuel + spentFuel
64
96
  }
65
97
 
66
98
  deviceCount++
@@ -68,7 +100,16 @@ async function create (from, to, userData, traccar) {
68
100
 
69
101
  const allDriversData = (Array.from(driversData.values())).filter(d => d.distance > 0)
70
102
  allDriversData.forEach(d => {
71
- d.score = (d.highEngineRPM + d.hardBraking + d.hardAcceleration + d.hardCornering) / (d.distance / 1000)
103
+ const distanceScore = (Math.abs(d.distance - distanceTarget) / distanceTarget) * distanceCoefficient
104
+ const rpmScore = ((d.highEngineRPM / 60000) / rpmTarget) * rpmCoefficient
105
+ const hardBrakingScore = (d.hardBraking / hardBrakingTarget) * hardBrakingCoefficient
106
+ const hardAccelerationScore = (d.hardAcceleration / hardAccelerationTarget) * hardAccelerationCoefficient
107
+ const hardCorneringScore = (d.hardCornering / hardCorneringTarget) * hardCorneringCoefficient
108
+ const overspeedScore = (d.overspeed / overspeedTarget) * overspeedCoefficient
109
+ const consumptionScore = (getCanAvgConsumption(d.distance, d.spentFuel).byKms / consumptionTarget) * consumptionCoefficient
110
+
111
+ d.avgConsumption = getCanAvgConsumption(d.distance, d.spentFuel).byKms
112
+ d.score = distanceScore + rpmScore + hardBrakingScore + hardAccelerationScore + hardCorneringScore + consumptionScore + overspeedScore
72
113
  })
73
114
  allDriversData.sort((a, b) => (a.score > b.score) ? 1 : -1)
74
115