fleetmap-reports 1.0.819 → 1.0.821

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.819",
3
+ "version": "1.0.821",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -8,7 +8,6 @@ function sliceArray (longArray, size) {
8
8
  const arrayToSlice = longArray.slice()
9
9
 
10
10
  const arrayOfArrays = []
11
- console.log('slice', arrayToSlice.length, 'in chunks of', size)
12
11
  for (let i = 0; i < arrayToSlice.length; i += size) {
13
12
  arrayOfArrays.push(arrayToSlice.slice(i, i + size))
14
13
  }
@@ -7,10 +7,6 @@ function calculateLastStopTime (stopTime, to, time) {
7
7
  return stopTime + (to.getTime() - new Date(time).getTime())
8
8
  }
9
9
 
10
- function calculateFirstStopTime (stopTime, from, time) {
11
- return stopTime + (new Date(time).getTime() - from.getTime())
12
- }
13
-
14
10
  async function createActivityReport (from, to, userData, traccarInstance) {
15
11
  const unauthorizedGeofences = []
16
12
  const authorizedGeofences = []
@@ -210,13 +210,14 @@ async function processDrivers (from, to, events, routes, userData) {
210
210
 
211
211
  return driversResult
212
212
  }
213
+ const MAX_DEVICE_SPEED = 160
213
214
 
214
215
  function processDevices (from, to, devices, events, routes, userData) {
215
216
  const devicesResult = []
216
217
  findEventsPosition(from, to, devices, events, routes, userData)
217
218
 
218
219
  for (const d of devices) {
219
- const deviceEvents = events.filter(e => e.deviceId === d.id && e.position)
220
+ const deviceEvents = events.filter(e => e.deviceId === d.id && e.position).filter(e => e.position.speed < MAX_DEVICE_SPEED)
220
221
  if (deviceEvents.length > 0) {
221
222
  deviceEvents.sort((a, b) => a.positionId - b.positionId)
222
223
  devicesResult.push({
@@ -7,14 +7,11 @@ describe('activity report', function () {
7
7
  it('Activity by device', async () => {
8
8
  const report = await getReports()
9
9
  const userData = await report.getUserData()
10
-
11
- const data = await report.activityReport(new Date(2022, 0, 1, 0, 0, 0, 0),
12
- new Date(2022, 0, 31, 23, 59, 59, 0),
10
+ userData.groupByDay = true
11
+ const data = await report.activityReport(new Date(2023, 0, 1, 0, 0, 0, 0),
12
+ new Date(2023, 0, 31, 23, 59, 59, 0),
13
13
  userData)
14
14
  assert.equal(data.length, 1)
15
- const device = data[0].devices.find(d => d.device.id === 22326)
16
- assert.equal(device.summary[0].startOdometer, 0)
17
- assert.equal(device.summary[0].distance, 0)
18
15
  assert.equal(device.summary[0].startTime, 0)
19
16
  assert.equal(device.summary[0].endTime, 0)
20
17
  }, 80000)
@@ -72,4 +69,14 @@ describe('activity report', function () {
72
69
  console.log(device)
73
70
  assert.equal(device.summary.reduce((a, b) => a + b.convertedSpentFuel, 0), 168.79999999999995)
74
71
  }, 800000)
72
+ it('Activity test performance', async () => {
73
+ const report = await getReports('q.trans', 'quality1214')
74
+ const userData = await report.getUserData()
75
+ console.log(userData)
76
+ userData.groupByDay = true
77
+ const data = await report.activityReport(new Date(2023, 7, 1, 0, 0, 0, 0),
78
+ new Date(2023, 31, 5, 23, 59, 59, 0),
79
+ userData)
80
+ assert.equal(data.length, 1)
81
+ }, 8000000)
75
82
  })
@@ -37,10 +37,12 @@ describe('speeding tests', function () {
37
37
  userData.customSpeed = false
38
38
  userData.useVehicleSpeedLimit = true
39
39
  const data = await report.speedingReport(
40
- new Date(Date.UTC(2022, 9, 22, 0, 0, 0, 0)),
41
- new Date(Date.UTC(2022, 9, 23, 23, 59, 59, 0)),
40
+ new Date(Date.UTC(2023, 7, 22, 0, 0, 0, 0)),
41
+ new Date(Date.UTC(2023, 7, 23, 23, 59, 59, 0)),
42
42
  userData)
43
- assert.equal(data[0].devices.length, 0)
43
+ console.log(data[0].devices[0].alerts.length)
44
+ console.log(data[0].devices[0].alerts)
45
+ assert.equal(data[0].devices.length, 2)
44
46
  }, 900000)
45
47
 
46
48
  // eslint-disable-next-line no-undef
package/src/util/trips.js CHANGED
@@ -1,4 +1,4 @@
1
- const { coordsDistance, convertFromUTC, weekDaySelected, convertFromLocal, isClientSide } = require('./utils')
1
+ const { coordsDistance, convertFromUTC, weekDaySelected, convertFromLocal, isClientSide, calculateDistance } = require('./utils')
2
2
  const { isInside } = require('./timetable')
3
3
 
4
4
  const minDistance = 0
@@ -120,7 +120,7 @@ function calculateTrip (device, route) {
120
120
  return {
121
121
  deviceId: device.id,
122
122
  deviceName: device.name,
123
- distance: route.reduce((a, b) => a + b.attributes.distance, 0),
123
+ distance: calculateDistance(route) * 1000,
124
124
  averageSpeed: Math.round((route.map(p => p.speed).reduce((a, b) => a + b, 0)) / route.length),
125
125
  maxSpeed: route.map(p => p.speed).reduce(function (a, b) { return Math.max(a, b) }),
126
126
  spentFuel: 0,