fleetmap-reports 1.0.822 → 1.0.824

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.822",
3
+ "version": "1.0.824",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -9,6 +9,7 @@ const { devicesToProcess } = require('./util/device')
9
9
  const { isInside } = require('./util/timetable')
10
10
  const { getDigitalPortValue } = require('./location-report')
11
11
  const { maxParallelRequests } = require('./automaticReports')
12
+ const { getNearestPOI } = require('./util/geofence')
12
13
 
13
14
  const fileName = 'EventReport'
14
15
 
@@ -82,6 +83,10 @@ async function processDevices (from, to, devices, data, traccar, userData) {
82
83
  for (const a of deviceAlerts) {
83
84
  a.position = positions.find(p => p.id === a.positionId)
84
85
 
86
+ if (!a.geofenceId) {
87
+ const poi = getNearestPOI(a.position, userData.geofences)
88
+ a.geofenceId = poi && poi.id
89
+ }
85
90
  if (a.geofenceId) {
86
91
  const geofence = userData.geofences.find(g => g.id === a.geofenceId)
87
92
  if (geofence) {
@@ -6,6 +6,11 @@ const { convertToFeature, convertPositionToFeature } = require('../util/utils')
6
6
  function calculateLastStopTime (stopTime, to, time) {
7
7
  return stopTime + (to.getTime() - new Date(time).getTime())
8
8
  }
9
+
10
+ function calculateFirstStopTime (stopTime, from, time) {
11
+ return stopTime + (new Date(time).getTime() - from.getTime())
12
+ }
13
+
9
14
  async function createActivityReport (from, to, userData, traccarInstance) {
10
15
  const unauthorizedGeofences = []
11
16
  const authorizedGeofences = []
@@ -72,14 +72,4 @@ describe('activity report', function () {
72
72
  console.log(device)
73
73
  assert.equal(device.summary.reduce((a, b) => a + b.convertedSpentFuel, 0), 168.79999999999995)
74
74
  }, 800000)
75
- it('Activity test performance', async () => {
76
- const report = await getReports('q.trans', 'quality1214')
77
- const userData = await report.getUserData()
78
- console.log(userData)
79
- userData.groupByDay = true
80
- const data = await report.activityReport(new Date(2023, 7, 1, 0, 0, 0, 0),
81
- new Date(2023, 31, 5, 23, 59, 59, 0),
82
- userData)
83
- assert.equal(data.length, 1)
84
- }, 8000000)
85
75
  })
@@ -32,18 +32,6 @@ describe('zones', function () {
32
32
  console.log('result', result)
33
33
  }, 4000000)
34
34
 
35
- it('works with afriquia', async () => {
36
- const report = await getReports(process.env.USER_AFRIQUIA, process.env.PASS_AFRIQUIA)
37
- const userData = await report.getUserData()
38
- console.log(userData.devices.length)
39
- console.log(userData.geofences)
40
- const result = await report.zoneReport(
41
- new Date(Date.UTC(2023, 5, 11, 0, 0, 0, 0)),
42
- new Date(Date.UTC(2023, 5, 11, 23, 59, 59, 0)),
43
- userData)
44
- console.log('result', result)
45
- }, 4000000)
46
-
47
35
  // eslint-disable-next-line no-undef
48
36
  it('works with casais', async () => {
49
37
  const report = await getReports(process.env.USER_CASAIS, process.env.PASS_CASAIS)
@@ -16,7 +16,8 @@ exports.insideGeofence = function insideGeofence (position, geofence) {
16
16
  return inside.default(pt, poly)
17
17
  }
18
18
 
19
- exports.getNearestPOIs = function getNearestPOIs (long, lat, geofences) {
19
+ exports.getNearestPOI = (position, geofences) => getNearestPOIs(position.longitude, position.latitude, geofences)[0]
20
+ function getNearestPOIs (long, lat, geofences) {
20
21
  const distance = geofences
21
22
  .filter(g => g && g.area.startsWith('CIRCLE'))
22
23
  .map(g => {
@@ -29,6 +30,7 @@ exports.getNearestPOIs = function getNearestPOIs (long, lat, geofences) {
29
30
  })
30
31
  return distance.filter(a => a.distance < 100).sort((a, b) => (a.distance > b.distance) ? 1 : -1)
31
32
  }
33
+ exports.getNearestPOIs = getNearestPOIs
32
34
 
33
35
  exports.loadGroupsData = async function loadGroupsData (userData, traccarInstance) {
34
36
  for (const g of userData.groups) {
@@ -195,7 +195,7 @@ async function processDevices (from, to, devices, userData, data) {
195
195
  outGeofenceName: a.geofenceName,
196
196
  inTime: zoneInOutData[index + 1].inTime,
197
197
  inGeofenceName: zoneInOutData[index + 1].geofenceName,
198
- distanceOut: a.distanceOut,
198
+ distanceOut: a.distanceOutAny,
199
199
  totalOutTime: new Date(zoneInOutData[index + 1].inTime.fixTime).getTime() - new Date(a.outTime.fixTime).getTime()
200
200
  })
201
201
  }
@@ -339,7 +339,7 @@ function analyseAlerts (alerts, deviceRoute, userData, from, to) {
339
339
  new Date(p.fixTime).getTime() >= outDate &&
340
340
  new Date(p.fixTime).getTime() < anyNextIn
341
341
  )
342
- const distanceOutAny = zoneInData.length < 2 ? calculateDistance(routeAfterOutAndBeforeAnyNextIn) : 0
342
+ const distanceOutAny = Object.keys(zoneInData).length < 2 ? calculateDistance(routeAfterOutAndBeforeAnyNextIn) : 0
343
343
 
344
344
  if (zoneInData[a.geofenceId]) {
345
345
  const totalInTime = new Date(a.position.fixTime).getTime() - new Date(zoneInData[a.geofenceId].position.fixTime).getTime()
@@ -361,7 +361,7 @@ function analyseAlerts (alerts, deviceRoute, userData, from, to) {
361
361
  stopped: routeIn.filter(p => !p.attributes.ignition).length > 0,
362
362
  driverName: zoneInData[a.geofenceId].position.driverName
363
363
  })
364
- zoneInData[a.geofenceId] = null
364
+ delete zoneInData[a.geofenceId]
365
365
  } else {
366
366
  const totalInTime = new Date(a.position.fixTime).getTime() - from.getTime()
367
367
  const routeIn = deviceRoute.filter(p =>