fleetmap-reports 1.0.767 → 1.0.769

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.767",
3
+ "version": "1.0.769",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -25,20 +25,6 @@ function fuelSignalInverter (device) {
25
25
  return device.attributes.fuel_low_threshold <= device.attributes.fuel_high_threshold ? 1 : -1
26
26
  }
27
27
 
28
- function calculateXpertSpentFuel (date, positions) {
29
- const begin = moment(date, 'YYYY-MM-DD').startOf('day')
30
- const end = moment(date, 'YYYY-MM-DD').endOf('day')
31
- const datePositions = positions.filter(p => moment(p.fixTime).isAfter(begin) && moment(p.fixTime).isBefore(end))
32
- const xpertMessages = datePositions.map(p => p.attributes.xpert).flat().filter(p => p)
33
- const xpertEndTripMessage = xpertMessages.filter(x => x.type === '3')
34
- if (xpertEndTripMessage.length > 1) {
35
- const diff = xpertEndTripMessage[xpertEndTripMessage.length - 1].total_fuel - xpertEndTripMessage[0].total_fuel
36
- console.log('Diff:', diff)
37
- return Math.round(diff)
38
- }
39
- return 0
40
- }
41
-
42
28
  function calculateXpertDistance (date, positions) {
43
29
  const begin = moment(date, 'YYYY-MM-DD').startOf('day')
44
30
  const end = moment(date, 'YYYY-MM-DD').endOf('day')
@@ -48,11 +34,9 @@ function calculateXpertDistance (date, positions) {
48
34
  }
49
35
 
50
36
  function calculateSpentFuel (value, device) {
51
- if (!value) { return value }
37
+ if (!value || device.attributes.xpert) { return value }
52
38
 
53
- if (device.attributes.xpert) {
54
- return Math.round((value * device.attributes.fuel_tank_capacity) / 100)
55
- } else if (device.attributes.fuel_low_threshold && device.attributes.fuel_high_threshold) {
39
+ if (device.attributes.fuel_low_threshold && device.attributes.fuel_high_threshold) {
56
40
  const valueSignalCheck = value * fuelSignalInverter(device)
57
41
  const valuePercentage = (valueSignalCheck * 100) / Math.abs(device.attributes.fuel_low_threshold - device.attributes.fuel_high_threshold)
58
42
  return Math.round((valuePercentage * device.attributes.fuel_tank_capacity) / 100)
@@ -63,6 +47,5 @@ function calculateSpentFuel (value, device) {
63
47
  exports.sliceArray = sliceArray
64
48
  exports.deviceWithFuelInfo = deviceWithFuelInfo
65
49
  exports.calculateSpentFuel = calculateSpentFuel
66
- exports.calculateXpertSpentFuel = calculateXpertSpentFuel
67
50
  exports.calculateXpertDistance = calculateXpertDistance
68
51
  exports.maxParallelRequests = maxParallelRequests
@@ -121,9 +121,6 @@ function calculateAvgConsumption (fuel, distance) {
121
121
  }
122
122
 
123
123
  function calculateConsumption (userData, d, day, avgConsumption, data) {
124
- if (d.attributes.xpert) {
125
- return automaticReports.calculateXpertSpentFuel(day, data.route)
126
- }
127
124
  if (useOdooFuelData(d, data.route)) {
128
125
  return (avgConsumption.byKms * (data.trips.reduce((a, b) => a + b.distance, 0) / 1000) / 100)
129
126
  }
@@ -15,24 +15,28 @@ async function createPerformanceReport (from, to, userData, traccar) {
15
15
  const allInOne = await traccarHelper.getAllInOne(traccar, from, to, slice, true, true, false, false, deviceCount, devices.length)
16
16
 
17
17
  slice.forEach(d => {
18
- const { endTripData, canDriverStyle } = getDeviceXpertData(allInOne, d)
18
+ const {
19
+ drivingTime, idleTime, cruiseControlTime, economicTime, highEngineRPM, hardBreaking, hardAcceleration,
20
+ drivingConsumption, idleConsumption, cruiseControlConsumption, economicConsumption, drivingDistance, cruiseControlDistance,
21
+ economicDistance
22
+ } = getDeviceData(allInOne, d)
19
23
 
20
24
  const deviceData = {
21
25
  device: d.name,
22
- drivingTime: endTripData.length > 1 ? endTripData[endTripData.length - 1].totalTimeDriving - endTripData[0].totalTimeDriving : 0,
23
- idleTime: endTripData.length > 1 ? endTripData[endTripData.length - 1].totalTimeInIdle - endTripData[0].totalTimeInIdle : 0,
24
- drivingConsumption: endTripData.length > 1 ? endTripData[endTripData.length - 1].totalFuelConsumptionDriving - endTripData[0].totalFuelConsumptionDriving : 0,
25
- idleConsumption: endTripData.length > 1 ? endTripData[endTripData.length - 1].totalFuelConsumptionInIdle - endTripData[0].totalFuelConsumptionInIdle : 0,
26
- drivingDistance: endTripData.length > 1 ? endTripData[endTripData.length - 1].totalDistanceTravelled - endTripData[0].totalDistanceTravelled : 0,
27
- cruiseControlTime: endTripData.length > 1 ? endTripData[endTripData.length - 1].totalTimeWithCruiseControl - endTripData[0].totalTimeWithCruiseControl : 0,
28
- cruiseControlConsumption: endTripData.length > 1 ? endTripData[endTripData.length - 1].totalFuelConsumptionWithCruiseControl - endTripData[0].totalFuelConsumptionWithCruiseControl : 0,
29
- cruiseControlDistance: endTripData.length > 1 ? endTripData[endTripData.length - 1].totalDistanceTravelledWithCruiseControl - endTripData[0].totalDistanceTravelledWithCruiseControl : 0,
30
- economicTime: canDriverStyle.length > 1 ? canDriverStyle[canDriverStyle.length - 1].totalTimeInEcoRange - canDriverStyle[0].totalTimeInEcoRange : 0,
31
- economicConsumption: canDriverStyle.length > 1 ? canDriverStyle[canDriverStyle.length - 1].totalFuelConsumptionInEcoRange - canDriverStyle[0].totalFuelConsumptionInEcoRange : 0,
32
- economicDistance: canDriverStyle.length > 1 ? canDriverStyle[canDriverStyle.length - 1].totalDistanceInEcoRange - canDriverStyle[0].totalDistanceInEcoRange : 0,
33
- highEngineRPM: canDriverStyle.length > 1 ? canDriverStyle[canDriverStyle.length - 1].totalTimeWithHighRpmAndTorque - canDriverStyle[0].totalTimeWithHighRpmAndTorque : 0,
34
- hardBreaking: canDriverStyle.length > 1 ? canDriverStyle[canDriverStyle.length - 1].totalNumberOfHarshBrakes - canDriverStyle[0].totalNumberOfHarshBrakes : 0,
35
- hardAcceleration: canDriverStyle.length > 1 ? canDriverStyle[canDriverStyle.length - 1].totalNumberOfHarshAccelerations - canDriverStyle[0].totalNumberOfHarshAccelerations : 0
26
+ drivingTime,
27
+ idleTime,
28
+ drivingConsumption,
29
+ idleConsumption,
30
+ drivingDistance,
31
+ cruiseControlTime,
32
+ cruiseControlConsumption,
33
+ cruiseControlDistance,
34
+ economicTime,
35
+ economicConsumption,
36
+ economicDistance,
37
+ highEngineRPM,
38
+ hardBreaking,
39
+ hardAcceleration
36
40
  }
37
41
  reportData.push(deviceData)
38
42
  })
@@ -43,39 +47,43 @@ async function createPerformanceReport (from, to, userData, traccar) {
43
47
  const allInOne = await traccarHelper.getAllInOne(traccar, from, to, userData.devices, true, true, false, false)
44
48
 
45
49
  const device = userData.devices[0]
46
- const { endTripData, canDriverStyle } = getDeviceXpertData(allInOne, device)
47
50
 
48
- const drivingTime = endTripData.length > 1 ? endTripData[endTripData.length - 1].totalTimeDriving - endTripData[0].totalTimeDriving : 0
49
- const idleTime = endTripData.length > 1 ? endTripData[endTripData.length - 1].totalTimeInIdle - endTripData[0].totalTimeInIdle : 0
50
- const cruiseControlTime = endTripData.length > 1 ? endTripData[endTripData.length - 1].totalTimeWithCruiseControl - endTripData[0].totalTimeWithCruiseControl : 0
51
- const economicTime = canDriverStyle.length > 1 ? canDriverStyle[canDriverStyle.length - 1].totalTimeInEcoRange - canDriverStyle[0].totalTimeInEcoRange : 0
52
- const highEngineRPM = canDriverStyle.length > 1 ? canDriverStyle[canDriverStyle.length - 1].totalTimeWithHighRpmAndTorque - canDriverStyle[0].totalTimeWithHighRpmAndTorque : 0
53
- const hardBreaking = canDriverStyle.length > 1 ? canDriverStyle[canDriverStyle.length - 1].totalNumberOfHarshBrakes - canDriverStyle[0].totalNumberOfHarshBrakes : 0
54
- const hardAcceleration = canDriverStyle.length > 1 ? canDriverStyle[canDriverStyle.length - 1].totalNumberOfHarshAccelerations - canDriverStyle[0].totalNumberOfHarshAccelerations : 0
55
-
56
- const drivingConsumption = endTripData.length > 1 ? endTripData[endTripData.length - 1].totalFuelConsumptionDriving - endTripData[0].totalFuelConsumptionDriving : 0
57
- const idleConsumption = endTripData.length > 1 ? endTripData[endTripData.length - 1].totalFuelConsumptionInIdle - endTripData[0].totalFuelConsumptionInIdle : 0
58
- const cruiseControlConsumption = endTripData.length > 1 ? endTripData[endTripData.length - 1].totalFuelConsumptionWithCruiseControl - endTripData[0].totalFuelConsumptionWithCruiseControl : 0
59
- const economicConsumption = canDriverStyle.length > 1 ? canDriverStyle[canDriverStyle.length - 1].totalFuelConsumptionInEcoRange - canDriverStyle[0].totalFuelConsumptionInEcoRange : 0
60
-
61
- const drivingDistance = endTripData.length > 1 ? endTripData[endTripData.length - 1].totalDistanceTravelled - endTripData[0].totalDistanceTravelled : 0
62
- const cruiseControlDistance = endTripData.length > 1 ? endTripData[endTripData.length - 1].totalDistanceTravelledWithCruiseControl - endTripData[0].totalDistanceTravelledWithCruiseControl : 0
63
- const economicDistance = canDriverStyle.length > 1 ? canDriverStyle[canDriverStyle.length - 1].totalDistanceInEcoRange - canDriverStyle[0].totalDistanceInEcoRange : 0
51
+ const {
52
+ drivingTime, idleTime, cruiseControlTime, economicTime, highEngineRPM, hardBreaking, hardAcceleration,
53
+ drivingConsumption, idleConsumption, cruiseControlConsumption, economicConsumption, drivingDistance, cruiseControlDistance,
54
+ economicDistance
55
+ } = getDeviceData(allInOne, device)
64
56
 
65
57
  const totalTime = drivingTime + idleTime
66
58
  const totalConsumption = drivingConsumption + idleConsumption
67
59
 
68
- const totalData = getRowData(1, device, 'Totale', totalTime, totalConsumption, drivingDistance, (drivingDistance > 0 ? (totalConsumption * 0.1) * 100 / drivingDistance : 0).toFixed(1) + ' L/100')
69
- const drivingData = getRowData(2, device, 'Conduite', drivingTime, drivingConsumption, drivingDistance, (drivingDistance > 0 ? (drivingConsumption * 0.1) * 100 / drivingDistance : 0).toFixed(1) + ' L/100')
70
- const idleData = getRowData(3, device, 'Ralenti', idleTime, idleConsumption, '', (totalConsumption > 0 ? idleConsumption * 100 / totalConsumption : 0) + ' %')
71
- const economicData = getRowData(4, device, 'Économique', economicTime, economicConsumption, economicDistance, totalTime > 0 ? economicTime * 100 / totalTime : 0)
72
- const cruiseControlData = getRowData(5, device, 'Cruise Control', cruiseControlTime, cruiseControlConsumption, cruiseControlDistance, totalTime > 0 ? cruiseControlTime * 100 / totalTime : 0)
73
- const highEngineRPMData = getRowData(6, device, 'Tour moteur élevé', highEngineRPM, '', '', totalTime > 0 ? highEngineRPM * 100 / totalTime : 0)
74
- const hardBreakingData = getRowData(7, device, 'Freinage brusque', hardBreaking, '', '', drivingDistance > 0 ? hardBreaking * 100 / drivingDistance : 0)
75
- const hardAccelerationData = getRowData(8, device, 'Accéleration brusque', hardAcceleration, '', '', drivingDistance > 0 ? hardAcceleration * 100 / drivingDistance : 0)
76
-
77
- drivingData.used = (totalTime > 0 ? drivingTime * 100 / totalTime : 0).toFixed(0)
78
- idleData.used = (totalTime > 0 ? idleTime * 100 / totalTime : 0).toFixed(0)
60
+ const totalIndicator = (drivingDistance > 0 ? (totalConsumption * 0.1) * 100 / drivingDistance : 0).toFixed(1) + ' L/100'
61
+ const drivingIndicator = (drivingDistance > 0 ? (drivingConsumption * 0.1) * 100 / drivingDistance : 0).toFixed(1) + ' L/100'
62
+ const idleIndicator = (totalConsumption > 0 ? idleConsumption * 100 / totalConsumption : 0).toFixed(1) + ' %'
63
+ const economicIndicator = (totalTime > 0 ? economicTime * 100 / totalTime : 0).toFixed(1) + ' %'
64
+ const cruiseControlIndicator = (totalTime > 0 ? cruiseControlTime * 100 / totalTime : 0).toFixed(1) + ' %'
65
+ const highEngineRPMIndicator = (totalTime > 0 ? highEngineRPM * 100 / totalTime : 0).toFixed(1) + ' %'
66
+ const hardBreakingIndicator = (drivingDistance > 0 ? hardBreaking * 100 / drivingDistance : 0).toFixed(0) + ' Freinage/100 Km'
67
+ const hardAccelerationIndicator = (drivingDistance > 0 ? hardAcceleration * 100 / drivingDistance : 0).toFixed(0) + ' Accélération/100 Km'
68
+
69
+ const drivingUse = Math.round(totalTime > 0 ? drivingTime * 100 / totalTime : 0)
70
+ const idleUse = Math.round(totalTime > 0 ? idleTime * 100 / totalTime : 0)
71
+
72
+ const engineEconomicRPM = Math.round(totalTime > 0 ? economicTime * 100 / totalTime : 0)
73
+ const engineHighRPM = Math.round(totalTime > 0 ? highEngineRPM * 100 / totalTime : 0)
74
+ const engineOtherRPM = 100 - (engineEconomicRPM + engineHighRPM)
75
+
76
+ const cruiseControlOn = Math.round(totalTime > 0 ? cruiseControlTime * 100 / totalTime : 0)
77
+ const cruiseControlOff = 100 - cruiseControlOn
78
+
79
+ const totalData = getRowData(1, device, 'Totale', totalTime, totalConsumption, drivingDistance, totalIndicator, 0, 0, 0)
80
+ const drivingData = getRowData(2, device, 'Conduite', drivingTime, drivingConsumption, drivingDistance, drivingIndicator, drivingUse, engineOtherRPM, cruiseControlOff)
81
+ const idleData = getRowData(3, device, 'Ralenti', idleTime, idleConsumption, '', idleIndicator, idleUse, 0, 0)
82
+ const economicData = getRowData(4, device, 'Économique', economicTime, economicConsumption, economicDistance, economicIndicator, 0, engineEconomicRPM, 0)
83
+ const cruiseControlData = getRowData(5, device, 'Cruise Control', cruiseControlTime, cruiseControlConsumption, cruiseControlDistance, cruiseControlIndicator, 0, 0, cruiseControlOn)
84
+ const highEngineRPMData = getRowData(6, device, 'Tour moteur élevé', highEngineRPM, '', '', highEngineRPMIndicator, 0, engineHighRPM, 0)
85
+ const hardBreakingData = getRowData(7, device, 'Freinage brusque', hardBreaking, '', '', hardBreakingIndicator, 0, 0, 0)
86
+ const hardAccelerationData = getRowData(8, device, 'Accéleration brusque', hardAcceleration, '', '', hardAccelerationIndicator, 0, 0, 0)
79
87
 
80
88
  reportData.push(totalData)
81
89
  reportData.push(drivingData)
@@ -89,7 +97,7 @@ async function createPerformanceReport (from, to, userData, traccar) {
89
97
  return reportData
90
98
  }
91
99
 
92
- function getDeviceXpertData (allInOne, d) {
100
+ function getDeviceData (allInOne, d) {
93
101
  const deviceRoute = allInOne.route.filter(t => t.deviceId === d.id)
94
102
  const deviceTrips = allInOne.trips.filter(t => t.deviceId === d.id)
95
103
 
@@ -98,12 +106,65 @@ function getDeviceXpertData (allInOne, d) {
98
106
  deviceTrips.push(uncompletedTrip)
99
107
  }
100
108
 
101
- const endTripData = getEndTripMessages(deviceRoute).map(m => parseEndTripMessage(m.xpertString || m)).sort((a, b) => a.date.localeCompare(b.date))
102
- const canDriverStyle = getCanDriverStyleMessages(deviceRoute).map(m => parseCanDriverStyleMessage(m.xpertString || m)).sort((a, b) => a.date.localeCompare(b.date))
103
- return { endTripData, canDriverStyle }
109
+ if (deviceRoute.find(p => p.attributes.xpert)) {
110
+ // Inofleet unit with xpert data
111
+ const endTripData = getEndTripMessages(deviceRoute).map(m => parseEndTripMessage(m.xpertString || m)).sort((a, b) => a.date.localeCompare(b.date))
112
+ const canDriverStyle = getCanDriverStyleMessages(deviceRoute).map(m => parseCanDriverStyleMessage(m.xpertString || m)).sort((a, b) => a.date.localeCompare(b.date))
113
+
114
+ const drivingTime = endTripData.length > 1 ? endTripData[endTripData.length - 1].totalTimeDriving - endTripData[0].totalTimeDriving : 0
115
+ const idleTime = endTripData.length > 1 ? endTripData[endTripData.length - 1].totalTimeInIdle - endTripData[0].totalTimeInIdle : 0
116
+ const cruiseControlTime = endTripData.length > 1 ? endTripData[endTripData.length - 1].totalTimeWithCruiseControl - endTripData[0].totalTimeWithCruiseControl : 0
117
+ const economicTime = canDriverStyle.length > 1 ? canDriverStyle[canDriverStyle.length - 1].totalTimeInEcoRange - canDriverStyle[0].totalTimeInEcoRange : 0
118
+ const highEngineRPM = canDriverStyle.length > 1 ? canDriverStyle[canDriverStyle.length - 1].totalTimeWithHighRpmAndTorque - canDriverStyle[0].totalTimeWithHighRpmAndTorque : 0
119
+ const hardBreaking = canDriverStyle.length > 1 ? canDriverStyle[canDriverStyle.length - 1].totalNumberOfHarshBrakes - canDriverStyle[0].totalNumberOfHarshBrakes : 0
120
+ const hardAcceleration = canDriverStyle.length > 1 ? canDriverStyle[canDriverStyle.length - 1].totalNumberOfHarshAccelerations - canDriverStyle[0].totalNumberOfHarshAccelerations : 0
121
+
122
+ const drivingConsumption = endTripData.length > 1 ? endTripData[endTripData.length - 1].totalFuelConsumptionDriving - endTripData[0].totalFuelConsumptionDriving : 0
123
+ const idleConsumption = endTripData.length > 1 ? endTripData[endTripData.length - 1].totalFuelConsumptionInIdle - endTripData[0].totalFuelConsumptionInIdle : 0
124
+ const cruiseControlConsumption = endTripData.length > 1 ? endTripData[endTripData.length - 1].totalFuelConsumptionWithCruiseControl - endTripData[0].totalFuelConsumptionWithCruiseControl : 0
125
+ const economicConsumption = canDriverStyle.length > 1 ? canDriverStyle[canDriverStyle.length - 1].totalFuelConsumptionInEcoRange - canDriverStyle[0].totalFuelConsumptionInEcoRange : 0
126
+
127
+ const drivingDistance = endTripData.length > 1 ? endTripData[endTripData.length - 1].totalDistanceTravelled - endTripData[0].totalDistanceTravelled : 0
128
+ const cruiseControlDistance = endTripData.length > 1 ? endTripData[endTripData.length - 1].totalDistanceTravelledWithCruiseControl - endTripData[0].totalDistanceTravelledWithCruiseControl : 0
129
+ const economicDistance = canDriverStyle.length > 1 ? canDriverStyle[canDriverStyle.length - 1].totalDistanceInEcoRange - canDriverStyle[0].totalDistanceInEcoRange : 0
130
+
131
+ return {
132
+ drivingTime,
133
+ idleTime,
134
+ cruiseControlTime,
135
+ economicTime,
136
+ highEngineRPM,
137
+ hardBreaking,
138
+ hardAcceleration,
139
+ drivingConsumption,
140
+ idleConsumption,
141
+ cruiseControlConsumption,
142
+ economicConsumption,
143
+ drivingDistance,
144
+ cruiseControlDistance,
145
+ economicDistance
146
+ }
147
+ } else {
148
+ return {
149
+ drivingTime: 0,
150
+ idleTime: 0,
151
+ cruiseControlTime: 0,
152
+ economicTime: 0,
153
+ highEngineRPM: 0,
154
+ hardBreaking: 0,
155
+ hardAcceleration: 0,
156
+ drivingConsumption: 0,
157
+ idleConsumption: 0,
158
+ cruiseControlConsumption: 0,
159
+ economicConsumption: 0,
160
+ drivingDistance: 0,
161
+ cruiseControlDistance: 0,
162
+ economicDistance: 0
163
+ }
164
+ }
104
165
  }
105
166
 
106
- function getRowData (index, device, description, time, consumption, distance, indicator) {
167
+ function getRowData (index, device, description, time, consumption, distance, indicator, use, rpm, cruiseControl) {
107
168
  return {
108
169
  index,
109
170
  device: device.name,
@@ -111,7 +172,10 @@ function getRowData (index, device, description, time, consumption, distance, in
111
172
  time,
112
173
  consumption,
113
174
  distance,
114
- indicator
175
+ indicator,
176
+ use,
177
+ rpm,
178
+ cruiseControl
115
179
  }
116
180
  }
117
181
 
@@ -45,4 +45,17 @@ describe('activity report', function () {
45
45
  assert.equal(device.summary[5].startTime, 0)
46
46
  assert.equal(device.summary[5].endTime, 0)
47
47
  }, 90000)
48
+ // eslint-disable-next-line no-undef
49
+ it('Activity check fuel consumption', async () => {
50
+ const report = await getReports()
51
+ const userData = await report.getUserData()
52
+ userData.devices = userData.devices.filter(d => d.id === 69114)
53
+ const data = await report.activityReport(new Date(2023, 5, 11, 0, 0, 0, 0),
54
+ new Date(2023, 6, 11, 23, 59, 59, 0),
55
+ userData)
56
+ assert.equal(data.length, 1)
57
+ const device = data[0].devices.find(d => d.device.id === 69114)
58
+ console.log(device)
59
+ assert.equal(device.summary[0].convertedSpentFuel, 168.6)
60
+ }, 800000)
48
61
  })
@@ -23,114 +23,6 @@ describe('Test_Reports', function () {
23
23
  console.log(utils.convertToLocaleString(new Date(), 'es-CL', 'Europe/Madrid'))
24
24
  })
25
25
 
26
- // eslint-disable-next-line no-undef
27
- it('Trip by device', async () => {
28
- const report = await getReports()
29
- const userData = await report.getUserData()
30
-
31
- const data = await report.tripReport(new Date(2022, 0, 3, 0, 0, 0, 0),
32
- new Date(2022, 0, 4, 23, 59, 59, 0),
33
- userData)
34
-
35
- assert.equal(data.length, 1)
36
- const device = data[0].devices.find(d => d.device.id === 22326)
37
- assert.equal(device.trips.length, 7) // Total Trips
38
- assert.equal(device.trips[0].endPOIName, 'Casa João')
39
- assert.equal(device.trips[0].idleTime, 602000)
40
- assert.equal(device.trips[1].endPOIName, undefined)
41
- assert.equal(device.totalDistance, 339170.3099999875) // Total Kms
42
- }, 30000)
43
- // eslint-disable-next-line no-undef
44
- it('Trip by driver', async () => {
45
- const report = await getReports()
46
- const userData = await report.getUserData()
47
- userData.byDriver = true
48
- const data = await report.tripReport(new Date(2022, 1, 1, 0, 0, 0, 0),
49
- new Date(2022, 1, 10, 23, 59, 59, 0),
50
- userData)
51
- assert.equal(data.length, 1)
52
- console.log(data[0].drivers)
53
- const driver = data[0].drivers.find(d => d.driver.id === 14020)
54
- assert.equal(driver.trips.length, 13) // Total Trips
55
- assert.equal(driver.totalDuration, 8159000)
56
- assert.equal(driver.maxSpeed, 78.8337)
57
- }, 90000)
58
- // eslint-disable-next-line no-undef
59
- it('Trip without addresses', async () => {
60
- const report = await getReports()
61
- const userData = await report.getUserData()
62
-
63
- const data = await report.tripReport(new Date(2022, 4, 27, 0, 0, 0, 0),
64
- new Date(2022, 4, 27, 23, 59, 59, 0),
65
- userData)
66
-
67
- assert.equal(data.length, 1)
68
- const device = data[0].devices.find(d => d.device.id === 25808)
69
- assert.equal(device.trips.length, 12) // Total Trips
70
- console.log(device.trips[0])
71
- // assert.equal(device.trips[0].endAddress, 'RS-409, 184-314 - Centro, Vera Cruz - RS, 96880-000, Brazil')
72
- assert.equal(device.trips[1].endPOIName, undefined)
73
- }, 20000)
74
- // eslint-disable-next-line no-undef
75
- it('Trip by device with time period ', async () => {
76
- const report = await getReports()
77
- const userData = await report.getUserData()
78
-
79
- userData.allWeek = false
80
- userData.weekDays = {
81
- sunday: true,
82
- monday: true,
83
- tuesday: true,
84
- wednesday: true,
85
- thursday: true,
86
- friday: true,
87
- saturday: true
88
- }
89
- userData.dayHours = {
90
- startTime: '15:00',
91
- endTime: '19:00'
92
- }
93
-
94
- const data = await report.tripReport(
95
- new Date(Date.UTC(2022, 0, 3, 0, 0, 0, 0)),
96
- new Date(Date.UTC(2022, 0, 4, 23, 59, 59, 0)),
97
- userData)
98
-
99
- assert.equal(data.length, 1)
100
- // const device = data[0].devices.find(d => d.device.id === 22326)
101
- // assert.equal(device.trips.length, 1) // Total Trips
102
- // assert.equal(device.totalDistance, 172190.92999999225) // Total Kms
103
- }, 20000)
104
- // eslint-disable-next-line no-undef
105
- it('Trip by device with time period 2', async () => {
106
- const report = await getReports()
107
- const userData = await report.getUserData()
108
-
109
- userData.allWeek = false
110
- userData.weekDays = {
111
- sunday: true,
112
- monday: true,
113
- tuesday: true,
114
- wednesday: true,
115
- thursday: true,
116
- friday: true,
117
- saturday: true
118
- }
119
- userData.dayHours = {
120
- startTime: '18:00',
121
- endTime: '09:00'
122
- }
123
-
124
- const data = await report.tripReport(
125
- new Date(Date.UTC(2022, 0, 10, 0, 0, 0, 0)),
126
- new Date(Date.UTC(2022, 0, 14, 23, 59, 59, 0)),
127
- userData)
128
-
129
- assert.equal(data.length, 1)
130
- /* const device = data[0].devices.find(d => d.device.id === 22326)
131
- assert.equal(device.trips.length, 22) // Total Trips
132
- assert.equal(device.totalDistance, 214334.7800000161) // Total Kms */
133
- }, 20000)
134
26
  // eslint-disable-next-line no-undef
135
27
  it('Location by device', async () => {
136
28
  const report = await getReports()
@@ -293,6 +185,19 @@ describe('Test_Reports', function () {
293
185
  assert.equal(device.days.length, 26)
294
186
  }, 30000)
295
187
  // eslint-disable-next-line no-undef
188
+ it('FuelConsumption xpert', async () => {
189
+ const report = await getReports()
190
+ const userData = await report.getUserData()
191
+ userData.devices = userData.devices.filter(d => d.id === 69114)
192
+ const data = await report.fuelConsumptionReport(new Date(2023, 5, 11, 0, 0, 0, 0),
193
+ new Date(2023, 6, 11, 23, 59, 59, 0),
194
+ userData)
195
+ assert.equal(data.length, 1)
196
+ const device = data[0].devices.find(d => d.device.id === 69114)
197
+ console.log(device)
198
+ assert.equal(device.days.reduce((a, b) => a + b.spentFuel, 0), 153.7)
199
+ }, 30000)
200
+ // eslint-disable-next-line no-undef
296
201
  it('Zone Report', async () => {
297
202
  const report = await getReports()
298
203
  const userData = await report.getUserData()
@@ -1,5 +1,6 @@
1
1
  const { getReports } = require('./index')
2
2
  const { createPerformanceReport } = require('../partnerReports/performance-report')
3
+ const assert = require('assert')
3
4
  // eslint-disable-next-line no-undef
4
5
  describe('performance', function () {
5
6
  // eslint-disable-next-line no-undef
@@ -14,4 +15,18 @@ describe('performance', function () {
14
15
  report.traccar)
15
16
  console.log(data)
16
17
  })
18
+
19
+ // eslint-disable-next-line no-undef
20
+ it('performance report 2', async () => {
21
+ const report = await getReports()
22
+ const userData = await report.getUserData()
23
+ userData.devices = userData.devices.filter(d => d.id === 69114)
24
+ const data = await createPerformanceReport(
25
+ new Date(Date.UTC(2023, 5, 11, 0, 0, 0, 0)),
26
+ new Date(Date.UTC(2023, 6, 11, 23, 59, 59, 0)),
27
+ userData,
28
+ report.traccar)
29
+ console.log(data)
30
+ assert.equal(data[0].consumption, 1685.1989999999996)
31
+ }, 8000000)
17
32
  })
@@ -1,5 +1,8 @@
1
1
  const { getReports } = require('./index')
2
+ const assert = require('assert')
3
+ // eslint-disable-next-line no-undef
2
4
  describe('trips', function () {
5
+ // eslint-disable-next-line no-undef
3
6
  it('converts to pdf', async () => {
4
7
  const report = await getReports()
5
8
  const userData = await report.getUserData()
@@ -12,4 +15,126 @@ describe('trips', function () {
12
15
  userData)
13
16
  // await report.tripReportToPDF(userData, data)
14
17
  }, 40000)
18
+ // eslint-disable-next-line no-undef
19
+ it('Trip by device', async () => {
20
+ const report = await getReports()
21
+ const userData = await report.getUserData()
22
+
23
+ const data = await report.tripReport(new Date(2022, 0, 3, 0, 0, 0, 0),
24
+ new Date(2022, 0, 4, 23, 59, 59, 0),
25
+ userData)
26
+
27
+ assert.equal(data.length, 1)
28
+ const device = data[0].devices.find(d => d.device.id === 22326)
29
+ assert.equal(device.trips.length, 7) // Total Trips
30
+ assert.equal(device.trips[0].endPOIName, 'Casa João')
31
+ assert.equal(device.trips[0].idleTime, 602000)
32
+ assert.equal(device.trips[1].endPOIName, undefined)
33
+ assert.equal(device.totalDistance, 339170.3099999875) // Total Kms
34
+ }, 30000)
35
+ // eslint-disable-next-line no-undef
36
+ it('Trip by driver', async () => {
37
+ const report = await getReports()
38
+ const userData = await report.getUserData()
39
+ userData.byDriver = true
40
+ const data = await report.tripReport(new Date(2022, 1, 1, 0, 0, 0, 0),
41
+ new Date(2022, 1, 10, 23, 59, 59, 0),
42
+ userData)
43
+ assert.equal(data.length, 1)
44
+ console.log(data[0].drivers)
45
+ const driver = data[0].drivers.find(d => d.driver.id === 14020)
46
+ assert.equal(driver.trips.length, 13) // Total Trips
47
+ assert.equal(driver.totalDuration, 8159000)
48
+ assert.equal(driver.maxSpeed, 78.8337)
49
+ }, 90000)
50
+ // eslint-disable-next-line no-undef
51
+ it('Trip without addresses', async () => {
52
+ const report = await getReports()
53
+ const userData = await report.getUserData()
54
+
55
+ const data = await report.tripReport(new Date(2022, 4, 27, 0, 0, 0, 0),
56
+ new Date(2022, 4, 27, 23, 59, 59, 0),
57
+ userData)
58
+
59
+ assert.equal(data.length, 1)
60
+ const device = data[0].devices.find(d => d.device.id === 25808)
61
+ assert.equal(device.trips.length, 12) // Total Trips
62
+ console.log(device.trips[0])
63
+ // assert.equal(device.trips[0].endAddress, 'RS-409, 184-314 - Centro, Vera Cruz - RS, 96880-000, Brazil')
64
+ assert.equal(device.trips[1].endPOIName, undefined)
65
+ }, 20000)
66
+ // eslint-disable-next-line no-undef
67
+ it('Trip by device with time period ', async () => {
68
+ const report = await getReports()
69
+ const userData = await report.getUserData()
70
+
71
+ userData.allWeek = false
72
+ userData.weekDays = {
73
+ sunday: true,
74
+ monday: true,
75
+ tuesday: true,
76
+ wednesday: true,
77
+ thursday: true,
78
+ friday: true,
79
+ saturday: true
80
+ }
81
+ userData.dayHours = {
82
+ startTime: '15:00',
83
+ endTime: '19:00'
84
+ }
85
+
86
+ const data = await report.tripReport(
87
+ new Date(Date.UTC(2022, 0, 3, 0, 0, 0, 0)),
88
+ new Date(Date.UTC(2022, 0, 4, 23, 59, 59, 0)),
89
+ userData)
90
+
91
+ assert.equal(data.length, 1)
92
+ // const device = data[0].devices.find(d => d.device.id === 22326)
93
+ // assert.equal(device.trips.length, 1) // Total Trips
94
+ // assert.equal(device.totalDistance, 172190.92999999225) // Total Kms
95
+ }, 20000)
96
+ // eslint-disable-next-line no-undef
97
+ it('Trip by device with time period 2', async () => {
98
+ const report = await getReports()
99
+ const userData = await report.getUserData()
100
+
101
+ userData.allWeek = false
102
+ userData.weekDays = {
103
+ sunday: true,
104
+ monday: true,
105
+ tuesday: true,
106
+ wednesday: true,
107
+ thursday: true,
108
+ friday: true,
109
+ saturday: true
110
+ }
111
+ userData.dayHours = {
112
+ startTime: '18:00',
113
+ endTime: '09:00'
114
+ }
115
+
116
+ const data = await report.tripReport(
117
+ new Date(Date.UTC(2022, 0, 10, 0, 0, 0, 0)),
118
+ new Date(Date.UTC(2022, 0, 14, 23, 59, 59, 0)),
119
+ userData)
120
+
121
+ assert.equal(data.length, 1)
122
+ /* const device = data[0].devices.find(d => d.device.id === 22326)
123
+ assert.equal(device.trips.length, 22) // Total Trips
124
+ assert.equal(device.totalDistance, 214334.7800000161) // Total Kms */
125
+ }, 20000)
126
+
127
+ // eslint-disable-next-line no-undef
128
+ it('Trip fuel consumption', async () => {
129
+ const report = await getReports()
130
+ const userData = await report.getUserData()
131
+ userData.devices = userData.devices.filter(d => d.id === 69114)
132
+ const data = await report.tripReport(new Date(2023, 5, 11, 0, 0, 0, 0),
133
+ new Date(2023, 6, 11, 23, 59, 59, 0),
134
+ userData)
135
+
136
+ assert.equal(data.length, 1)
137
+ const device = data[0].devices.find(d => d.device.id === 69114)
138
+ assert.equal(device.trips.reduce((a, b) => a + b.spentFuel, 0), 153.6999999999998) // Total Trips
139
+ }, 30000)
15
140
  })