fleetmap-reports 1.0.737 → 1.0.739

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": "1.0.737",
3
+ "version": "1.0.739",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -1,6 +1,10 @@
1
1
  const moment = require('moment')
2
2
 
3
- function sliceArray (longArray, size = 1) {
3
+ const maxParallelRequests = 25
4
+ function sliceArray (longArray, size) {
5
+ if (!size) {
6
+ size = (longArray.length / maxParallelRequests) + 1
7
+ }
4
8
  const arrayToSlice = longArray.slice()
5
9
 
6
10
  const arrayOfArrays = []
@@ -1,7 +1,7 @@
1
1
  const automaticReports = require('../automaticReports')
2
2
  const traccarHelper = require('../util/traccar')
3
3
  const { getUncompletedTrip } = require('../util/trips')
4
- const { getEndTripMessage, getCanDriverStyleMessage, parseEndTripMessage, parseCanDriverStyleMessage } = require('../util/xpert')
4
+ const { getEndTripMessages, getCanDriverStyleMessages, parseEndTripMessage, parseCanDriverStyleMessage } = require('../util/xpert')
5
5
 
6
6
  async function createPerformanceReport (from, to, userData, traccar) {
7
7
  const reportData = []
@@ -22,30 +22,25 @@ async function createPerformanceReport (from, to, userData, traccar) {
22
22
  deviceTrips.push(uncompletedTrip)
23
23
  }
24
24
 
25
- deviceTrips.forEach(t => {
26
- const endTripData = getEndTripMessage(t, deviceRoute)
27
- const canDriverStyle = getCanDriverStyleMessage(t, deviceRoute)
28
-
29
- t.endTripData = endTripData && parseEndTripMessage(endTripData.xpertString || endTripData)
30
- t.canDriverStyle = canDriverStyle && parseCanDriverStyleMessage(canDriverStyle.xpertString || canDriverStyle)
31
- })
25
+ const endTripData = getEndTripMessages(deviceRoute).map(m => parseEndTripMessage(m.xpertString || m))
26
+ const canDriverStyle = getCanDriverStyleMessages(deviceRoute).map(m => parseCanDriverStyleMessage(m.xpertString || m))
32
27
 
33
28
  const deviceData = {
34
29
  device: d.name,
35
- drivingTime: deviceTrips.reduce((a, b) => a + (b.endTripData ? b.endTripData.totalTimeDriving : 0), 0),
36
- idleTime: deviceTrips.reduce((a, b) => a + (b.endTripData ? b.endTripData.totalTimeInIdle : 0), 0),
37
- drivingConsumption: deviceTrips.reduce((a, b) => a + (b.endTripData ? b.endTripData.totalFuelConsumptionDriving : 0), 0),
38
- idleConsumption: deviceTrips.reduce((a, b) => a + (b.endTripData ? b.endTripData.totalFuelConsumptionInIdle : 0), 0),
39
- drivingDistance: deviceTrips.reduce((a, b) => a + (b.endTripData ? b.endTripData.totalDistanceTravelled : 0), 0),
40
- cruiseControlTime: deviceTrips.reduce((a, b) => a + (b.endTripData ? b.endTripData.totalTimeWithCruiseControl : 0), 0),
41
- cruiseControlConsumption: deviceTrips.reduce((a, b) => a + (b.endTripData ? b.endTripData.totalFuelConsumptionWithCruiseControl : 0), 0),
42
- cruiseControlDistance: deviceTrips.reduce((a, b) => a + (b.endTripData ? b.endTripData.totalDistanceTravelledWithCruiseControl : 0), 0),
43
- economicTime: deviceTrips.reduce((a, b) => a + (b.canDriverStyle ? b.canDriverStyle.totalTimeInEcoRange : 0), 0),
44
- economicConsumption: deviceTrips.reduce((a, b) => a + (b.canDriverStyle ? b.canDriverStyle.totalFuelConsumptionInEcoRange : 0), 0),
45
- economicDistance: deviceTrips.reduce((a, b) => a + (b.canDriverStyle ? b.canDriverStyle.totalDistanceInEcoRange : 0), 0),
46
- highEngineRPM: deviceTrips.reduce((a, b) => a + (b.canDriverStyle ? b.canDriverStyle.totalTimeWithHighRpmAndTorque : 0), 0),
47
- hardBreaking: deviceTrips.reduce((a, b) => a + (b.canDriverStyle ? b.canDriverStyle.totalNumberOfHarshBrakes : 0), 0),
48
- hardAcceleration: deviceTrips.reduce((a, b) => a + (b.canDriverStyle ? b.canDriverStyle.totalNumberOfHarshAccelerations : 0), 0)
30
+ drivingTime: endTripData.reduce((a, b) => a + b.totalTimeDriving, 0),
31
+ idleTime: endTripData.reduce((a, b) => a + b.totalTimeInIdle, 0),
32
+ drivingConsumption: endTripData.reduce((a, b) => a + b.totalFuelConsumptionDriving, 0),
33
+ idleConsumption: endTripData.reduce((a, b) => a + b.totalFuelConsumptionInIdle, 0),
34
+ drivingDistance: endTripData.reduce((a, b) => a + b.totalDistanceTravelled, 0),
35
+ cruiseControlTime: endTripData.reduce((a, b) => a + b.totalTimeWithCruiseControl, 0),
36
+ cruiseControlConsumption: endTripData.reduce((a, b) => a + b.totalFuelConsumptionWithCruiseControl, 0),
37
+ cruiseControlDistance: endTripData.reduce((a, b) => a + b.totalDistanceTravelledWithCruiseControl, 0),
38
+ economicTime: canDriverStyle.reduce((a, b) => a + b.totalTimeInEcoRange, 0),
39
+ economicConsumption: canDriverStyle.reduce((a, b) => a + b.totalFuelConsumptionInEcoRange, 0),
40
+ economicDistance: canDriverStyle.reduce((a, b) => a + b.totalDistanceInEcoRange, 0),
41
+ highEngineRPM: canDriverStyle.reduce((a, b) => a + b.totalTimeWithHighRpmAndTorque, 0),
42
+ hardBreaking: canDriverStyle.reduce((a, b) => a + b.totalNumberOfHarshBrakes, 0),
43
+ hardAcceleration: canDriverStyle.reduce((a, b) => a + b.totalNumberOfHarshAccelerations, 0)
49
44
  }
50
45
  reportData.push(deviceData)
51
46
  })
@@ -2,7 +2,6 @@ const { getReports } = require('./index')
2
2
  const { createPerformanceReport } = require('../partnerReports/performance-report')
3
3
  // eslint-disable-next-line no-undef
4
4
  describe('performance', function () {
5
- this.timeout(500000)
6
5
  // eslint-disable-next-line no-undef
7
6
  it('performance report', async () => {
8
7
  const report = await getReports()
@@ -2,7 +2,6 @@ const { getReports } = require('./index')
2
2
  const assert = require('assert')
3
3
  // eslint-disable-next-line no-undef
4
4
  describe('zones', function () {
5
- this.timeout(500000)
6
5
  // eslint-disable-next-line no-undef
7
6
  it('works with ellca', async () => {
8
7
  const report = await getReports()
@@ -48,25 +47,4 @@ describe('zones', function () {
48
47
  assert.equal(first.inTime.fixTime, '2023-01-03T21:23:24.000+0000')
49
48
  assert.equal(first.outTime.fixTime, '2023-01-07T12:22:53.000+0000')
50
49
  }, 4000000)
51
-
52
- // eslint-disable-next-line no-undef
53
- it('works with casais 2', async () => {
54
- const report = await getReports('mario.andre.moreira@casais.gi', 'Casais.23')
55
- const userData = await report.getUserData()
56
- userData.groupByDay = true
57
- userData.devices = userData.devices.filter(d => d.name === 'G-2542-F Fiat Tipo')
58
- userData.geofences = userData.geofences.filter(g => g.name === 'baliza raio verde ')
59
- assert.equal(userData.geofences.length > 0, true)
60
- assert.equal(userData.devices.length > 0, true)
61
- const result = await report.zoneReport(
62
- new Date(2023, 1, 27, 0, 0, 0, 0),
63
- new Date(2023, 1, 27, 23, 59, 59, 0),
64
- userData)
65
- assert.equal(result[0].devices[0].geofences.length, 1)
66
- assert.equal(result[0].devices[0].geofences[0].days.length, 1)
67
- const first = result[0].devices[0].geofences[0].days[0]
68
- assert.equal(first.firstIn, '2023-02-27T21:53:16.000+0000')
69
- assert.equal(first.distanceIn, 93.03917199839687)
70
- assert.equal(first.distanceOut, 819.6685737216337)
71
- }, 4000000)
72
50
  })
package/src/util/xpert.js CHANGED
@@ -42,23 +42,21 @@ function parseCanDriverStyleMessage (xpertMessage) {
42
42
  }
43
43
  }
44
44
 
45
- function getEndTripMessage (trip, route) {
46
- const p = route.find(p => new Date(p.fixTime).getTime() > new Date(trip.endTime).getTime() &&
47
- p.attributes.xpert &&
45
+ function getEndTripMessages (route) {
46
+ const positions = route.filter(p => p.attributes.xpert &&
48
47
  (Array.isArray(p.attributes.xpert) ? p.attributes.xpert.find(x => x.type === '3') : p.attributes.xpert.split(';').find(m => m.startsWith('3'))))
49
48
 
50
- return p && (Array.isArray(p.attributes.xpert) ? p.attributes.xpert.find(x => x.type === '3') : p.attributes.xpert.split(';').find(m => m.startsWith('3')))
49
+ return positions.map(p => (Array.isArray(p.attributes.xpert) ? p.attributes.xpert.find(x => x.type === '3') : p.attributes.xpert.split(';').find(m => m.startsWith('3'))))
51
50
  }
52
51
 
53
- function getCanDriverStyleMessage (trip, route) {
54
- const p = route.find(p => new Date(p.fixTime).getTime() > new Date(trip.endTime).getTime() &&
55
- p.attributes.xpert &&
52
+ function getCanDriverStyleMessages (route) {
53
+ const positions = route.filter(p => p.attributes.xpert &&
56
54
  (Array.isArray(p.attributes.xpert) ? p.attributes.xpert.find(x => x.type === '4') : p.attributes.xpert.split(';').find(m => m.startsWith('4'))))
57
55
 
58
- return p && (Array.isArray(p.attributes.xpert) ? p.attributes.xpert.find(x => x.type === '4') : p.attributes.xpert.split(';').find(m => m.startsWith('4')))
56
+ return positions.map(p => (Array.isArray(p.attributes.xpert) ? p.attributes.xpert.find(x => x.type === '4') : p.attributes.xpert.split(';').find(m => m.startsWith('4'))))
59
57
  }
60
58
 
61
59
  exports.parseEndTripMessage = parseEndTripMessage
62
- exports.getEndTripMessage = getEndTripMessage
60
+ exports.getEndTripMessages = getEndTripMessages
63
61
  exports.parseCanDriverStyleMessage = parseCanDriverStyleMessage
64
- exports.getCanDriverStyleMessage = getCanDriverStyleMessage
62
+ exports.getCanDriverStyleMessages = getCanDriverStyleMessages