fleetmap-reports 1.0.777 → 1.0.778

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.777",
3
+ "version": "1.0.778",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -2,6 +2,7 @@ const automaticReports = require('../automaticReports')
2
2
  const traccarHelper = require('../util/traccar')
3
3
  const { getUncompletedTrip } = require('../util/trips')
4
4
  const { getEndTripMessages, getCanDriverStyleMessages, parseEndTripMessage, parseCanDriverStyleMessage } = require('../util/xpert')
5
+ const { calculateDistance } = require('../util/utils')
5
6
 
6
7
  async function createPerformanceReport (from, to, userData, traccar) {
7
8
  const reportData = []
@@ -133,24 +134,40 @@ function getDeviceData (allInOne, d) {
133
134
  const idleTime = deviceTrips.reduce((a, b) => a + b.idleTime, 0) + deviceStops.reduce((a, b) => a + b.engineHours, 0)
134
135
  const idleConsumption = deviceSummary && deviceSummary.spentFuel > drivingConsumption ? deviceSummary.spentFuel - drivingConsumption : 0
135
136
 
136
- const hardBreaking = deviceRoute.filter(p => p.attributes.io253 === 2).length
137
- const hardAcceleration = deviceRoute.filter(p => p.attributes.io253 === 1).length
137
+ const highEngineRPMSections = calculateRPMSections(deviceRoute, d.attributes.highRPM || 1300)
138
+ const highEngineRPM = highEngineRPMSections.map(a => a.length > 1
139
+ ? a.map((p, index) => index === 0 ? 0 : new Date(p.fixTime).getTime() - new Date(a[index - 1].fixTime).getTime()).reduce((a, b) => a + b)
140
+ : 0).reduce((a, b) => a + b, 0)
141
+
142
+ const economicRPMSections = calculateRPMSections(deviceRoute, d.attributes.minEconomicRPM || 1000, d.attributes.maxEconomicRPM || 1250)
143
+ const economicTime = economicRPMSections.map(a => a.length > 1
144
+ ? a.map((p, index) => index === 0 ? 0 : new Date(p.fixTime).getTime() - new Date(a[index - 1].fixTime).getTime()).reduce((a, b) => a + b)
145
+ : 0).reduce((a, b) => a + b, 0)
146
+ const economicDistance = economicRPMSections.map(a => a.length > 1
147
+ ? calculateDistance(a)
148
+ : 0).reduce((a, b) => a + b, 0)
149
+ const economicConsumption = economicRPMSections.map(a => a.length > 1
150
+ ? a[a.length - 1].attributes.fuelUsed - a[0].attributes.fuelUsed
151
+ : 0).reduce((a, b) => a + (b || 0), 0)
152
+
153
+ const hardBreaking = deviceRoute.filter(p => p.attributes.alarm === 'hardBreaking').length
154
+ const hardAcceleration = deviceRoute.filter(p => p.attributes.alarm === 'hardAcceleration').length
138
155
 
139
156
  return {
140
157
  drivingTime: drivingTime / 1000,
141
158
  idleTime: idleTime / 1000,
142
159
  cruiseControlTime: 0,
143
- economicTime: 0,
144
- highEngineRPM: 0,
160
+ economicTime: economicTime / 1000,
161
+ highEngineRPM: highEngineRPM / 1000,
145
162
  hardBreaking,
146
163
  hardAcceleration,
147
164
  drivingConsumption,
148
165
  idleConsumption,
149
166
  cruiseControlConsumption: 0,
150
- economicConsumption: 0,
167
+ economicConsumption,
151
168
  drivingDistance,
152
169
  cruiseControlDistance: 0,
153
- economicDistance: 0
170
+ economicDistance
154
171
  }
155
172
  }
156
173
  }
@@ -170,4 +187,24 @@ function getRowData (index, device, description, time, consumption, distance, in
170
187
  }
171
188
  }
172
189
 
190
+ function calculateRPMSections (route, min, max) {
191
+ const sections = []
192
+ let newSection = true
193
+ route.forEach(p => {
194
+ const rpm = p.attributes.rpm
195
+ if ((!min || rpm > min) && (!max || rpm < max)) {
196
+ if (newSection) {
197
+ sections.push([p])
198
+ } else {
199
+ sections[sections.length - 1].push(p)
200
+ }
201
+ newSection = false
202
+ } else {
203
+ newSection = true
204
+ }
205
+ })
206
+
207
+ return sections
208
+ }
209
+
173
210
  exports.createPerformanceReport = createPerformanceReport
@@ -10,13 +10,14 @@ describe('performance', function () {
10
10
  const userData = await report.getUserData()
11
11
  userData.devices = userData.devices.filter(d => d.id === 22326)
12
12
  const data = await createPerformanceReport(
13
- new Date(Date.UTC(2023, 5, 10, 0, 0, 0, 0)),
14
- new Date(Date.UTC(2023, 5, 20, 23, 59, 59, 0)),
13
+ new Date(Date.UTC(2023, 6, 1, 0, 0, 0, 0)),
14
+ new Date(Date.UTC(2023, 6, 17, 23, 59, 59, 0)),
15
15
  userData,
16
16
  report.traccar)
17
- assert.equal(data[0].consumption, 21.8)
18
- assert.equal(data[0].distance, 381.29861000000005)
19
- assert.equal(convertMS(data[1].time * 1000, false), '10:30')
17
+ console.log(data)
18
+ assert.equal(data[0].consumption, 19.799999999999997)
19
+ assert.equal(data[0].distance, 326.7657)
20
+ assert.equal(convertMS(data[1].time * 1000, false), '08:19')
20
21
  }, 8000000)
21
22
 
22
23
  // eslint-disable-next-line no-undef