fleetmap-reports 2.0.215 → 2.0.218
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 -1
- package/src/util/parallel.js +1 -1
- package/src/util/route.js +15 -12
- package/src/util/traccar.js +9 -7
- package/src/util/traccar.worker.js +7 -8
- package/src/zone-report.js +19 -14
package/package.json
CHANGED
package/src/util/parallel.js
CHANGED
|
@@ -23,7 +23,7 @@ exports.parallel = (report, method, toSlice, ...args) => {
|
|
|
23
23
|
reject(new Error('got empty slice'))
|
|
24
24
|
}
|
|
25
25
|
try {
|
|
26
|
-
console.log('forking worker', workerCount++, report, method, slice)
|
|
26
|
+
console.log('forking worker', workerCount++, report, method, slice.length)
|
|
27
27
|
const worker = cluster.fork()
|
|
28
28
|
worker.send({
|
|
29
29
|
report,
|
package/src/util/route.js
CHANGED
|
@@ -41,19 +41,21 @@ function filterPositions (positions) {
|
|
|
41
41
|
return positions.filter(filterPosition)
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
function cleanPosition (p) {
|
|
45
|
+
return {
|
|
46
|
+
id: p.id,
|
|
47
|
+
fixTime: p.fixTime,
|
|
48
|
+
address: p.address,
|
|
49
|
+
latitude: p.latitude,
|
|
50
|
+
longitude: p.longitude,
|
|
51
|
+
deviceId: p.deviceId,
|
|
52
|
+
speed: p.speed,
|
|
53
|
+
valid: p.valid
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
44
57
|
exports.cleanPositions = (positions) => {
|
|
45
|
-
return positions.map(
|
|
46
|
-
return {
|
|
47
|
-
id: p.id,
|
|
48
|
-
fixTime: p.fixTime,
|
|
49
|
-
address: p.address,
|
|
50
|
-
latitude: p.latitude,
|
|
51
|
-
longitude: p.longitude,
|
|
52
|
-
deviceId: p.deviceId,
|
|
53
|
-
speed: p.speed,
|
|
54
|
-
valid: p.valid
|
|
55
|
-
}
|
|
56
|
-
})
|
|
58
|
+
return positions.map(cleanPosition)
|
|
57
59
|
}
|
|
58
60
|
|
|
59
61
|
function filterPosition (p) {
|
|
@@ -68,3 +70,4 @@ function filterPosition (p) {
|
|
|
68
70
|
|
|
69
71
|
exports.getIdleEvents = getIdleEvents
|
|
70
72
|
exports.filterPositions = filterPositions
|
|
73
|
+
exports.cleanPositon = cleanPosition
|
package/src/util/traccar.js
CHANGED
|
@@ -69,10 +69,10 @@ async function getSummary (traccar, from, to, devices) {
|
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
async function getItems (traccar, u, _chunk, counter, devicesPerRequest, ignorePercentage,
|
|
72
|
-
totalDevices, currentDeviceCount, routeOnly) {
|
|
72
|
+
totalDevices, currentDeviceCount, routeOnly, filter) {
|
|
73
73
|
try {
|
|
74
|
-
const x = routeOnly
|
|
75
|
-
? await streamJson(traccar, u)
|
|
74
|
+
const x = routeOnly && !isClientSide()
|
|
75
|
+
? await streamJson(traccar, u.replace('allinone', 'route'), filter)
|
|
76
76
|
: await traccar.axios.get(u, {
|
|
77
77
|
withCredentials: true
|
|
78
78
|
}).then(r => r.data)
|
|
@@ -93,11 +93,12 @@ async function getItems (traccar, u, _chunk, counter, devicesPerRequest, ignoreP
|
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
function streamJson (traccar, u,
|
|
97
|
-
const cookie =
|
|
96
|
+
function streamJson (traccar, u, filter) {
|
|
97
|
+
const cookie = traccar.axios.defaults.headers?.cookie || traccar.axios.defaults.headers?.common?.cookie
|
|
98
98
|
return piscina.run({
|
|
99
99
|
url: traccar.axios.defaults.baseURL + u,
|
|
100
|
-
cookie
|
|
100
|
+
cookie,
|
|
101
|
+
filter
|
|
101
102
|
},
|
|
102
103
|
{
|
|
103
104
|
filename: path.resolve(__dirname, './traccar.worker.js'),
|
|
@@ -135,7 +136,8 @@ async function getAllInOne (
|
|
|
135
136
|
console.log(u)
|
|
136
137
|
requests.push(
|
|
137
138
|
getItems(traccar, u, _chunk, counter, devicesPerRequest, ignorePercentage, totalDevices, currentDeviceCount,
|
|
138
|
-
!getTrips && !getStops && !getSummary)
|
|
139
|
+
!getTrips && !getStops && !getSummary)
|
|
140
|
+
)
|
|
139
141
|
}
|
|
140
142
|
const now = new Date()
|
|
141
143
|
console.log('parallel', requests.length)
|
|
@@ -3,30 +3,29 @@ const { parser } = require('stream-json')
|
|
|
3
3
|
const { pick } = require('stream-json/filters/Pick')
|
|
4
4
|
const { streamArray } = require('stream-json/streamers/StreamArray')
|
|
5
5
|
const { Readable } = require('stream')
|
|
6
|
+
const { cleanPosition } = require('./route')
|
|
6
7
|
|
|
7
|
-
module.exports = async ({ url, cookie }) => {
|
|
8
|
+
module.exports = async ({ url, cookie, filter }) => {
|
|
8
9
|
const now = new Date()
|
|
9
|
-
console.log(url)
|
|
10
10
|
const response = await fetch(url, {
|
|
11
11
|
headers: { cookie }
|
|
12
12
|
})
|
|
13
13
|
if (!response.ok) {
|
|
14
|
-
throw new Error(
|
|
14
|
+
throw new Error(`${cookie} ${url} Fetch failed: ${response.status} ${response.statusText}`)
|
|
15
15
|
}
|
|
16
16
|
console.log(url, 'took', new Date() - now, 'ms', 'streaming...')
|
|
17
|
-
|
|
18
|
-
/* const nodeStream = Readable.fromWeb(response.body)
|
|
17
|
+
const nodeStream = Readable.fromWeb(response.body)
|
|
19
18
|
|
|
20
19
|
const result = { route: [] }
|
|
21
20
|
return new Promise((resolve, reject) => {
|
|
22
21
|
const pipeline = chain([
|
|
23
22
|
nodeStream,
|
|
24
23
|
parser(),
|
|
25
|
-
pick({ filter: 'route' }),
|
|
26
24
|
streamArray() // Stream each item in the array
|
|
27
25
|
])
|
|
28
|
-
pipeline.on('data', ({ value }) => result.route.push(
|
|
26
|
+
pipeline.on('data', ({ value }) => result.route.push(
|
|
27
|
+
filter ? cleanPosition(value) : value))
|
|
29
28
|
pipeline.on('end', () => resolve(result))
|
|
30
29
|
pipeline.on('error', reject)
|
|
31
|
-
})
|
|
30
|
+
})
|
|
32
31
|
}
|
package/src/zone-report.js
CHANGED
|
@@ -23,11 +23,26 @@ const { checkGeofenceIn } = require('./util/geofence')
|
|
|
23
23
|
const { parallel } = require('./util/parallel')
|
|
24
24
|
const { getDataByDay } = require('./util/trips')
|
|
25
25
|
const axios = require('axios').default
|
|
26
|
-
const sliceSize =
|
|
26
|
+
const sliceSize = 10
|
|
27
27
|
const deviceChunk = 5
|
|
28
28
|
const fileName = 'ZoneReport'
|
|
29
29
|
|
|
30
|
-
async function
|
|
30
|
+
async function process (traccar, from, to, slice, deviceCount, devices, reportRangeDays, userData) {
|
|
31
|
+
const data = await traccarHelper.getAllInOne(
|
|
32
|
+
traccar, from, to, slice, true, false, false, false,
|
|
33
|
+
deviceCount, devices.length, sliceSize, reportRangeDays > 29 ? 1 : deviceChunk, undefined, filterPositions)
|
|
34
|
+
|
|
35
|
+
const route = filterPositions(data.route)
|
|
36
|
+
const alerts = []
|
|
37
|
+
if (isClientSide()) {
|
|
38
|
+
alerts.push(...(await getInAndOutEvents(slice, cleanPositions(route), userData)))
|
|
39
|
+
} else {
|
|
40
|
+
alerts.push(...(await parallel('zone-report', 'getInAndOutEvents', slice, cleanPositions(route), userData)))
|
|
41
|
+
}
|
|
42
|
+
return await processDevices(from, to, slice, userData, { alerts, route, summary: data.summary })
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async function createZoneReport (from, to, userData, traccar) {
|
|
31
46
|
console.log('createZoneReport', from, to)
|
|
32
47
|
const reportData = []
|
|
33
48
|
const devices = devicesToProcess(userData)
|
|
@@ -71,18 +86,8 @@ async function createZoneReport (from, to, userData, traccar, cookie) {
|
|
|
71
86
|
|
|
72
87
|
let deviceCount = 0
|
|
73
88
|
for (const slice of sliced) {
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
deviceCount, devices.length, sliceSize, reportRangeDays > 29 ? 1 : deviceChunk, undefined)
|
|
77
|
-
|
|
78
|
-
const route = filterPositions(data.route)
|
|
79
|
-
const alerts = []
|
|
80
|
-
if (isClientSide()) {
|
|
81
|
-
alerts.push(...(await getInAndOutEvents(slice, cleanPositions(route), userData)))
|
|
82
|
-
} else {
|
|
83
|
-
alerts.push(...(await parallel('zone-report', 'getInAndOutEvents', slice, cleanPositions(route), userData)))
|
|
84
|
-
}
|
|
85
|
-
allData.devices.push(...await processDevices(from, to, slice, userData, { alerts, route, summary: data.summary }))
|
|
89
|
+
const processed = await process(traccar, from, to, slice, deviceCount, devices, reportRangeDays, userData)
|
|
90
|
+
allData.devices.push(...processed)
|
|
86
91
|
|
|
87
92
|
deviceCount = deviceCount + slice.length
|
|
88
93
|
}
|