fleetmap-reports 1.0.708 → 1.0.710
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 +1 -2
- package/src/tests/fuel.test.js +0 -1
- package/src/util/parallel.js +36 -0
- package/src/worker.js +6 -0
- package/src/zone-report.js +13 -24
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fleetmap-reports",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.710",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -14,7 +14,6 @@
|
|
|
14
14
|
"@turf/distance": "^6.5.0",
|
|
15
15
|
"@turf/helpers": "^6.5.0",
|
|
16
16
|
"@turf/point-to-line-distance": "^6.5.0",
|
|
17
|
-
"async": "^3.2.4",
|
|
18
17
|
"axios": "^0.22.0",
|
|
19
18
|
"axios-cookiejar-support": "^1.0.1",
|
|
20
19
|
"docx": "^7.3.0",
|
package/src/tests/fuel.test.js
CHANGED
|
@@ -5,7 +5,6 @@ const assert = require('assert')
|
|
|
5
5
|
const deviceId = 122575
|
|
6
6
|
// eslint-disable-next-line no-undef
|
|
7
7
|
describe('Test_Reports', function () {
|
|
8
|
-
this.timeout(5000000)
|
|
9
8
|
it('Trip by device', async () => {
|
|
10
9
|
console.log('trip by device')
|
|
11
10
|
const report = await getReports()
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const { sliceArray } = require('../automaticReports')
|
|
2
|
+
const cluster = require('cluster')
|
|
3
|
+
|
|
4
|
+
exports.parallel = (report, method, devices, route, userData) => {
|
|
5
|
+
const numCPUs = require('os').cpus().length
|
|
6
|
+
return new Promise((resolve) => {
|
|
7
|
+
if (cluster.isPrimary) {
|
|
8
|
+
console.log(`Master ${process.pid} is running`, process.cwd())
|
|
9
|
+
cluster.setupPrimary({
|
|
10
|
+
exec: './src/worker.js'
|
|
11
|
+
})
|
|
12
|
+
const sliced = sliceArray(devices, numCPUs)
|
|
13
|
+
const _result = []
|
|
14
|
+
let done = 0
|
|
15
|
+
sliced.forEach((_devices) => {
|
|
16
|
+
const worker = cluster.fork()
|
|
17
|
+
worker.send({
|
|
18
|
+
report,
|
|
19
|
+
method,
|
|
20
|
+
args: [_devices, route.filter(p => _devices.find(d => d.id === p.deviceId)), userData]
|
|
21
|
+
})
|
|
22
|
+
worker.on('message', ({ result }) => {
|
|
23
|
+
console.log(`Received result from worker ${worker.process.pid}:`, result)
|
|
24
|
+
_result.push(result)
|
|
25
|
+
if (++done === sliced.length) {
|
|
26
|
+
resolve(_result.flat())
|
|
27
|
+
}
|
|
28
|
+
})
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
cluster.on('exit', (worker, code, signal) => {
|
|
32
|
+
console.log('Worker died', worker.process.pid, code, signal)
|
|
33
|
+
})
|
|
34
|
+
}
|
|
35
|
+
})
|
|
36
|
+
}
|
package/src/worker.js
ADDED
package/src/zone-report.js
CHANGED
|
@@ -2,7 +2,8 @@ const automaticReports = require('./automaticReports')
|
|
|
2
2
|
const {
|
|
3
3
|
convertMS, convertToLocaleString, getTranslations, convertToFeature, convertPositionToFeature,
|
|
4
4
|
calculateDistance,
|
|
5
|
-
sortPositions, getDates, convertToLocaleDateString, convertToLocaleTimeString
|
|
5
|
+
sortPositions, getDates, convertToLocaleDateString, convertToLocaleTimeString,
|
|
6
|
+
isClientSide
|
|
6
7
|
} = require('./util/utils')
|
|
7
8
|
const jsPDF = require('jspdf')
|
|
8
9
|
require('jspdf-autotable')
|
|
@@ -12,9 +13,9 @@ const { getStyle } = require('./reportStyle')
|
|
|
12
13
|
const { getUserPartner } = require('fleetmap-partners')
|
|
13
14
|
const { devicesToProcess } = require('./util/device')
|
|
14
15
|
const axios = require('axios')
|
|
15
|
-
const { processServerSide } = require('./util')
|
|
16
16
|
const { filterPositions } = require('./util/route')
|
|
17
17
|
const { checkGeofenceIn } = require('./util/geofence')
|
|
18
|
+
const { parallel } = require('./util/parallel')
|
|
18
19
|
const sliceSize = 100
|
|
19
20
|
const deviceChunk = 5
|
|
20
21
|
const fileName = 'ZoneReport'
|
|
@@ -27,19 +28,10 @@ async function createZoneReport (from, to, userData, traccar) {
|
|
|
27
28
|
xpert: devices.filter(d => d.attributes.xpert).length > 0
|
|
28
29
|
}
|
|
29
30
|
|
|
30
|
-
if (
|
|
31
|
+
if (isClientSide()) {
|
|
31
32
|
const url = `https://${process.env.SERVER_HOST}/reports/zone-report`
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
for (const slice of sliced) {
|
|
35
|
-
promises.push(axios.post(url, { from, to, userData: { ...userData, devices: slice } }, { withCredentials: true })
|
|
36
|
-
.then(d => d.data)
|
|
37
|
-
.then(data => allData.devices.push(...(data[0].devices)))
|
|
38
|
-
)
|
|
39
|
-
}
|
|
40
|
-
await Promise.all(promises)
|
|
41
|
-
reportData.push(allData)
|
|
42
|
-
return reportData
|
|
33
|
+
return axios.post(url, { from, to, userData }, { withCredentials: true })
|
|
34
|
+
.then(d => d.data)
|
|
43
35
|
}
|
|
44
36
|
const types = ['geofenceEnter', 'geofenceExit']
|
|
45
37
|
|
|
@@ -75,8 +67,7 @@ async function createZoneReport (from, to, userData, traccar) {
|
|
|
75
67
|
deviceCount, devices.length, sliceSize, deviceChunk, undefined)
|
|
76
68
|
|
|
77
69
|
const route = filterPositions(data.route)
|
|
78
|
-
const alerts = await getInAndOutEvents
|
|
79
|
-
|
|
70
|
+
const alerts = await parallel('zone-report', 'getInAndOutEvents', slice, route, userData)
|
|
80
71
|
allData.devices.push(...await processDevices(from, to, devices, userData, { alerts, route }))
|
|
81
72
|
|
|
82
73
|
deviceCount = deviceCount + slice.length
|
|
@@ -304,18 +295,16 @@ async function getInAndOutEvents (devices, route, userData) {
|
|
|
304
295
|
const events = []
|
|
305
296
|
const geofencesFeatures = userData.geofences.map(g => convertToFeature(g))
|
|
306
297
|
|
|
307
|
-
|
|
308
|
-
await async.parallel(devices.map(async.asyncify(async d => {
|
|
298
|
+
devices.forEach(d => {
|
|
309
299
|
const deviceRoute = route.filter(p => p.deviceId === d.id)
|
|
310
300
|
const routePoints = deviceRoute.sort(sortPositions).map(p => convertPositionToFeature(p))
|
|
311
|
-
const deviceEvents = []
|
|
312
301
|
routePoints.filter(p => p.properties.position.valid).forEach((p, i, array) => {
|
|
313
302
|
p.inside = {}
|
|
314
303
|
if (!i) {
|
|
315
304
|
geofencesFeatures.forEach((g, id) => {
|
|
316
305
|
if (checkGeofenceIn(p, g)) {
|
|
317
306
|
p.inside[id] = true
|
|
318
|
-
|
|
307
|
+
events.push(createEvent('geofenceIn', d.id, p, g))
|
|
319
308
|
}
|
|
320
309
|
})
|
|
321
310
|
return
|
|
@@ -324,20 +313,19 @@ async function getInAndOutEvents (devices, route, userData) {
|
|
|
324
313
|
geofencesFeatures.forEach((g, id) => {
|
|
325
314
|
if (previous.inside[id]) {
|
|
326
315
|
if (!checkGeofenceIn(p, g)) {
|
|
327
|
-
|
|
316
|
+
events.push(createEvent('geofenceExit', d.id, p, g))
|
|
328
317
|
} else {
|
|
329
318
|
p.inside[id] = true
|
|
330
319
|
}
|
|
331
320
|
} else {
|
|
332
321
|
if (checkGeofenceIn(p, g)) {
|
|
333
322
|
p.inside[id] = true
|
|
334
|
-
|
|
323
|
+
events.push(createEvent('geofenceEnter', d.id, p, g))
|
|
335
324
|
}
|
|
336
325
|
}
|
|
337
326
|
})
|
|
338
327
|
})
|
|
339
|
-
|
|
340
|
-
})))
|
|
328
|
+
})
|
|
341
329
|
return events
|
|
342
330
|
}
|
|
343
331
|
|
|
@@ -555,3 +543,4 @@ function geofenceExit (user, row) {
|
|
|
555
543
|
exports.createZoneReport = createZoneReport
|
|
556
544
|
exports.exportZoneReportToPDF = exportZoneReportToPDF
|
|
557
545
|
exports.exportZoneReportToExcel = exportZoneReportToExcel
|
|
546
|
+
exports.getInAndOutEvents = getInAndOutEvents
|