fleetmap-reports 1.0.538 → 1.0.540

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/one ADDED
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fleetmap-reports",
3
- "version": "1.0.538",
3
+ "version": "1.0.540",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -7,7 +7,6 @@ const { headerFromUser } = require('./util/pdfDocument')
7
7
  const { getStyle } = require('./reportStyle')
8
8
  const { getUserPartner } = require('fleetmap-partners')
9
9
  const { devicesToProcess } = require('./util/device')
10
- const traccarHelper = require('./util/traccar')
11
10
  const pointToLineDistance = require('@turf/point-to-line-distance')
12
11
  const booleanPointInPolygon = require('@turf/boolean-point-in-polygon')
13
12
  const distance = require('@turf/distance')
@@ -59,16 +58,13 @@ async function createZoneReport (from, to, userData, traccar) {
59
58
  xpert: devices.filter(d => d.attributes.xpert).length > 0
60
59
  }
61
60
 
62
- const sliced = automaticReports.sliceArray(devices, 100)
61
+ const sliced = automaticReports.sliceArray(devices, 200)
63
62
 
64
63
  let deviceCount = 0
65
64
  for (const slice of sliced) {
66
- const allInOne = await traccarHelper.getAllInOne(
65
+ const data = await getAllInOne(
67
66
  traccar, from, to, slice, true, false, false, false,
68
- deviceCount, devices.length, 50, 5)
69
- const routeData = allInOne.route
70
-
71
- const data = getInAndOutEvents(slice, routeData, userData)
67
+ deviceCount, devices.length, 200, 5, undefined, userData)
72
68
 
73
69
  console.log('Geofence Enter/Exit Alerts:' + data.length)
74
70
 
@@ -83,6 +79,53 @@ async function createZoneReport (from, to, userData, traccar) {
83
79
  return reportData
84
80
  }
85
81
 
82
+ async function getAllInOne (
83
+ traccar,
84
+ from,
85
+ to,
86
+ devices,
87
+ getRoutes,
88
+ getTrips,
89
+ getStops,
90
+ getSummary,
91
+ currentDeviceCount = 0,
92
+ totalDevices = devices.length,
93
+ sliceSize = 5,
94
+ devicesPerRequest = 1,
95
+ counter = undefined,
96
+ userData) {
97
+ let url = `/reports/allinone?from=${from.toISOString()}&to=${to.toISOString()}`
98
+ if (getRoutes) url += '&type=route'
99
+ if (getTrips) url += '&type=trips'
100
+ if (getStops) url += '&type=stops'
101
+ if (getSummary) url += '&type=summary'
102
+
103
+ const sliced = automaticReports.sliceArray(devices, sliceSize)
104
+ const result = []
105
+ for (const chunk of sliced) {
106
+ const requests = []
107
+ for (const _chunk of automaticReports.sliceArray(chunk, devicesPerRequest)) {
108
+ const u = url + '&' + _chunk.map(d => `deviceId=${d.id}`).join('&')
109
+ requests.push(
110
+ traccar.axios.get(u, {
111
+ jar: traccar.cookieJar,
112
+ withCredentials: true
113
+ }).then(r => r.data).then(x => {
114
+ if (counter) {
115
+ counter.count += devicesPerRequest
116
+ console.log(`PROGRESS_PERC:${counter.count / totalDevices * 100}`)
117
+ } else {
118
+ currentDeviceCount += devicesPerRequest
119
+ console.log(`PROGRESS_PERC:${currentDeviceCount / totalDevices * 100}`)
120
+ }
121
+ return getInAndOutEvents(devices, x.route, userData)
122
+ }))
123
+ }
124
+ result.push(...(await Promise.all(requests)))
125
+ }
126
+ return result
127
+ }
128
+
86
129
  async function processDevices (from, to, devices, drivers, geofences, data) {
87
130
  const devicesResult = []
88
131