fleetmap-reports 2.0.35 → 2.0.36

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/util/driver.js +6 -13
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fleetmap-reports",
3
- "version": "2.0.35",
3
+ "version": "2.0.36",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -6,20 +6,13 @@ const { isInsideTimetable, isPartialInsideTimetable } = require('./trips')
6
6
  // get devices used by each driver between two dates
7
7
  async function devicesByDriver (traccarInstance, from, to, drivers, devices) {
8
8
  const eventsData = await traccar.getEvents(traccarInstance, from, to, devices, ['driverChanged'])
9
- const deviceIds = []
10
- const driversIds = []
11
- for (const d of drivers) {
12
- const events = eventsData.filter(e => {
13
- return !d.uniqueId.localeCompare(e.attributes.driverUniqueId, undefined, { sensitivity: 'base' })
14
- })
15
-
16
- if (events.length) {
17
- driversIds.push(d.id)
18
- }
9
+ const driverUniqueIdsToProcess = new Set(eventsData.map(e => e.attributes.driverUniqueId))
10
+ const driversToProcess = drivers.filter(d => driverUniqueIdsToProcess.has(d.uniqueId))
19
11
 
20
- deviceIds.push(...events.map(e => e.deviceId))
21
- }
22
- return { devices: devices.filter(d => deviceIds.includes(d.id)), drivers: drivers.filter(d => driversIds.includes(d.id)) }
12
+ const deviceIdsToProcess = new Set(eventsData.map(e => e.deviceId))
13
+ const devicesToProcess = devices.filter(d => deviceIdsToProcess.has(d.id))
14
+
15
+ return { devices: devicesToProcess, drivers: driversToProcess }
23
16
  }
24
17
 
25
18
  async function reportByDriver (devices, traccar, from, to, userData, processor, allInOneData = { route: true, trips: true, stops: true, summary: false }) {