fleetmap-reports 2.0.142 → 2.0.144

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/lang/frFR.json CHANGED
@@ -288,7 +288,13 @@
288
288
  "highEngineRPM": "Moteur élevé",
289
289
  "hardAcceleration": "Accéleration brusque",
290
290
  "hardBraking": "Freinage brusque",
291
- "hardCornering": "Virages brusque"
291
+ "hardCornering": "Virages brusque",
292
+ "avgFuelConsumption": "Avg. L/100",
293
+ "overspeedAlarm": "Exces Vitesse",
294
+ "geofenceAlarm": "Ceinture",
295
+ "continuesDrivingAlarm": "Cond. Continue",
296
+ "reverseAlarm": "Marche Arriere",
297
+ "otherAlarm": "Other"
292
298
  },
293
299
  "layout": {
294
300
  "deviceOnline": "Appareil en ligne",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fleetmap-reports",
3
- "version": "2.0.142",
3
+ "version": "2.0.144",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -2,7 +2,7 @@ const traccarHelper = require('../util/traccar')
2
2
  const { getDriverData } = require('../util/driver')
3
3
  const { getCanDriverStyleMessages, parseCanDriverStyleMessage } = require('../util/xpert')
4
4
  const { calculateRPMSections } = require('./performance-report')
5
- const { getTranslations, isClientSide, convertToLocaleString } = require('../util/utils')
5
+ const { getTranslations, isClientSide, convertToLocaleString, convertMS } = require('../util/utils')
6
6
  const jsPDF = require('jspdf')
7
7
  const { headerFromUser, addTable } = require('../util/pdfDocument')
8
8
  const { getStyle } = require('../reportStyle')
@@ -11,41 +11,22 @@ const { getOverspeedEvents } = require('../speeding-report')
11
11
  const { calculateConsumption } = require('../util/fuel')
12
12
  const { getCanAvgConsumption } = require('../fuel-consumption-report')
13
13
 
14
- const distanceTarget = 10000000 // meters
15
14
  const distanceCoefficient = 0.5
16
-
17
- const consumptionTarget = 11.5 // minutes
18
15
  const consumptionCoefficient = 0.7
19
-
20
- const rpmTarget = 60 // minutes
21
16
  const rpmCoefficient = 0.8
22
-
23
- const hardBrakingTarget = 1
24
17
  const hardBrakingCoefficient = 0.10
25
-
26
- const hardAccelerationTarget = 1
27
18
  const hardAccelerationCoefficient = 0.10
28
-
29
- const hardCorneringTarget = 1
30
19
  const hardCorneringCoefficient = 0.10
31
-
32
- const overspeedTarget = 2
33
20
  const overspeedCoefficient = 0.15
34
-
35
- const geofenceTarget = 1
36
21
  const geofenceCoefficient = 0.15
37
-
38
- const continuesDrivingTarget = 1
39
22
  const continuesDrivingCoefficient = 0.1
40
-
41
- const reverseTarget = 1
42
23
  const reverseCoefficient = 0.1
43
-
44
- const otherTarget = 1
45
24
  const otherCoefficient = 0.1
46
25
 
47
26
  async function create (from, to, userData, traccar) {
48
- const reportData = []
27
+ const reportData = {
28
+ drivers: []
29
+ }
49
30
 
50
31
  const drivers = userData.drivers
51
32
  const devices = userData.devices
@@ -131,38 +112,52 @@ async function create (from, to, userData, traccar) {
131
112
 
132
113
  const allDriversData = (Array.from(driversData.values())).filter(d => d.distance > 0)
133
114
  allDriversData.forEach(d => {
134
- const distanceScore = (Math.abs(d.distance - distanceTarget) / distanceTarget) * distanceCoefficient
135
- const rpmScore = ((d.highEngineRPM / 60000) / rpmTarget) * rpmCoefficient
136
- const hardBrakingScore = (d.hardBraking / hardBrakingTarget) * hardBrakingCoefficient
137
- const hardAccelerationScore = (d.hardAcceleration / hardAccelerationTarget) * hardAccelerationCoefficient
138
- const hardCorneringScore = (d.hardCornering / hardCorneringTarget) * hardCorneringCoefficient
139
- const overspeedScore = (d.overspeed / overspeedTarget) * overspeedCoefficient
140
- const consumptionScore = (getCanAvgConsumption(d.distance, d.spentFuel).byKms / consumptionTarget) * consumptionCoefficient
141
- const geofenceAlarmScore = (d.geofenceAlarm / geofenceTarget) * geofenceCoefficient
142
- const continuesDrivingAlarmScore = (d.continuesDrivingAlarm / continuesDrivingTarget) * continuesDrivingCoefficient
143
- const reverseAlarmScore = (d.reverseAlarm / reverseTarget) * reverseCoefficient
144
- const otherAlarmScore = (d.otherAlarm / otherTarget) * otherCoefficient
145
-
146
- d.avgConsumption = getCanAvgConsumption(d.distance, d.spentFuel).byKms
115
+ const distanceScore = (Math.abs(d.distance - userData.distanceTarget) / userData.distanceTarget) * distanceCoefficient
116
+ const rpmScore = ((d.highEngineRPM / 60000) / userData.rpmTarget) * rpmCoefficient
117
+ const hardBrakingScore = (d.hardBraking / userData.hardBrakingTarget) * hardBrakingCoefficient
118
+ const hardAccelerationScore = (d.hardAcceleration / userData.hardAccelerationTarget) * hardAccelerationCoefficient
119
+ const hardCorneringScore = (d.hardCornering / userData.hardCorneringTarget) * hardCorneringCoefficient
120
+ const overspeedScore = (d.overspeed / userData.overspeedTarget) * overspeedCoefficient
121
+ const consumptionScore = (getCanAvgConsumption(d.distance, d.spentFuel).byKms / userData.fuelConsumptionTarget) * consumptionCoefficient
122
+ const geofenceAlarmScore = (d.geofenceAlarm / userData.geofenceTarget) * geofenceCoefficient
123
+ const continuesDrivingAlarmScore = (d.continuesDrivingAlarm / userData.continuesDrivingTarget) * continuesDrivingCoefficient
124
+ const reverseAlarmScore = (d.reverseAlarm / userData.reverseTarget) * reverseCoefficient
125
+ const otherAlarmScore = (d.otherAlarm / userData.otherTarget) * otherCoefficient
126
+
127
+ d.avgFuelConsumption = getCanAvgConsumption(d.distance, d.spentFuel).byKms
147
128
  d.score = distanceScore + rpmScore + hardBrakingScore + hardAccelerationScore +
148
129
  hardCorneringScore + consumptionScore + overspeedScore + geofenceAlarmScore +
149
130
  continuesDrivingAlarmScore + reverseAlarmScore + otherAlarmScore
150
131
  })
151
132
  allDriversData.sort((a, b) => (a.score > b.score) ? 1 : -1)
152
133
 
153
- reportData.push(...allDriversData)
154
-
155
- reportData.targetValues = {
156
- distanceTarget,
157
- rpmTarget,
158
- hardBrakingTarget,
159
- hardAccelerationTarget,
160
- hardCorneringTarget,
161
- consumptionTarget,
162
- overspeedTarget,
163
- geofenceTarget,
164
- continuesDrivingTarget,
165
- reverseTarget,
134
+ reportData.drivers.push(...allDriversData)
135
+
136
+ reportData.target = {
137
+ distanceTarget: userData.distanceTarget,
138
+ rpmTarget: userData.rpmTarget,
139
+ hardBrakingTarget: userData.hardBrakingTarget,
140
+ hardAccelerationTarget: userData.hardAccelerationTarget,
141
+ hardCorneringTarget: userData.hardCorneringTarget,
142
+ fuelConsumptionTarget: userData.fuelConsumptionTarget,
143
+ overspeedTarget: userData.overspeedTarget,
144
+ geofenceTarget: userData.geofenceTarget,
145
+ continuesDrivingTarget: userData.continuesDrivingTarget,
146
+ reverseTarget: userData.reverseTarget,
147
+ otherTarget: userData.otherTarget
148
+ }
149
+
150
+ reportData.coefficient = {
151
+ distanceCoefficient,
152
+ rpmCoefficient,
153
+ hardBrakingCoefficient,
154
+ hardAccelerationCoefficient,
155
+ hardCorneringCoefficient,
156
+ consumptionCoefficient,
157
+ overspeedCoefficient,
158
+ geofenceCoefficient,
159
+ continuesDrivingCoefficient,
160
+ reverseCoefficient,
166
161
  otherCoefficient
167
162
  }
168
163
 
@@ -175,7 +170,7 @@ async function exportToExcel (userData, reportData) {
175
170
 
176
171
  const translations = getTranslations(userData)
177
172
 
178
- const reportDataRows = reportData
173
+ const reportDataRows = reportData.drivers
179
174
 
180
175
  const settings = {
181
176
  sheetName: translations.report.titleDriverRankingReport, // The name of the sheet
@@ -185,10 +180,16 @@ async function exportToExcel (userData, reportData) {
185
180
  const headers = [
186
181
  { label: translations.report.driver, value: 'name' },
187
182
  { label: translations.report.distance, value: 'distance' },
183
+ { label: translations.report.avgFuelConsumption, value: 'avgFuelConsumption' },
188
184
  { label: translations.report.highEngineRPM, value: 'highEngineRPM' },
189
185
  { label: translations.report.hardBraking, value: 'hardBraking' },
190
186
  { label: translations.report.hardAcceleration, value: 'hardAcceleration' },
191
187
  { label: translations.report.hardCornering, value: 'hardCornering' },
188
+ { label: translations.report.overspeedAlarm, value: 'overspeed' },
189
+ { label: translations.report.geofenceAlarm, value: 'geofenceAlarm' },
190
+ { label: translations.report.continuesDrivingAlarm, value: 'continuesDrivingAlarm' },
191
+ { label: translations.report.reverseAlarm, value: 'reverseAlarm' },
192
+ { label: translations.report.otherAlarm, value: 'otherAlarm' },
192
193
  { label: translations.report.score, value: 'score' }
193
194
  ]
194
195
 
@@ -198,11 +199,17 @@ async function exportToExcel (userData, reportData) {
198
199
  data = data.concat({
199
200
  name: row.name,
200
201
  distance: Number(row.distance.toFixed(1)),
201
- highEngineRPM: row.highEngineRPM,
202
+ avgFuelConsumption: Number(row.avgFuelConsumption.toFixed(2)),
203
+ highEngineRPM: convertMS(row.highEngineRPM, false),
202
204
  hardBraking: row.hardBraking,
203
205
  hardAcceleration: row.hardAcceleration,
204
206
  hardCornering: row.hardCornering,
205
- score: row.score
207
+ overspeed: row.overspeed,
208
+ geofenceAlarm: row.geofenceAlarm,
209
+ continuesDrivingAlarm: row.continuesDrivingAlarm,
210
+ reverseAlarm: row.reverseAlarm,
211
+ otherAlarm: row.otherAlarm,
212
+ score: Number(row.score.toFixed(2))
206
213
  })
207
214
  })
208
215
  console.log(data)
@@ -220,15 +227,21 @@ async function exportToPDF (userData, reportData) {
220
227
  const timezone = userData.user.attributes.timezone
221
228
  const translations = getTranslations(userData)
222
229
  const lang = userData.user.attributes.lang || (isClientSide() && navigator.language)
223
- const reportDataRows = reportData.devices
230
+ const reportDataRows = reportData.drivers
224
231
 
225
232
  const headers = [
226
233
  translations.report.driver,
227
234
  translations.report.distance,
235
+ translations.report.avgFuelConsumption,
228
236
  translations.report.highEngineRPM,
229
237
  translations.report.hardBraking,
230
238
  translations.report.hardAcceleration,
231
239
  translations.report.hardCornering,
240
+ translations.report.overspeedAlarm,
241
+ translations.report.geofenceAlarm,
242
+ translations.report.continuesDrivingAlarm,
243
+ translations.report.reverseAlarm,
244
+ translations.report.otherAlarm,
232
245
  translations.report.score
233
246
  ]
234
247
 
@@ -244,12 +257,18 @@ async function exportToPDF (userData, reportData) {
244
257
  reportDataRows.forEach(function (row) {
245
258
  const temp = [
246
259
  row.name,
247
- row.distance,
248
- row.highEngineRPM,
260
+ row.distance.toFixed(1),
261
+ row.avgFuelConsumption.toFixed(2),
262
+ convertMS(row.highEngineRPM, false),
249
263
  row.hardBraking,
250
264
  row.hardAcceleration,
251
265
  row.hardCornering,
252
- row.score
266
+ row.overspeed,
267
+ row.geofenceAlarm,
268
+ row.continuesDrivingAlarm,
269
+ row.reverseAlarm,
270
+ row.otherAlarm,
271
+ row.score.toFixed(2)
253
272
  ]
254
273
  data.push(temp)
255
274
  })
@@ -257,7 +276,20 @@ async function exportToPDF (userData, reportData) {
257
276
 
258
277
  const style = getStyle(getUserPartner(userData.user))
259
278
 
260
- addTable(doc, headers, data, footValues, style, 40)
279
+ addTable(doc, headers, data, footValues, style, 40, {
280
+ 1: { halign: 'right' },
281
+ 2: { halign: 'right' },
282
+ 3: { halign: 'right' },
283
+ 4: { halign: 'right' },
284
+ 5: { halign: 'right' },
285
+ 6: { halign: 'right' },
286
+ 7: { halign: 'right' },
287
+ 8: { halign: 'right' },
288
+ 9: { halign: 'right' },
289
+ 10: { halign: 'right' },
290
+ 11: { halign: 'right' },
291
+ 12: { halign: 'right' }
292
+ })
261
293
  return doc
262
294
  }
263
295
  }