fleetmap-reports 2.0.137 → 2.0.139
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
|
@@ -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,42 @@ 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.5
|
|
16
|
+
|
|
17
|
+
const consumptionTarget = 11.5 // minutes
|
|
18
|
+
const consumptionCoefficient = 0.7
|
|
19
|
+
|
|
20
|
+
const rpmTarget = 60 // minutes
|
|
21
|
+
const rpmCoefficient = 0.8
|
|
22
|
+
|
|
23
|
+
const hardBrakingTarget = 1
|
|
24
|
+
const hardBrakingCoefficient = 0.10
|
|
25
|
+
|
|
26
|
+
const hardAccelerationTarget = 1
|
|
27
|
+
const hardAccelerationCoefficient = 0.10
|
|
28
|
+
|
|
29
|
+
const hardCorneringTarget = 1
|
|
30
|
+
const hardCorneringCoefficient = 0.10
|
|
31
|
+
|
|
32
|
+
const overspeedTarget = 2
|
|
33
|
+
const overspeedCoefficient = 0.15
|
|
34
|
+
|
|
35
|
+
const geofenceTarget = 1
|
|
36
|
+
const geofenceCoefficient = 0.15
|
|
37
|
+
|
|
38
|
+
const continuesDrivingTarget = 1
|
|
39
|
+
const continuesDrivingCoefficient = 0.1
|
|
40
|
+
|
|
41
|
+
const reverseTarget = 1
|
|
42
|
+
const reverseCoefficient = 0.1
|
|
43
|
+
|
|
44
|
+
const otherTarget = 1
|
|
45
|
+
const otherCoefficient = 0.1
|
|
10
46
|
|
|
11
47
|
async function create (from, to, userData, traccar) {
|
|
12
48
|
const reportData = []
|
|
@@ -18,9 +54,19 @@ async function create (from, to, userData, traccar) {
|
|
|
18
54
|
const driversData = new Map()
|
|
19
55
|
for (const device of devices) {
|
|
20
56
|
const allInOne = await traccarHelper.getAllInOne(traccar, from, to, [device], true, true, false, false, deviceCount, devices.length)
|
|
57
|
+
const hereResults = await getRoadSpeedLimits([device], allInOne.route, 5)
|
|
58
|
+
|
|
59
|
+
// getEvents
|
|
60
|
+
const geofenceAlarm = 0
|
|
61
|
+
const continuesDrivingAlarm = 0
|
|
62
|
+
const reverseAlarm = 0
|
|
63
|
+
const otherAlarm = 0
|
|
21
64
|
|
|
22
65
|
for (const d of drivers) {
|
|
23
66
|
const { trips, route } = await getDriverData(d, allInOne, userData)
|
|
67
|
+
const positionIds = route.map(p => p.id)
|
|
68
|
+
const driverOverSpeedEvents = hereResults.filter(e => positionIds.includes(e.positionId))
|
|
69
|
+
const spentFuel = calculateConsumption(device, { trips, route })
|
|
24
70
|
|
|
25
71
|
let driverData = driversData.get(d.id)
|
|
26
72
|
if (!driverData) {
|
|
@@ -30,7 +76,13 @@ async function create (from, to, userData, traccar) {
|
|
|
30
76
|
highEngineRPM: 0,
|
|
31
77
|
hardBraking: 0,
|
|
32
78
|
hardAcceleration: 0,
|
|
33
|
-
hardCornering: 0
|
|
79
|
+
hardCornering: 0,
|
|
80
|
+
overspeed: 0,
|
|
81
|
+
spentFuel: 0,
|
|
82
|
+
geofenceAlarm: 0,
|
|
83
|
+
continuesDrivingAlarm: 0,
|
|
84
|
+
reverseAlarm: 0,
|
|
85
|
+
otherAlarm: 0
|
|
34
86
|
}
|
|
35
87
|
driversData.set(d.id, driverData)
|
|
36
88
|
}
|
|
@@ -61,6 +113,12 @@ async function create (from, to, userData, traccar) {
|
|
|
61
113
|
driverData.hardBraking = driverData.hardBraking + hardBraking
|
|
62
114
|
driverData.hardAcceleration = driverData.hardAcceleration + hardAcceleration
|
|
63
115
|
driverData.hardCornering = driverData.hardCornering + hardCornering
|
|
116
|
+
driverData.overspeed = driverData.overspeed + driverOverSpeedEvents.length
|
|
117
|
+
driverData.spentFuel = driverData.spentFuel + spentFuel
|
|
118
|
+
driverData.geofenceAlarm = driverData.geofenceAlarm + geofenceAlarm
|
|
119
|
+
driverData.continuesDrivingAlarm = driverData.continuesDrivingAlarm + continuesDrivingAlarm
|
|
120
|
+
driverData.reverseAlarm = driverData.reverseAlarm + reverseAlarm
|
|
121
|
+
driverData.otherAlarm = driverData.otherAlarm + otherAlarm
|
|
64
122
|
}
|
|
65
123
|
|
|
66
124
|
deviceCount++
|
|
@@ -68,12 +126,41 @@ async function create (from, to, userData, traccar) {
|
|
|
68
126
|
|
|
69
127
|
const allDriversData = (Array.from(driversData.values())).filter(d => d.distance > 0)
|
|
70
128
|
allDriversData.forEach(d => {
|
|
71
|
-
|
|
129
|
+
const distanceScore = (Math.abs(d.distance - distanceTarget) / distanceTarget) * distanceCoefficient
|
|
130
|
+
const rpmScore = ((d.highEngineRPM / 60000) / rpmTarget) * rpmCoefficient
|
|
131
|
+
const hardBrakingScore = (d.hardBraking / hardBrakingTarget) * hardBrakingCoefficient
|
|
132
|
+
const hardAccelerationScore = (d.hardAcceleration / hardAccelerationTarget) * hardAccelerationCoefficient
|
|
133
|
+
const hardCorneringScore = (d.hardCornering / hardCorneringTarget) * hardCorneringCoefficient
|
|
134
|
+
const overspeedScore = (d.overspeed / overspeedTarget) * overspeedCoefficient
|
|
135
|
+
const consumptionScore = (getCanAvgConsumption(d.distance, d.spentFuel).byKms / consumptionTarget) * consumptionCoefficient
|
|
136
|
+
const geofenceAlarmScore = (d.geofenceAlarm / geofenceTarget) * geofenceCoefficient
|
|
137
|
+
const continuesDrivingAlarmScore = (d.continuesDrivingAlarm / continuesDrivingTarget) * continuesDrivingCoefficient
|
|
138
|
+
const reverseAlarmScore = (d.reverseAlarm / reverseTarget) * reverseCoefficient
|
|
139
|
+
const otherAlarmScore = (d.otherAlarm / otherTarget) * otherCoefficient
|
|
140
|
+
|
|
141
|
+
d.avgConsumption = getCanAvgConsumption(d.distance, d.spentFuel).byKms
|
|
142
|
+
d.score = distanceScore + rpmScore + hardBrakingScore + hardAccelerationScore +
|
|
143
|
+
hardCorneringScore + consumptionScore + overspeedScore + geofenceAlarmScore +
|
|
144
|
+
continuesDrivingAlarmScore + reverseAlarmScore + otherAlarmScore
|
|
72
145
|
})
|
|
73
146
|
allDriversData.sort((a, b) => (a.score > b.score) ? 1 : -1)
|
|
74
147
|
|
|
75
148
|
reportData.push(...allDriversData)
|
|
76
149
|
|
|
150
|
+
reportData.targetValues = {
|
|
151
|
+
distanceTarget,
|
|
152
|
+
rpmTarget,
|
|
153
|
+
hardBrakingTarget,
|
|
154
|
+
hardAccelerationTarget,
|
|
155
|
+
hardCorneringTarget,
|
|
156
|
+
consumptionTarget,
|
|
157
|
+
overspeedTarget,
|
|
158
|
+
geofenceTarget,
|
|
159
|
+
continuesDrivingTarget,
|
|
160
|
+
reverseTarget,
|
|
161
|
+
otherCoefficient
|
|
162
|
+
}
|
|
163
|
+
|
|
77
164
|
return reportData
|
|
78
165
|
}
|
|
79
166
|
|