fleetmap-reports 1.0.768 → 1.0.770

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.768",
3
+ "version": "1.0.770",
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
@@ -55,6 +55,12 @@ async function createFuelConsumptionReport (from, to, userData, traccar) {
55
55
  new Map()
56
56
  )
57
57
 
58
+ route.forEach(p => { p.startDate = p.fixTime.substring(0, 10) })
59
+ const groupedRouteByDay = route.reduce(
60
+ (entryMap, e) => entryMap.set(e.startDate, [...entryMap.get(e.startDate) || [], e]),
61
+ new Map()
62
+ )
63
+
58
64
  const days = []
59
65
  const keys = Array.from(groupedTripsByDay.keys())
60
66
 
@@ -63,7 +69,7 @@ async function createFuelConsumptionReport (from, to, userData, traccar) {
63
69
  const dayTrips = groupedTripsByDay.get(day)
64
70
  const dayRefueling = groupedRefuelingsByDay.get(day)
65
71
  const distance = dayTrips.reduce((a, b) => a + b.distance, 0)
66
- const spentFuel = calculateConsumption(userData, d, day, odooAvgConsumption, { trips: dayTrips, route })
72
+ const spentFuel = calculateConsumption(userData, d, day, odooAvgConsumption, { trips: dayTrips, route: groupedRouteByDay.get(day) })
67
73
 
68
74
  const dataRow = {
69
75
  date: day,
@@ -121,12 +127,14 @@ function calculateAvgConsumption (fuel, distance) {
121
127
  }
122
128
 
123
129
  function calculateConsumption (userData, d, day, avgConsumption, data) {
124
- if (d.attributes.xpert) {
125
- return automaticReports.calculateXpertSpentFuel(day, data.route)
126
- }
127
130
  if (useOdooFuelData(d, data.route)) {
128
131
  return (avgConsumption.byKms * (data.trips.reduce((a, b) => a + b.distance, 0) / 1000) / 100)
129
132
  }
133
+
134
+ if (data.route.length > 1 && data.route[0].attributes.fuelUsed) {
135
+ return data.route[data.route.length - 1].attributes.fuelUsed - data.route[0].attributes.fuelUsed
136
+ }
137
+
130
138
  return automaticReports.calculateSpentFuel(data.trips.reduce((a, b) => a + b.spentFuel, 0), d)
131
139
  }
132
140
 
@@ -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,24 +47,12 @@ 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
@@ -105,7 +97,7 @@ async function createPerformanceReport (from, to, userData, traccar) {
105
97
  return reportData
106
98
  }
107
99
 
108
- function getDeviceXpertData (allInOne, d) {
100
+ function getDeviceData (allInOne, d) {
109
101
  const deviceRoute = allInOne.route.filter(t => t.deviceId === d.id)
110
102
  const deviceTrips = allInOne.trips.filter(t => t.deviceId === d.id)
111
103
 
@@ -114,9 +106,65 @@ function getDeviceXpertData (allInOne, d) {
114
106
  deviceTrips.push(uncompletedTrip)
115
107
  }
116
108
 
117
- const endTripData = getEndTripMessages(deviceRoute).map(m => parseEndTripMessage(m.xpertString || m)).sort((a, b) => a.date.localeCompare(b.date))
118
- const canDriverStyle = getCanDriverStyleMessages(deviceRoute).map(m => parseCanDriverStyleMessage(m.xpertString || m)).sort((a, b) => a.date.localeCompare(b.date))
119
- 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
+ const drivingTime = deviceTrips.reduce((a, b) => a + b.duration, 0)
149
+ const drivingDistance = deviceTrips.reduce((a, b) => a + b.distance, 0)
150
+
151
+ return {
152
+ drivingTime: drivingTime,
153
+ idleTime: 0,
154
+ cruiseControlTime: 0,
155
+ economicTime: 0,
156
+ highEngineRPM: 0,
157
+ hardBreaking: 0,
158
+ hardAcceleration: 0,
159
+ drivingConsumption: 0,
160
+ idleConsumption: 0,
161
+ cruiseControlConsumption: 0,
162
+ economicConsumption: 0,
163
+ drivingDistance: drivingDistance,
164
+ cruiseControlDistance: 0,
165
+ economicDistance: 0
166
+ }
167
+ }
120
168
  }
121
169
 
122
170
  function getRowData (index, device, description, time, consumption, distance, indicator, use, rpm, cruiseControl) {
@@ -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,18 @@ 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
+ assert.equal(device.days.reduce((a, b) => a + b.spentFuel, 0), 168.91999999999985)
198
+ }, 30000)
199
+ // eslint-disable-next-line no-undef
296
200
  it('Zone Report', async () => {
297
201
  const report = await getReports()
298
202
  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
  })