fleetmap-reports 2.0.311 → 2.0.313
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/zone-report.js +26 -2
package/package.json
CHANGED
package/src/zone-report.js
CHANGED
|
@@ -26,6 +26,28 @@ const sliceSize = 1
|
|
|
26
26
|
const deviceChunk = 5
|
|
27
27
|
const fileName = 'ZoneReport'
|
|
28
28
|
|
|
29
|
+
function simpleLimit (concurrency) {
|
|
30
|
+
const queue = []
|
|
31
|
+
let activeCount = 0
|
|
32
|
+
|
|
33
|
+
const next = () => {
|
|
34
|
+
if (queue.length === 0 || activeCount >= concurrency) return
|
|
35
|
+
activeCount++
|
|
36
|
+
const { fn, resolve, reject } = queue.shift()
|
|
37
|
+
fn().then(resolve).catch(reject).finally(() => {
|
|
38
|
+
activeCount--
|
|
39
|
+
next()
|
|
40
|
+
})
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return fn => {
|
|
44
|
+
return new Promise((resolve, reject) => {
|
|
45
|
+
queue.push({ fn, resolve, reject })
|
|
46
|
+
next()
|
|
47
|
+
})
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
29
51
|
exports.process = async (traccar, from, to, slice, deviceCount, devices, reportRangeDays, userData) => {
|
|
30
52
|
const data = await traccarHelper.getAllInOne(
|
|
31
53
|
traccar, from, to, slice, true, false, false, false,
|
|
@@ -85,7 +107,8 @@ async function createZoneReport (from, to, userData, traccar) {
|
|
|
85
107
|
|
|
86
108
|
const url = 'https://rntba7aqifqx3iywrenb7pq6km0liwsr.lambda-url.us-east-1.on.aws/pinmeapi/process-report/zone-report-processing'
|
|
87
109
|
|
|
88
|
-
const
|
|
110
|
+
const limit = simpleLimit(1000)
|
|
111
|
+
const promises = sliced.map((slice, i) => limit(async () => {
|
|
89
112
|
const now = new Date()
|
|
90
113
|
return traccar.axios.post(url, {
|
|
91
114
|
from,
|
|
@@ -112,6 +135,7 @@ async function createZoneReport (from, to, userData, traccar) {
|
|
|
112
135
|
return response.data
|
|
113
136
|
})
|
|
114
137
|
})
|
|
138
|
+
)
|
|
115
139
|
const results = await Promise.all(promises)
|
|
116
140
|
results.forEach(processed => {
|
|
117
141
|
if (processed && processed.length) {
|
|
@@ -128,7 +152,7 @@ async function processDevices (from, to, devices, userData, data) {
|
|
|
128
152
|
const devicesResult = []
|
|
129
153
|
console.log('processDevices', from, to, devices.length)
|
|
130
154
|
for (const d of devices) {
|
|
131
|
-
const alerts = data.alerts.filter(t => t.deviceId === d.id)
|
|
155
|
+
const alerts = data.alerts.filter(t => t && t.deviceId === d.id)
|
|
132
156
|
const deviceRoute = data.route.filter(p => p.deviceId === d.id)
|
|
133
157
|
let zoneInOutData = analyseAlerts(alerts, deviceRoute, userData, from, to, d).filter(d => !userData.onlyWithStop || d.stopped)
|
|
134
158
|
|