fleetmap-reports 1.0.622 → 1.0.623

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.622",
3
+ "version": "1.0.623",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -1,16 +1,24 @@
1
1
  const traccar = require('../util/traccar')
2
+ const { getIdleEvents } = require('../util/route')
2
3
 
3
4
  async function createActivityReport (from, to, userData, traccarInstance) {
4
- const allInOne = await traccar.getAllInOne(traccarInstance, from, to, userData.devices, false, true, true, false)
5
+ const allInOne = await traccar.getAllInOne(traccarInstance, from, to, userData.devices, true, true, true, false)
5
6
 
6
7
  const reportData = []
7
8
  userData.devices.forEach(d => {
8
9
  const trips = allInOne.trips.filter(t => t.deviceId === d.id)
10
+ const route = allInOne.route.filter(p => p.deviceId === d.id)
9
11
  const stops = allInOne.stops.filter(s => s.deviceId === d.id)
10
12
  const group = userData.groups.find(g => g.id === d.groupId)
11
13
 
14
+ const idleEvents = getIdleEvents(route)
15
+
12
16
  const totalDistance = trips.reduce((a, b) => a + b.distance, 0)
13
17
  const idleTime = stops.reduce((a, b) => a + b.engineHours, 0)
18
+ const drivingTime = trips.reduce((a, b) => a + b.duration, 0)
19
+ const stopTime = stops.reduce((a, b) => a + b.duration, 0) - idleTime
20
+
21
+ const idleTimeArray = idleEvents.map(e => e.idleTime)
14
22
 
15
23
  const deviceData = {
16
24
  device: d.name,
@@ -19,10 +27,16 @@ async function createActivityReport (from, to, userData, traccarInstance) {
19
27
  startTime: trips.length ? trips[0].startTime : '',
20
28
  endAddress: trips.length ? trips[trips.length - 1].endAddress : '',
21
29
  endTime: trips.length ? trips[trips.length - 1].endTime : '',
22
- drivingTime: trips.reduce((a, b) => a + b.duration, 0),
23
- stopTime: stops.reduce((a, b) => a + b.duration, 0) - idleTime,
24
- idleTime,
30
+ drivingTime,
31
+ stopTime,
32
+ idleTime: idleEvents.reduce((a, b) => a + b.idleTime, 0),
25
33
  distance: totalDistance,
34
+ totalIdleEvents: idleEvents.length,
35
+ minIdleEvent: Math.max(...idleTimeArray),
36
+ maxIdleEvent: Math.min(...idleTimeArray),
37
+ authorizedStops: 0,
38
+ unauthorizedStops: 0,
39
+ authorizedStopsTime: 0,
26
40
  averageSpeed: totalDistance > 0 ? ((trips.reduce((a, b) => a + (b.averageSpeed * b.distance), 0)) / totalDistance) : 0,
27
41
  maxSpeed: trips.reduce((a, b) => {
28
42
  return a > b.maxSpeed ? a : b.maxSpeed