fleetmap-reports 1.0.636 → 1.0.638

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.636",
3
+ "version": "1.0.638",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -2,6 +2,14 @@ const traccar = require('../util/traccar')
2
2
  const { getIdleEvents } = require('../util/route')
3
3
  const { insideGeofence, getNearestPOIs } = require('../util/geofence')
4
4
 
5
+ function calculateLastStopTime (stopTime, to, time) {
6
+ return stopTime + (to.getTime() - new Date(time).getTime())
7
+ }
8
+
9
+ function calculateFirstStopTime (stopTime, from, time) {
10
+ return stopTime + (new Date(time).getTime(), from.getTime())
11
+ }
12
+
5
13
  async function createActivityReport (from, to, userData, traccarInstance) {
6
14
  const notAuthGroup = userData.groups.find(g => g.name === 'Zones Non Autorisées')
7
15
  const authGroup = userData.groups.find(g => g.name === 'Zones Autorisées')
@@ -38,13 +46,33 @@ async function createActivityReport (from, to, userData, traccarInstance) {
38
46
 
39
47
  const totalDistance = trips.reduce((a, b) => a + b.distance, 0)
40
48
  const drivingTime = trips.reduce((a, b) => a + b.duration, 0)
41
- const stopTime = stops.reduce((a, b) => a + (b.duration > b.engineHours ? (b.duration - b.engineHours) : 0), 0)
49
+ let stopTime = stops.reduce((a, b) => a + (b.duration > b.engineHours ? (b.duration - b.engineHours) : 0), 0)
42
50
 
43
51
  const idleTimeArray = idleEvents.map(e => e.idleTime).filter(a => a > 0)
44
52
 
45
53
  const startTrip = trips.length ? trips[0] : undefined
46
54
  const endTrip = trips.length ? trips[trips.length - 1] : undefined
47
55
 
56
+ /* if (stops.length > 0 && startTrip) {
57
+ if (startTrip.startTime > stops[0].startTime) {
58
+
59
+ }
60
+ }
61
+ stopTime = stopTime + (new Date(startTrip).getTime() - from.getTime())
62
+ */
63
+
64
+ if (endTrip && stops.length > 0) {
65
+ if (endTrip.endTime > stops[stops.length - 1].endTime) {
66
+ stopTime = calculateLastStopTime(stopTime, to, endTrip.endTime)
67
+ } else {
68
+ stopTime = calculateLastStopTime(stopTime, to, stops[stops.length - 1].endTime)
69
+ }
70
+ } else if (!endTrip && stops.length > 0) {
71
+ stopTime = calculateLastStopTime(stopTime, to, stops[stops.length - 1].endTime)
72
+ } if (endTrip && stops.length === 0) {
73
+ stopTime = calculateLastStopTime(stopTime, to, endTrip.endTime)
74
+ }
75
+
48
76
  const startNearestPOIs = startTrip ? getNearestPOIs(startTrip.startLon, startTrip.startLat, userData.geofences) : []
49
77
  const endNearestPOIs = endTrip ? getNearestPOIs(endTrip.endLon, endTrip.endLat, userData.geofences) : []
50
78