fleetmap-reports 1.0.652 → 1.0.653
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 +1 -1
- package/src/zone-report.js +41 -40
package/package.json
CHANGED
package/src/zone-report.js
CHANGED
|
@@ -83,9 +83,10 @@ async function createZoneReport (from, to, userData, traccar) {
|
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
function getNextIn (outDate, alerts, geofenceId, deviceRoute) {
|
|
86
|
-
|
|
86
|
+
const next = alerts
|
|
87
87
|
.filter(a => a.type === 'geofenceEnter' && a.geofenceId === geofenceId)
|
|
88
|
-
.find(a => new Date(a.position.fixTime).getTime() > outDate)
|
|
88
|
+
.find(a => new Date(a.position.fixTime).getTime() > outDate)
|
|
89
|
+
return (next && next.position && new Date(next.position.fixTime).getTime()) ||
|
|
89
90
|
new Date(deviceRoute.slice(-1)[0].fixTime).getTime()
|
|
90
91
|
}
|
|
91
92
|
|
|
@@ -101,45 +102,45 @@ async function processDevices (from, to, devices, userData, data) {
|
|
|
101
102
|
const zoneInData = {}
|
|
102
103
|
|
|
103
104
|
alerts.forEach(a => {
|
|
104
|
-
if (a.position) {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
105
|
+
if (!a.position) { return }
|
|
106
|
+
if (a.type === 'geofenceEnter') {
|
|
107
|
+
const driver = userData.drivers.find(d => a.position.attributes && d.uniqueId === a.position.attributes.driverUniqueId)
|
|
108
|
+
a.position.driverName = driver ? driver.name : ''
|
|
109
|
+
zoneInData[a.geofenceId] = a
|
|
110
|
+
} else if (a.type === 'geofenceExit') {
|
|
111
|
+
const geofence = userData.geofences.find(g => g.id === a.geofenceId)
|
|
112
|
+
if (!geofence) { return }
|
|
113
|
+
const outDate = new Date(a.position.fixTime).getTime()
|
|
114
|
+
const routeAfterOut = deviceRoute.filter(p =>
|
|
115
|
+
new Date(p.fixTime).getTime() >= outDate &&
|
|
116
|
+
new Date(p.fixTime).getTime() < getNextIn(outDate, alerts, a.geofenceId, deviceRoute)
|
|
117
|
+
)
|
|
118
|
+
const distanceOut = calculateDistance(routeAfterOut)
|
|
119
|
+
if (zoneInData[a.geofenceId]) {
|
|
120
|
+
const totalInTime = moment(a.position.fixTime).diff(moment(zoneInData[a.geofenceId].position.fixTime), 'seconds')
|
|
121
|
+
const inDate = new Date(zoneInData[a.geofenceId].position.fixTime).getTime()
|
|
122
|
+
const routeIn = deviceRoute.filter(p =>
|
|
123
|
+
new Date(p.fixTime).getTime() >= inDate &&
|
|
122
124
|
new Date(p.fixTime).getTime() < outDate
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
}
|
|
125
|
+
)
|
|
126
|
+
zoneInOutData.push({
|
|
127
|
+
inTime: zoneInData[a.geofenceId].position,
|
|
128
|
+
outTime: a.position,
|
|
129
|
+
totalTime: totalInTime,
|
|
130
|
+
distanceIn: calculateDistance(routeIn),
|
|
131
|
+
distanceOut,
|
|
132
|
+
geofenceName: geofence.name,
|
|
133
|
+
stopped: routeIn.filter(p => !p.attributes.ignition).length > 0,
|
|
134
|
+
driverName: zoneInData[a.geofenceId].position.driverName
|
|
135
|
+
})
|
|
136
|
+
zoneInData[a.geofenceId] = null
|
|
137
|
+
} else {
|
|
138
|
+
zoneInOutData.push({
|
|
139
|
+
outTime: a.position,
|
|
140
|
+
geofenceName: geofence.name,
|
|
141
|
+
driverName: '',
|
|
142
|
+
distanceOut
|
|
143
|
+
})
|
|
143
144
|
}
|
|
144
145
|
}
|
|
145
146
|
})
|