fleetmap-reports 1.0.770 → 1.0.772

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.770",
3
+ "version": "1.0.772",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -15,36 +15,15 @@ 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 {
19
- drivingTime, idleTime, cruiseControlTime, economicTime, highEngineRPM, hardBreaking, hardAcceleration,
20
- drivingConsumption, idleConsumption, cruiseControlConsumption, economicConsumption, drivingDistance, cruiseControlDistance,
21
- economicDistance
22
- } = getDeviceData(allInOne, d)
23
-
24
- const deviceData = {
25
- device: d.name,
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
40
- }
18
+ const deviceData = getDeviceData(allInOne, d)
19
+ deviceData.device = d.name
41
20
  reportData.push(deviceData)
42
21
  })
43
22
 
44
23
  deviceCount = deviceCount + slice.length
45
24
  }
46
25
  } else {
47
- const allInOne = await traccarHelper.getAllInOne(traccar, from, to, userData.devices, true, true, false, false)
26
+ const allInOne = await traccarHelper.getAllInOne(traccar, from, to, userData.devices, true, true, false, true)
48
27
 
49
28
  const device = userData.devices[0]
50
29
 
@@ -145,22 +124,30 @@ function getDeviceData (allInOne, d) {
145
124
  economicDistance
146
125
  }
147
126
  } else {
127
+ const deviceSummary = allInOne.summary.filter(t => t.deviceId === d.id)
128
+
148
129
  const drivingTime = deviceTrips.reduce((a, b) => a + b.duration, 0)
149
- const drivingDistance = deviceTrips.reduce((a, b) => a + b.distance, 0)
130
+ const drivingConsumption = deviceTrips.reverse((a, b) => a + b.spentFuel, 0)
131
+ const drivingDistance = deviceSummary.distanceIn
132
+ const idleTime = deviceSummary.engineHours - drivingTime
133
+ const idleConsumption = deviceSummary.spentFuel - drivingConsumption
134
+
135
+ const hardBreaking = deviceRoute.filter(p => p.attributes.io253 === 2).length
136
+ const hardAcceleration = deviceRoute.filter(p => p.attributes.io253 === 1).length
150
137
 
151
138
  return {
152
- drivingTime: drivingTime,
153
- idleTime: 0,
139
+ drivingTime,
140
+ idleTime,
154
141
  cruiseControlTime: 0,
155
142
  economicTime: 0,
156
143
  highEngineRPM: 0,
157
- hardBreaking: 0,
158
- hardAcceleration: 0,
159
- drivingConsumption: 0,
160
- idleConsumption: 0,
144
+ hardBreaking,
145
+ hardAcceleration,
146
+ drivingConsumption,
147
+ idleConsumption,
161
148
  cruiseControlConsumption: 0,
162
149
  economicConsumption: 0,
163
- drivingDistance: drivingDistance,
150
+ drivingDistance,
164
151
  cruiseControlDistance: 0,
165
152
  economicDistance: 0
166
153
  }
@@ -7,14 +7,14 @@ describe('performance', function () {
7
7
  it('performance report', async () => {
8
8
  const report = await getReports()
9
9
  const userData = await report.getUserData()
10
- userData.devices = userData.devices.filter(d => d.attributes.xpert)
10
+ userData.devices = userData.devices.filter(d => d.id === 22326)
11
11
  const data = await createPerformanceReport(
12
12
  new Date(Date.UTC(2023, 5, 10, 0, 0, 0, 0)),
13
13
  new Date(Date.UTC(2023, 5, 20, 23, 59, 59, 0)),
14
14
  userData,
15
15
  report.traccar)
16
16
  console.log(data)
17
- })
17
+ }, 5000000)
18
18
 
19
19
  // eslint-disable-next-line no-undef
20
20
  it('performance report 2', async () => {
@@ -135,6 +135,6 @@ describe('trips', function () {
135
135
 
136
136
  assert.equal(data.length, 1)
137
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
138
+ assert.equal(device.trips.reduce((a, b) => a + b.fuelConsumption, 0), 167.69999999999987) // Total Trips
139
139
  }, 30000)
140
140
  })
@@ -167,14 +167,14 @@ function processDevices (from, to, devices, data, userData, traccar) {
167
167
  trip.endPOIName = nearestPOIs[0].p.name
168
168
  }
169
169
 
170
+ const stop = getStop(new Date(trip.startTime), stops)
171
+
170
172
  if ((deviceRoute[0].protocol === 'teltonika' && deviceRoute.some(r => r.attributes.fuel)) ||
171
173
  automaticReports.deviceWithFuelInfo(d)) {
172
- trip.fuelConsumption = trip.spentFuel
174
+ trip.fuelConsumption = trip.spentFuel + (stop ? stop.spentFuel : 0)
173
175
  trip.avgFuelConsumption = trip.totalKms > 0 ? trip.fuelConsumption * 100 / trip.totalKms : 0
174
176
  }
175
177
 
176
- const stop = getStop(new Date(trip.startTime), stops)
177
-
178
178
  if (stop && !trip.endTimeIsOut) {
179
179
  trip.stopDuration = calculateStopDuration(stop)
180
180
  trip.stopEngineHours = trip.idleTime + stop.engineHours