fleetmap-reports 2.0.127 → 2.0.129

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.127",
3
+ "version": "2.0.129",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -409,8 +409,8 @@ function exportLocationReportToExcel (userData, reportData) {
409
409
  driver: userData.byDriver ? d.driver.name : getDriverName(a.attributes.driverUniqueId, a.fixTime, userData),
410
410
  temperature: getTempValue(a, 'temp1'),
411
411
  temperature2: getTempValue(a, 'temp2'),
412
- digitalport1: getDigitalPortValue(a, 1, translations, d.device.attributes),
413
- digitalport2: getDigitalPortValue(a, 2, translations, d.device.attributes),
412
+ digitalport1: d.device && getDigitalPortValue(a, 1, translations, d.device.attributes),
413
+ digitalport2: d.device && getDigitalPortValue(a, 2, translations, d.device.attributes),
414
414
  latitude: a.latitude,
415
415
  longitude: a.longitude
416
416
  }
@@ -0,0 +1,34 @@
1
+ const traccarHelper = require('../util/traccar')
2
+ const { getDriverData } = require('../util/driver')
3
+ const { getCanDriverStyleMessages, parseCanDriverStyleMessage } = require('../util/xpert')
4
+
5
+ async function createDriverRankingReport (from, to, userData, traccar) {
6
+ const reportData = []
7
+
8
+ const drivers = userData.drivers
9
+ const devices = userData.devices
10
+
11
+ const allInOne = await traccarHelper.getAllInOne(traccar, from, to, devices, true, true, false, false)
12
+
13
+ for (const d of drivers) {
14
+ const { trips, route } = await getDriverData(d, allInOne, userData)
15
+ const xpertMessages = route.map(p => p.attributes.rawXpert).filter(a => a)
16
+ const canDriverStyle = getCanDriverStyleMessages(xpertMessages).map(m => parseCanDriverStyleMessage(m.xpertString || m)).sort((a, b) => a.date.localeCompare(b.date))
17
+
18
+ const highEngineRPM = canDriverStyle.length > 1 ? canDriverStyle[canDriverStyle.length - 1].totalTimeWithHighRpmAndTorque - canDriverStyle[0].totalTimeWithHighRpmAndTorque : 0
19
+ const hardBraking = canDriverStyle.length > 1 ? canDriverStyle[canDriverStyle.length - 1].totalNumberOfHarshBrakes - canDriverStyle[0].totalNumberOfHarshBrakes : 0
20
+ const hardAcceleration = canDriverStyle.length > 1 ? canDriverStyle[canDriverStyle.length - 1].totalNumberOfHarshAccelerations - canDriverStyle[0].totalNumberOfHarshAccelerations : 0
21
+
22
+ reportData.drivers.push({
23
+ name: d.name,
24
+ distance: trips.filter(t => t.distance > 0).reduce((a, b) => a + b.distance, 0),
25
+ highEngineRPM,
26
+ hardBraking,
27
+ hardAcceleration
28
+ })
29
+ }
30
+
31
+ return reportData
32
+ }
33
+
34
+ exports.createDriverRankingReport = createDriverRankingReport