fleetmap-reports 1.0.746 → 1.0.748

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fleetmap-reports",
3
- "version": "1.0.746",
3
+ "version": "1.0.748",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -8,6 +8,7 @@ function sliceArray (longArray, size) {
8
8
  const arrayToSlice = longArray.slice()
9
9
 
10
10
  const arrayOfArrays = []
11
+ console.log('slice', arrayToSlice.length, 'in chunks of', size)
11
12
  for (let i = 0; i < arrayToSlice.length; i += size) {
12
13
  arrayOfArrays.push(arrayToSlice.slice(i, i + size))
13
14
  }
@@ -23,19 +23,16 @@ const { parallel } = require('./util/parallel')
23
23
  const fileName = 'TripReport'
24
24
 
25
25
  async function createTripReport (from, to, userData, traccar) {
26
- console.log('Create TripReport')
26
+ console.log('createTripReport', from, to, userData.byDriver ? 'by driver' : userData.byGroup ? 'by group' : 'by device')
27
27
  const reportData = []
28
28
 
29
29
  if (userData.byDriver) {
30
- console.log('ByDriver')
31
30
  const report = await createTripReportByDriver(from, to, userData, traccar)
32
31
  reportData.push(report)
33
32
  } else if (userData.byGroup) {
34
- console.log('ByGroup')
35
33
  const allData = await createTripReportByGroup(from, to, userData, traccar)
36
34
  reportData.push(...allData)
37
35
  } else {
38
- console.log('ByDevice')
39
36
  const report = await createTripReportByDevice(from, to, userData, traccar)
40
37
  reportData.push(report)
41
38
  }
@@ -116,7 +113,7 @@ async function createTripReportByGroup (from, to, userData, traccar) {
116
113
 
117
114
  async function createTripReportByDriver (from, to, userData, traccar) {
118
115
  const devices = await traccar.devices.devicesGet().then(d => d.data)
119
- console.log(devices.length)
116
+ console.log(devices.length, 'devices')
120
117
 
121
118
  if (!devices.length) {
122
119
  // Empty report
@@ -125,9 +122,7 @@ async function createTripReportByDriver (from, to, userData, traccar) {
125
122
 
126
123
  const results = await reportByDriver(devices, traccar, from, to, userData, processDrivers)
127
124
 
128
- const report = {
129
- drivers: []
130
- }
125
+ const report = { drivers: [] }
131
126
 
132
127
  results.drivers.forEach(result => {
133
128
  const driver = report.drivers.find(d => d.driver.id === result.driver.id)
@@ -17,20 +17,15 @@ async function devicesByDriver (traccarInstance, from, to, drivers, devices) {
17
17
  }
18
18
 
19
19
  async function reportByDriver (devices, traccar, from, to, userData, processor) {
20
- const report = {
21
- drivers: []
22
- }
20
+ const report = { drivers: [] }
23
21
 
24
22
  const sliced = automaticReports.sliceArray(devices, 5)
25
23
 
26
24
  let deviceCount = 0
27
25
  for (const slice of sliced) {
28
26
  const allInOne = await traccarHelper.getAllInOne(traccar, from, to, slice, true, true, true, false, deviceCount, devices.length)
29
-
30
27
  const results = await processor(from, to, userData, { trips: allInOne.trips, route: allInOne.route, stops: allInOne.stops })
31
-
32
28
  report.drivers.push(...results)
33
-
34
29
  deviceCount = deviceCount + slice.length
35
30
  }
36
31
 
@@ -7,13 +7,15 @@ exports.parallel = (report, method, toSlice, ...args) => {
7
7
  return new Promise((resolve, reject) => {
8
8
  if (cluster.isPrimary) {
9
9
  console.log('master', process.pid, 'is running', process.cwd(), 'with', numCPUs, 'cpus')
10
- console.log('setupPrimary', cluster.setupPrimary({
11
- exec: path.resolve(__dirname, 'worker.js')
12
- }), __dirname, 'worker.js')
10
+ cluster.setupPrimary({ exec: path.resolve(__dirname, 'worker.js') })
13
11
  const sliced = toSlice.length > (numCPUs - 1) ? sliceArray(toSlice, toSlice.length / (numCPUs - 1)) : toSlice
14
12
  const _result = []
15
13
  let done = 0
16
14
  let workerCount = 0
15
+ if (!sliced.length) {
16
+ console.error(report, method, 'got sliced length', sliced.length, toSlice)
17
+ reject(new Error('0 to process'))
18
+ }
17
19
  sliced.forEach((slice) => {
18
20
  try {
19
21
  console.log('forking worker', workerCount++, report, method, slice)