fleetmap-reports 1.0.592 → 1.0.594

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/lang/frFR.js CHANGED
@@ -161,7 +161,7 @@ module.exports = {
161
161
  select_geofences_placeholder: 'Geofences',
162
162
  select_period: 'Select period',
163
163
  period: 'Period',
164
- titleTripReport: 'Reporte de viaje',
164
+ titleTripReport: 'Rapport de voyage',
165
165
  titleLocationReport: 'Rapport de localisation',
166
166
  titleSpeedingReport: 'Rapport de survitesse',
167
167
  titleZoneReport: 'Rapport de zones',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fleetmap-reports",
3
- "version": "1.0.592",
3
+ "version": "1.0.594",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -1,8 +1,5 @@
1
1
  const jsPDF = require('jspdf')
2
- const {
3
- convertMS, convertToLocaleString, convertToFeature, convertPositionToFeature, getTranslations, getLanguage,
4
- checkGeocoding
5
- } = require('./util/utils')
2
+ const { convertMS, convertToLocaleString, convertToFeature, convertPositionToFeature, getTranslations, getLanguage } = require('./util/utils')
6
3
  const { headerFromUser, AmiriRegular } = require('./util/pdfDocument')
7
4
  require('jspdf-autotable')
8
5
  const { getStyle } = require('./reportStyle')
@@ -100,7 +97,7 @@ async function createSpeedingReportByDevice (from, to, userData, traccarInstance
100
97
  }
101
98
  }))
102
99
  }
103
- checkGeocoding(allData)
100
+
104
101
  return allData
105
102
  }
106
103
 
@@ -412,4 +412,17 @@ describe('Test_Reports', function () {
412
412
  assert.equal(device.geofences[0].totalTime, '28777')
413
413
  assert.equal(device.geofences[0].geofenceName, 'Casa João')
414
414
  }, 30000)
415
+ // eslint-disable-next-line no-undef
416
+ it('Zone Report With Stops', async () => {
417
+ const report = await getReports()
418
+ const userData = await report.getUserData()
419
+ userData.onlyWithStop = true
420
+ const data = await report.zoneReport(new Date(2023, 1, 1, 0, 0, 0, 0),
421
+ new Date(2023, 1, 5, 23, 59, 59, 0),
422
+ userData)
423
+
424
+ assert.equal(data.length, 1)
425
+ const device = data[0].devices.find(d => d.device.id === 82063)
426
+ assert.equal(device.geofences.length, 15)
427
+ }, 30000)
415
428
  })
package/src/util/route.js CHANGED
@@ -36,4 +36,20 @@ function getIdleEvents (route, driver) {
36
36
 
37
37
  return idleEvents
38
38
  }
39
+
40
+ function filterPositions (positions) {
41
+ return positions.filter(filterPosition)
42
+ }
43
+
44
+ function filterPosition (p) {
45
+ if (p.valid === false) {
46
+ return p.attributes.ignition || p.attributes.motion
47
+ }
48
+ if (p.protocol === 'osmand') {
49
+ return !(p.attributes.event >= 200 || p.attributes.event === 30)
50
+ }
51
+ return true
52
+ }
53
+
39
54
  exports.getIdleEvents = getIdleEvents
55
+ exports.filterPositions = filterPositions
package/src/util/utils.js CHANGED
@@ -227,8 +227,3 @@ exports.getLogo = (user) => {
227
227
  }
228
228
  exports.convertToFeature = convertToFeature
229
229
  exports.convertPositionToFeature = convertPositionToFeature
230
-
231
- function checkGeocoding () {
232
- }
233
-
234
- exports.checkGeocoding = checkGeocoding
@@ -13,6 +13,7 @@ const booleanPointInPolygon = require('@turf/boolean-point-in-polygon')
13
13
  const distance = require('@turf/distance')
14
14
  const axios = require('axios')
15
15
  const { processServerSide } = require('./util')
16
+ const { filterPositions } = require('./util/route')
16
17
  const sliceSize = 200
17
18
  const deviceChunk = 5
18
19
  const fileName = 'ZoneReport'
@@ -68,11 +69,13 @@ async function createZoneReport (from, to, userData, traccar) {
68
69
  traccar, from, to, slice, true, false, false, false,
69
70
  deviceCount, devices.length, sliceSize, deviceChunk, undefined)
70
71
 
71
- const alerts = getInAndOutEvents(slice, data.route, userData)
72
+ const route = filterPositions(data.route)
73
+
74
+ const alerts = getInAndOutEvents(slice, route, userData)
72
75
  console.log('Geofence Enter/Exit Alerts:' + alerts.length)
73
76
 
74
77
  if (alerts.length) {
75
- allData.devices.push(...await processDevices(from, to, devices, userData, { alerts, route: data.route }))
78
+ allData.devices.push(...await processDevices(from, to, devices, userData, { alerts, route }))
76
79
  }
77
80
  deviceCount = deviceCount + slice.length
78
81
  }
@@ -87,6 +90,8 @@ async function processDevices (from, to, devices, userData, data) {
87
90
 
88
91
  for (const d of devices) {
89
92
  const alerts = data.alerts.filter(t => t.deviceId === d.id)
93
+ const deviceRoute = data.route.filter(p => p.deviceId === d.id)
94
+
90
95
  if (alerts.length > 0) {
91
96
  const zoneInOutData = []
92
97
  const zoneInData = {}
@@ -101,9 +106,8 @@ async function processDevices (from, to, devices, userData, data) {
101
106
  const geofence = userData.geofences.find(g => g.id === a.geofenceId)
102
107
  if (zoneInData[a.geofenceId]) {
103
108
  const totalInTime = moment(a.position.fixTime).diff(moment(zoneInData[a.geofenceId].position.fixTime), 'seconds')
104
- const route = data.route.filter(p => new Date(p.fixTime).getTime() >= new Date(zoneInData[a.geofenceId].position.fixTime).getTime() &&
109
+ const route = deviceRoute.filter(p => new Date(p.fixTime).getTime() >= new Date(zoneInData[a.geofenceId].position.fixTime).getTime() &&
105
110
  new Date(p.fixTime).getTime() <= new Date(a.position.fixTime).getTime())
106
- console.log(route)
107
111
  if (geofence) {
108
112
  zoneInOutData.push({
109
113
  inTime: zoneInData[a.geofenceId].position,
@@ -167,6 +171,9 @@ function getInAndOutEvents (devices, route, userData) {
167
171
 
168
172
  const entryMap = []
169
173
  routePoints.forEach(p => {
174
+ if (!p.properties.position.valid) {
175
+ return
176
+ }
170
177
  geofencesFeatures.forEach(g => {
171
178
  if (g.geometry.type === 'Polygon') {
172
179
  if (booleanPointInPolygon.default(p, g)) {
@@ -343,7 +350,6 @@ function exportZoneReportToExcel (userData, reportData) {
343
350
  }
344
351
  }))
345
352
  })
346
- console.log(data)
347
353
  return {
348
354
  headers,
349
355
  data,