fleetmap-reports 1.0.491 → 1.0.493

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.491",
3
+ "version": "1.0.493",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -102,20 +102,21 @@ async function createSpeedingReportByDevice (from, to, userData, traccarInstance
102
102
  async function createSpeedingReportByDriver (from, to, userData, traccarInstance) {
103
103
  const devices = await drivers.devicesByDriver(traccarInstance, from, to, userData.drivers, userData.devices)
104
104
  console.log('Devices with driver', devices.length)
105
-
106
- if (!devices.length) {
107
- // empty report
108
- return { drivers: [] }
109
- }
110
-
111
- const { routes, events } = await getEvents(traccarInstance, from, to, devices, userData)
112
-
113
- if (!events.length) {
114
- // empty report
115
- return { drivers: [] }
105
+ const _drivers = []
106
+ const sliced = automaticReports.sliceArray(devices, 10)
107
+ let deviceCount = 0
108
+ for (const slice of sliced) {
109
+ const { routes, events } = await getEvents(traccarInstance, from, to, devices, userData, deviceCount, devices.length, slice.length)
110
+ if (processServerSide()) {
111
+ console.log('LOADING_MESSAGE:' + slice[0].name)
112
+ console.log(`PROGRESS_PERC:${deviceCount / devices.length * 100}`)
113
+ }
114
+ if (events.length > 0) {
115
+ _drivers.push(...(await processDrivers(from, to, events, routes, userData)))
116
+ }
117
+ deviceCount = deviceCount + slice.length
116
118
  }
117
-
118
- return { drivers: await processDrivers(from, to, events, routes, userData) }
119
+ return { drivers: _drivers }
119
120
  }
120
121
 
121
122
  async function getEvents (traccarInstance, from, to, devices, userData, deviceCount, totalDevices, sliceSize) {
@@ -298,7 +299,7 @@ async function getCustomSpeedLimitEvents (devices, routes, customSpeed) {
298
299
  async function getHereEvents (devices, routes, threshold) {
299
300
  try {
300
301
  console.log('env', process.env.PROCESS_HERE_EVENTS)
301
- console.log('here speed limit events')
302
+ console.log('here speed limit events', devices.length, 'devices')
302
303
  const events = []
303
304
  const promises = devices.map(d => new Promise((resolve) => {
304
305
  const positions = routes.filter(p => p.deviceId === d.id)
@@ -307,6 +308,7 @@ async function getHereEvents (devices, routes, threshold) {
307
308
  resolve()
308
309
  }
309
310
  here.routeMatch(positions).then(results => {
311
+ console.log(d.name, 'got', results.length, 'from here')
310
312
  const reduced = results.reduce((acc, cur, idx, src) => {
311
313
  cur.overSpeeding = cur.currentSpeedKmh > parseInt(cur.speedLimit) + (threshold || 0)
312
314
  const last = acc.length && acc.slice(-1)[0]