fleetmap-reports 1.0.715 → 1.0.717
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/activity-report.js +20 -5
- package/src/trip-report.js +22 -5
- package/src/util/driver.js +1 -1
- package/src/util/parallel.js +34 -30
package/package.json
CHANGED
package/src/activity-report.js
CHANGED
|
@@ -191,7 +191,9 @@ function processDevices (from, to, devices, data, userData) {
|
|
|
191
191
|
endOdometer: 0,
|
|
192
192
|
startOdometer: 0,
|
|
193
193
|
startTime: tripsByDay.length && tripsByDay[0].startTime,
|
|
194
|
-
|
|
194
|
+
startAddress: tripsByDay.length && tripsByDay[0].startAddress,
|
|
195
|
+
endTime: tripsByDay.length && tripsByDay[tripsByDay.length - 1].endTime,
|
|
196
|
+
endAddress: tripsByDay.length && tripsByDay[tripsByDay.length - 1].endAddress
|
|
195
197
|
})
|
|
196
198
|
}
|
|
197
199
|
} else {
|
|
@@ -204,7 +206,9 @@ function processDevices (from, to, devices, data, userData) {
|
|
|
204
206
|
summaryCurrentDay.distance = distance
|
|
205
207
|
summaryCurrentDay.convertedSpentFuel = automaticReports.calculateSpentFuel(summaryCurrentDay.spentFuel, d)
|
|
206
208
|
summaryCurrentDay.startTime = tripsByDay.length && tripsByDay[0].startTime
|
|
209
|
+
summaryCurrentDay.startAddress = tripsByDay.length && tripsByDay[0].startAddress
|
|
207
210
|
summaryCurrentDay.endTime = tripsByDay.length && tripsByDay[tripsByDay.length - 1].endTime
|
|
211
|
+
summaryCurrentDay.endAddress = tripsByDay.length && tripsByDay[tripsByDay.length - 1].endAddress
|
|
208
212
|
|
|
209
213
|
summary.push(summaryCurrentDay)
|
|
210
214
|
}
|
|
@@ -225,7 +229,9 @@ function processDevices (from, to, devices, data, userData) {
|
|
|
225
229
|
startOdometer: trips.length ? trips[0].startOdometer : 0,
|
|
226
230
|
endOdometer: trips.length ? trips[trips.length - 1].endOdometer : 0,
|
|
227
231
|
startTime: trips.length && trips[0].startTime,
|
|
228
|
-
|
|
232
|
+
startAddress: trips.length && trips[0].startAddress,
|
|
233
|
+
endTime: trips.length && trips[trips.length - 1].endTime,
|
|
234
|
+
endAddress: trips.length && trips[trips.length - 1].endAddress
|
|
229
235
|
})
|
|
230
236
|
} else {
|
|
231
237
|
summary.push(...data.summaries.filter(s => s.deviceId === d.id))
|
|
@@ -236,7 +242,9 @@ function processDevices (from, to, devices, data, userData) {
|
|
|
236
242
|
s.distance = deviceTrips.reduce((a, b) => a + b.distance, 0)
|
|
237
243
|
s.convertedSpentFuel = automaticReports.calculateSpentFuel(s.spentFuel, d)
|
|
238
244
|
s.startTime = deviceTrips.length && deviceTrips[0].startTime
|
|
245
|
+
s.startAddress = deviceTrips.length && deviceTrips[0].startAddress
|
|
239
246
|
s.endTime = deviceTrips.length && deviceTrips[deviceTrips.length - 1].endTime
|
|
247
|
+
s.endAddress = deviceTrips.length && deviceTrips[deviceTrips.length - 1].endAddress
|
|
240
248
|
})
|
|
241
249
|
}
|
|
242
250
|
}
|
|
@@ -246,7 +254,10 @@ function processDevices (from, to, devices, data, userData) {
|
|
|
246
254
|
device: d,
|
|
247
255
|
summary
|
|
248
256
|
}
|
|
249
|
-
|
|
257
|
+
|
|
258
|
+
if ((deviceData.summary.length && deviceData.summary[0].startTime) || !userData.onlyWithActivity) {
|
|
259
|
+
devicesResult.push(deviceData)
|
|
260
|
+
}
|
|
250
261
|
})
|
|
251
262
|
|
|
252
263
|
return devicesResult
|
|
@@ -279,7 +290,9 @@ function processDrivers (from, to, drivers, data, userData) {
|
|
|
279
290
|
maxSpeed: tripsByDay.reduce((a, b) => Math.max(a, b.maxSpeed), 0),
|
|
280
291
|
averageSpeed: tripsByDay.length ? Math.round(tripsByDay.reduce((a, b) => a + b.averageSpeed, 0) / tripsByDay.length) : 0,
|
|
281
292
|
startTime: tripsByDay.length && tripsByDay[0].startTime,
|
|
282
|
-
|
|
293
|
+
startAddress: tripsByDay.length && tripsByDay[0].startAddress,
|
|
294
|
+
endTime: tripsByDay.length && tripsByDay[tripsByDay.length - 1].endTime,
|
|
295
|
+
endAddress: tripsByDay.length && tripsByDay[tripsByDay.length - 1].endAddress
|
|
283
296
|
})
|
|
284
297
|
}
|
|
285
298
|
} else {
|
|
@@ -289,7 +302,9 @@ function processDrivers (from, to, drivers, data, userData) {
|
|
|
289
302
|
maxSpeed: trips.reduce((a, b) => Math.max(a, b.maxSpeed), 0),
|
|
290
303
|
averageSpeed: Math.round(trips.reduce((a, b) => a + b.averageSpeed, 0) / trips.length),
|
|
291
304
|
startTime: trips.length && trips[0].startTime,
|
|
292
|
-
|
|
305
|
+
startAddress: trips.length && trips[0].startAddress,
|
|
306
|
+
endTime: trips.length && trips[trips.length - 1].endTime,
|
|
307
|
+
endAddress: trips.length && trips[trips.length - 1].endAddress
|
|
293
308
|
})
|
|
294
309
|
}
|
|
295
310
|
driversResult.push(driverData)
|
package/src/trip-report.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
const automaticReports = require('./automaticReports')
|
|
2
2
|
const jsPDF = require('jspdf')
|
|
3
|
-
const {
|
|
3
|
+
const {
|
|
4
|
+
convertMS, convertToLocaleString, convertToLocaleDateString, convertToLocaleTimeString, getTranslations,
|
|
5
|
+
isClientSide
|
|
6
|
+
} = require('./util/utils')
|
|
4
7
|
require('jspdf-autotable')
|
|
5
8
|
const { getUserPartner } = require('fleetmap-partners')
|
|
6
9
|
const { headerFromUser, addTable } = require('./util/pdfDocument')
|
|
@@ -12,6 +15,7 @@ const { devicesToProcess, deviceName } = require('./util/device')
|
|
|
12
15
|
const { getIdleEvents } = require('./util/route')
|
|
13
16
|
const { reportByDriver, getDriverName, getDriverData } = require('./util/driver')
|
|
14
17
|
const { getNearestPOIs } = require('./util/geofence')
|
|
18
|
+
const { parallel } = require('./util/parallel')
|
|
15
19
|
|
|
16
20
|
const fileName = 'TripReport'
|
|
17
21
|
|
|
@@ -212,16 +216,29 @@ function processDevices (from, to, devices, data, userData, traccar) {
|
|
|
212
216
|
return devicesResult
|
|
213
217
|
}
|
|
214
218
|
|
|
215
|
-
function
|
|
216
|
-
|
|
219
|
+
function calculateIdleEvents (drivers, route) {
|
|
220
|
+
const idleEvents = []
|
|
221
|
+
drivers.forEach(d => {
|
|
222
|
+
idleEvents.push(...getIdleEvents(route, d))
|
|
223
|
+
})
|
|
224
|
+
return idleEvents
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
async function processDrivers (from, to, userData, data) {
|
|
217
228
|
const driversResult = []
|
|
229
|
+
|
|
230
|
+
const idleEvents = []
|
|
231
|
+
if (isClientSide()) {
|
|
232
|
+
idleEvents.push(...(calculateIdleEvents(userData.drivers, data.route)))
|
|
233
|
+
} else {
|
|
234
|
+
idleEvents.push(...(await parallel('trip-report', 'calculateIdleEvents', userData.drivers, data.route)))
|
|
235
|
+
}
|
|
236
|
+
|
|
218
237
|
userData.drivers.forEach(d => {
|
|
219
238
|
const { route, trips } = getDriverData(d, data)
|
|
220
239
|
const filteredTrips = trips.filter(t => (userData.allWeek || !userData.weekDays || isInsideTimetable(t, userData) || isPartialInsideTimetable(t, userData, route)))
|
|
221
240
|
filteredTrips.sort((a, b) => new Date(a.startTime).getTime() - new Date(b.startTime).getTime())
|
|
222
241
|
|
|
223
|
-
const idleEvents = getIdleEvents(data.route, d)
|
|
224
|
-
|
|
225
242
|
filteredTrips.forEach(function (trip, i) {
|
|
226
243
|
trip.totalKms = trip.distance / 1000
|
|
227
244
|
|
package/src/util/driver.js
CHANGED
|
@@ -27,7 +27,7 @@ async function reportByDriver (devices, traccar, from, to, userData, processor)
|
|
|
27
27
|
for (const slice of sliced) {
|
|
28
28
|
const allInOne = await traccarHelper.getAllInOne(traccar, from, to, slice, true, true, true, false, deviceCount, devices.length)
|
|
29
29
|
|
|
30
|
-
const results = processor(from, to, userData, { trips: allInOne.trips, route: allInOne.route, stops: allInOne.stops })
|
|
30
|
+
const results = await processor(from, to, userData, { trips: allInOne.trips, route: allInOne.route, stops: allInOne.stops })
|
|
31
31
|
|
|
32
32
|
report.drivers.push(...results)
|
|
33
33
|
|
package/src/util/parallel.js
CHANGED
|
@@ -1,37 +1,41 @@
|
|
|
1
1
|
const { sliceArray } = require('../automaticReports')
|
|
2
|
-
const cluster = require('cluster')
|
|
3
2
|
const path = require('path')
|
|
4
3
|
|
|
5
|
-
exports.parallel = (report, method,
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
cluster.
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const _result = []
|
|
15
|
-
let done = 0
|
|
16
|
-
sliced.forEach((_devices) => {
|
|
17
|
-
const worker = cluster.fork()
|
|
18
|
-
worker.send({
|
|
19
|
-
report,
|
|
20
|
-
method,
|
|
21
|
-
args: [_devices, route.filter(p => _devices.find(d => d.id === p.deviceId)), userData]
|
|
4
|
+
exports.parallel = (report, method, toSlice, ...args) => {
|
|
5
|
+
try {
|
|
6
|
+
const cluster = require('cluster')
|
|
7
|
+
const numCPUs = require('os').cpus().length
|
|
8
|
+
return new Promise((resolve) => {
|
|
9
|
+
if (cluster.isPrimary) {
|
|
10
|
+
console.log(`Master ${process.pid} is running`, process.cwd())
|
|
11
|
+
cluster.setupPrimary({
|
|
12
|
+
exec: path.resolve(__dirname, 'worker.js')
|
|
22
13
|
})
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
14
|
+
const sliced = sliceArray(toSlice, numCPUs)
|
|
15
|
+
const _result = []
|
|
16
|
+
let done = 0
|
|
17
|
+
sliced.forEach((slice) => {
|
|
18
|
+
const worker = cluster.fork()
|
|
19
|
+
worker.send({
|
|
20
|
+
report,
|
|
21
|
+
method,
|
|
22
|
+
args: [slice, ...args]
|
|
23
|
+
})
|
|
24
|
+
worker.on('message', ({result}) => {
|
|
25
|
+
console.log('Received result from worker', worker.process.pid)
|
|
26
|
+
_result.push(result)
|
|
27
|
+
if (++done === sliced.length) {
|
|
28
|
+
resolve(_result.flat())
|
|
29
|
+
}
|
|
30
|
+
})
|
|
29
31
|
})
|
|
30
|
-
})
|
|
31
32
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
cluster.on('exit', (worker, code, signal) => {
|
|
34
|
+
console.log('Worker died', worker.process.pid, code, signal)
|
|
35
|
+
})
|
|
36
|
+
}
|
|
37
|
+
})
|
|
38
|
+
} catch (e) {
|
|
39
|
+
console.log('ClientSide')
|
|
40
|
+
}
|
|
37
41
|
}
|