fleetmap-reports 1.0.651 → 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/util/device.js +0 -1
- package/src/zone-report.js +41 -43
package/package.json
CHANGED
package/src/util/device.js
CHANGED
|
@@ -2,7 +2,6 @@ function devicesToProcess (userData) {
|
|
|
2
2
|
const groupIds = userData.groups.map(g => g.id)
|
|
3
3
|
const devices = userData.byGroup ? userData.devices.filter(d => !groupIds.includes(d.groupId)) : userData.devices
|
|
4
4
|
devices.sort((a, b) => (a.name > b.name) ? 1 : -1)
|
|
5
|
-
|
|
6
5
|
console.log('LOADING_MESSAGE:' + devices.map(d => d.name).join(', '))
|
|
7
6
|
return devices
|
|
8
7
|
}
|
package/src/zone-report.js
CHANGED
|
@@ -27,7 +27,6 @@ async function createZoneReport (from, to, userData, traccar) {
|
|
|
27
27
|
const url = `https://${process.env.SERVER_HOST}/reports/zone-report`
|
|
28
28
|
return axios.post(url, { from, to, userData }, { withCredentials: true }).then(d => d.data)
|
|
29
29
|
}
|
|
30
|
-
console.log('Create ZoneReport')
|
|
31
30
|
const reportData = []
|
|
32
31
|
const types = ['geofenceEnter', 'geofenceExit']
|
|
33
32
|
|
|
@@ -84,9 +83,10 @@ async function createZoneReport (from, to, userData, traccar) {
|
|
|
84
83
|
}
|
|
85
84
|
|
|
86
85
|
function getNextIn (outDate, alerts, geofenceId, deviceRoute) {
|
|
87
|
-
|
|
86
|
+
const next = alerts
|
|
88
87
|
.filter(a => a.type === 'geofenceEnter' && a.geofenceId === geofenceId)
|
|
89
|
-
.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()) ||
|
|
90
90
|
new Date(deviceRoute.slice(-1)[0].fixTime).getTime()
|
|
91
91
|
}
|
|
92
92
|
|
|
@@ -102,47 +102,45 @@ async function processDevices (from, to, devices, userData, data) {
|
|
|
102
102
|
const zoneInData = {}
|
|
103
103
|
|
|
104
104
|
alerts.forEach(a => {
|
|
105
|
-
if (a.position) {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
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 &&
|
|
118
124
|
new Date(p.fixTime).getTime() < outDate
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
}
|
|
138
|
-
if (geofence) {
|
|
139
|
-
zoneInOutData.push({
|
|
140
|
-
outTime: a.position,
|
|
141
|
-
geofenceName: geofence.name,
|
|
142
|
-
driverName: ''
|
|
143
|
-
})
|
|
144
|
-
}
|
|
145
|
-
}
|
|
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
|
+
})
|
|
146
144
|
}
|
|
147
145
|
}
|
|
148
146
|
})
|