fleetmap-reports 2.0.386 → 2.0.387

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": "2.0.386",
3
+ "version": "2.0.387",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -209,7 +209,7 @@ function calculateRPMSections (route, min, max) {
209
209
  let newSection = true
210
210
  route.forEach(p => {
211
211
  const rpm = p.attributes.rpm
212
- if ((!min || rpm > min) && (!max || rpm < max)) {
212
+ if ((min === undefined || rpm > min) && (!max || rpm < max)) {
213
213
  if (newSection) {
214
214
  sections.push([p])
215
215
  } else {
package/src/rpm-report.js CHANGED
@@ -10,7 +10,7 @@ const automaticReports = require('./automaticReports')
10
10
  const { calculateRPMSections } = require('./partnerReports/performance-report')
11
11
 
12
12
  const fileName = 'RPMReport'
13
- const defaultThreshold = 2500
13
+ const defaultThreshold = 0
14
14
 
15
15
  async function createRPMReport (from, to, userData, traccarInstance) {
16
16
  console.log('Create RPMReport', from, to)
@@ -23,6 +23,7 @@ async function createRPMReport (from, to, userData, traccarInstance) {
23
23
  }
24
24
 
25
25
  const dates = getDates(from, to, userData.user.attributes.timezone || getUserPartner(userData.user).timezone)
26
+ const threshold = getThreshold(userData)
26
27
 
27
28
  let deviceCount = 0
28
29
  const sliced = automaticReports.sliceArray(allDevices, 20)
@@ -31,7 +32,7 @@ async function createRPMReport (from, to, userData, traccarInstance) {
31
32
  for (const d of devices) {
32
33
  const deviceRoute = route.filter(p => p.deviceId === d.id && p.attributes.rpm !== undefined)
33
34
  if (deviceRoute.length) {
34
- allData.devices.push(processDevice(d, deviceRoute, dates))
35
+ allData.devices.push(processDevice(d, deviceRoute, dates, threshold))
35
36
  }
36
37
  }
37
38
  deviceCount += devices.length
@@ -40,8 +41,10 @@ async function createRPMReport (from, to, userData, traccarInstance) {
40
41
  return [allData]
41
42
  }
42
43
 
43
- function getThreshold (device) {
44
- return Number(device.attributes.highRPM) || defaultThreshold
44
+ // the report's own threshold (userData.rpmThreshold), independent of the device highRPM attribute used by other reports
45
+ function getThreshold (userData) {
46
+ const threshold = Number(userData.rpmThreshold)
47
+ return userData.rpmThreshold !== undefined && userData.rpmThreshold !== '' && Number.isFinite(threshold) ? threshold : defaultThreshold
45
48
  }
46
49
 
47
50
  function dayKey (date) {
@@ -49,8 +52,7 @@ function dayKey (date) {
49
52
  }
50
53
 
51
54
  // time between consecutive positions that are both above the threshold, attributed to the day of the first one
52
- function processDevice (device, deviceRoute, dates) {
53
- const threshold = getThreshold(device)
55
+ function processDevice (device, deviceRoute, dates, threshold = defaultThreshold) {
54
56
  const days = dates.map(date => ({ date, time: 0 }))
55
57
  calculateRPMSections(deviceRoute, threshold).forEach(section => {
56
58
  for (let i = 1; i < section.length; i++) {
@@ -17,17 +17,28 @@ describe('RPM_Report', function () {
17
17
  position(new Date(2026, 9, 2, 9, 0), 2600),
18
18
  position(new Date(2026, 9, 2, 9, 0, 30), 2600)
19
19
  ]
20
- it('sums time above the default threshold per day', () => {
21
- const result = processDevice({ id: 1, attributes: {} }, route, dates)
20
+ it('sums time above the threshold per day', () => {
21
+ const result = processDevice({ id: 1, attributes: {} }, route, dates, 2500)
22
22
  assert.equal(result.threshold, 2500)
23
23
  assert.equal(result.days[0].time, 3 * 60 * 1000)
24
24
  assert.equal(result.days[1].time, 30 * 1000)
25
25
  assert.equal(result.time, 3 * 60 * 1000 + 30 * 1000)
26
26
  })
27
- it('uses the device highRPM attribute as threshold', () => {
28
- const result = processDevice({ id: 1, attributes: { highRPM: 2650 } }, route, dates)
29
- assert.equal(result.threshold, 2650)
30
- assert.equal(result.days[0].time, 2 * 60 * 1000)
31
- assert.equal(result.days[1].time, 0)
27
+ it('ignores the device highRPM attribute', () => {
28
+ const result = processDevice({ id: 1, attributes: { highRPM: 2650 } }, route, dates, 2500)
29
+ assert.equal(result.threshold, 2500)
30
+ assert.equal(result.days[0].time, 3 * 60 * 1000)
31
+ })
32
+ it('defaults to rpm > 0 (engine running time)', () => {
33
+ const idleRoute = [
34
+ position(new Date(2026, 9, 1, 8, 0), 0),
35
+ position(new Date(2026, 9, 1, 8, 10), 800),
36
+ position(new Date(2026, 9, 1, 8, 20), 2000),
37
+ position(new Date(2026, 9, 1, 8, 30), 0),
38
+ position(new Date(2026, 9, 1, 8, 40), 0)
39
+ ]
40
+ const result = processDevice({ id: 1, attributes: {} }, idleRoute, dates)
41
+ assert.equal(result.threshold, 0)
42
+ assert.equal(result.days[0].time, 10 * 60 * 1000)
32
43
  })
33
44
  })