fleetmap-reports 1.0.345 → 1.0.348

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.345",
3
+ "version": "1.0.348",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
package/src/index.test.js CHANGED
@@ -119,6 +119,7 @@ describe('Test_Reports', function() {
119
119
  it('KmsReport by device', async () => {
120
120
  const reports = await getReports()
121
121
  const userData = await reports.getUserData()
122
+ userData.devices = userData.devices.filter(d => d.id === 22326)
122
123
  const data = await reports.kmsReport(new Date(2021, 10, 1, 0, 0,0), new Date(2021, 10, 31, 23, 59, 59),
123
124
  userData)
124
125
  assert.equal(data.length, 1)
@@ -129,6 +130,7 @@ describe('Test_Reports', function() {
129
130
  it('KmsReport byDevice groupByDay', async () => {
130
131
  const reports = await getReports()
131
132
  const userData = await reports.getUserData()
133
+ userData.devices = userData.devices.filter(d => d.id === 22326)
132
134
  userData.groupByDay = true
133
135
  const data = await reports.kmsReport(new Date(2021, 10, 1, 0, 0,0), new Date(2021, 10, 10, 23, 59, 59),
134
136
  userData)
@@ -137,7 +139,7 @@ describe('Test_Reports', function() {
137
139
  const device = data[0].devices.find(d => d.device.id===22326)
138
140
  assert.equal(device.days.length, 10) // Total Kms
139
141
  assert.equal(device.days[5].kms, 23183.010000005364) // Total Kms
140
- },90000)
142
+ },30000)
141
143
  it('Idle by device', async () => {
142
144
  const report = await getReports()
143
145
  const userData = await report.getUserData()
@@ -215,4 +217,33 @@ describe('Test_Reports', function() {
215
217
  const device2 = kmsReport[0].devices.find(d => d.device.id===11681)
216
218
  assert.equal(device2.summary.distance, device1.totalDistance) // Total Kms
217
219
  }, 30000)
220
+ it('Refueling Report', async () => {
221
+ const report = await getReports()
222
+ const userData = await report.getUserData()
223
+
224
+ const data = await report.refuelingReport(new Date(2022, 1, 2, 0, 0, 0, 0),
225
+ new Date(2022, 1, 2, 23, 59, 59, 0),
226
+ userData)
227
+
228
+ assert.equal(data.length, 1)
229
+ console.log(data[0])
230
+ const device = data[0].devices.find(d => d.device.id===16245)
231
+ assert.equal(device.refuelings.length, 2)
232
+
233
+ }, 30000)
234
+ it('Refueling2 Report', async () => {
235
+ const report = await getReports()
236
+ const userData = await report.getUserData()
237
+
238
+ const data = await report.refuelingReport(new Date(2022, 1, 21, 0, 0, 0, 0),
239
+ new Date(2022, 1, 25, 23, 59, 59, 0),
240
+ userData)
241
+
242
+ assert.equal(data.length, 1)
243
+ console.log(data[0])
244
+ const device = data[0].devices.find(d => d.device.id===16245)
245
+ console.log(device.refuelings)
246
+ assert.equal(device.refuelings.length, 4)
247
+
248
+ }, 30000)
218
249
  })
@@ -1,6 +1,8 @@
1
1
  const helpers = require("turf");
2
2
  const automaticReports = require("./automaticReports");
3
3
 
4
+ const positionsToCheck = 15
5
+
4
6
  async function createRefuelingReport(from, to, userData, traccar) {
5
7
  console.log('Create RefuelingReport')
6
8
 
@@ -134,10 +136,10 @@ function calculateRefuelingPositions(d, positions) {
134
136
  const value = Math.round(diff * d.attributes.fuel_tank_capacity / 100)
135
137
  refuelingPositions.push({position: element, diff: value})
136
138
  lastRefuelingIndex = index
137
- positionsChecked = 6 // to reset values
139
+ positionsChecked = positionsToCheck+1 // to reset values
138
140
  }
139
141
 
140
- if(positionsChecked > 5) {
142
+ if(positionsChecked > positionsToCheck) {
141
143
  refuelingActivated = false
142
144
  currentValue = null
143
145
  positionsChecked = 0
@@ -68,7 +68,7 @@ async function createSpeedingReportByGroup(from, to, userData, traccarInstance){
68
68
 
69
69
  async function createSpeedingReportByDevice(from, to, userData, traccarInstance) {
70
70
  const groupIds = userData.groups.map(g => g.id)
71
- const devices = userData.devices.filter(d => !groupIds.includes(d.groupId))
71
+ const devices = userData.byGroup ? userData.devices.filter(d => !groupIds.includes(d.groupId)) : userData.devices
72
72
 
73
73
  devices.sort((a, b) => (a.name > b.name) ? 1 : -1)
74
74
 
@@ -238,7 +238,6 @@ async function getHereEvents(devices, routes, threshold){
238
238
  continue
239
239
  }
240
240
  let hereAlerts = null
241
- try {
242
241
  const results = await here.routeMatch(positions)
243
242
  hereAlerts = results.filter(r => r.currentSpeedKmh > (parseInt(r.speedLimit) + threshold)).map(r => {
244
243
  const position = positions.find(p => new Date(p.fixTime).getTime() === r.timestamp)
@@ -265,9 +264,6 @@ async function getHereEvents(devices, routes, threshold){
265
264
  return acc
266
265
  })
267
266
  events.push(...reduced)
268
- } catch (e) {
269
- console.error(hereAlerts, 'threshold', threshold, e)
270
- }
271
267
  }
272
268
  return events
273
269
  }