fleetmap-reports 1.0.648 → 1.0.650
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 +3 -3
- package/src/tests/index.test.js +1 -1
- package/src/tests/trips.test.js +2 -2
- package/src/util/utils.js +5 -1
- package/src/zone-report.js +23 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fleetmap-reports",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.650",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
"eslint-plugin-import": "^2.26.0",
|
|
35
35
|
"eslint-plugin-node": "^11.1.0",
|
|
36
36
|
"eslint-plugin-promise": "^6.0.0",
|
|
37
|
-
"jest": "^
|
|
38
|
-
"mocha": "^
|
|
37
|
+
"jest": "^27.5.0",
|
|
38
|
+
"mocha": "^9.0.3",
|
|
39
39
|
"webpack": "^5.24.3",
|
|
40
40
|
"webpack-cli": "^4.5.0"
|
|
41
41
|
}
|
package/src/tests/index.test.js
CHANGED
|
@@ -363,7 +363,7 @@ describe('Test_Reports', function () {
|
|
|
363
363
|
assert.equal(device.geofences[0].outTime.fixTime, '2022-04-26T07:47:35.000+0000')
|
|
364
364
|
assert.equal(device.geofences[0].totalTime, '28777')
|
|
365
365
|
assert.equal(device.geofences[0].geofenceName, 'Casa João')
|
|
366
|
-
},
|
|
366
|
+
}, 990000)
|
|
367
367
|
// eslint-disable-next-line no-undef
|
|
368
368
|
it('Zone Report With Stops', async () => {
|
|
369
369
|
const report = await getReports()
|
package/src/tests/trips.test.js
CHANGED
|
@@ -6,10 +6,10 @@ describe('trips', function () {
|
|
|
6
6
|
userData.roadSpeedLimits = false
|
|
7
7
|
userData.customSpeed = false
|
|
8
8
|
userData.useVehicleSpeedLimit = true
|
|
9
|
-
|
|
9
|
+
await report.tripReport(
|
|
10
10
|
new Date(Date.UTC(2022, 9, 22, 0, 0, 0, 0)),
|
|
11
11
|
new Date(Date.UTC(2022, 9, 22, 23, 59, 59, 0)),
|
|
12
12
|
userData)
|
|
13
|
-
await report.tripReportToPDF(userData, data)
|
|
13
|
+
// await report.tripReportToPDF(userData, data)
|
|
14
14
|
}, 40000)
|
|
15
15
|
})
|
package/src/util/utils.js
CHANGED
|
@@ -235,10 +235,14 @@ exports.getLogo = (user) => {
|
|
|
235
235
|
exports.convertToFeature = convertToFeature
|
|
236
236
|
exports.convertPositionToFeature = convertPositionToFeature
|
|
237
237
|
exports.calculateDistance = (positions) => {
|
|
238
|
-
return positions
|
|
238
|
+
return positions
|
|
239
|
+
.sort((a, b) => new Date(a.fixTime).getTime() - new Date(b.fixTime).getTime())
|
|
240
|
+
.map(p => [p.longitude, p.latitude])
|
|
239
241
|
.reduce((previousValue, currentValue, currentIndex, array) => {
|
|
240
242
|
return currentIndex < array.length - 1
|
|
241
243
|
? previousValue + distance.default(currentValue, array[currentIndex + 1])
|
|
242
244
|
: previousValue
|
|
243
245
|
}, 0) || 0
|
|
244
246
|
}
|
|
247
|
+
|
|
248
|
+
exports.sortPositions = (a, b) => new Date(a).getTime() - new Date(b).getTime()
|
package/src/zone-report.js
CHANGED
|
@@ -2,7 +2,8 @@ const moment = require('moment')
|
|
|
2
2
|
const automaticReports = require('./automaticReports')
|
|
3
3
|
const {
|
|
4
4
|
convertMS, convertToLocaleString, getTranslations, convertToFeature, convertPositionToFeature,
|
|
5
|
-
calculateDistance
|
|
5
|
+
calculateDistance,
|
|
6
|
+
sortPositions
|
|
6
7
|
} = require('./util/utils')
|
|
7
8
|
const jsPDF = require('jspdf')
|
|
8
9
|
require('jspdf-autotable')
|
|
@@ -88,6 +89,13 @@ async function createZoneReport (from, to, userData, traccar) {
|
|
|
88
89
|
return reportData
|
|
89
90
|
}
|
|
90
91
|
|
|
92
|
+
function getNextIn(outDate, alerts, geofenceId, deviceRoute) {
|
|
93
|
+
return alerts
|
|
94
|
+
.filter(a => a.type === 'geofenceEnter' && a.geofenceId === geofenceId)
|
|
95
|
+
.find(a => new Date(a.position.fixTime).getTime() > outDate) ||
|
|
96
|
+
new Date(deviceRoute.slice(-1)[0].fixTime).getTime()
|
|
97
|
+
}
|
|
98
|
+
|
|
91
99
|
async function processDevices (from, to, devices, userData, data) {
|
|
92
100
|
const devicesResult = []
|
|
93
101
|
|
|
@@ -109,16 +117,25 @@ async function processDevices (from, to, devices, userData, data) {
|
|
|
109
117
|
const geofence = userData.geofences.find(g => g.id === a.geofenceId)
|
|
110
118
|
if (zoneInData[a.geofenceId]) {
|
|
111
119
|
const totalInTime = moment(a.position.fixTime).diff(moment(zoneInData[a.geofenceId].position.fixTime), 'seconds')
|
|
112
|
-
const
|
|
113
|
-
|
|
120
|
+
const inDate = new Date(zoneInData[a.geofenceId].position.fixTime).getTime()
|
|
121
|
+
const outDate = new Date(a.position.fixTime).getTime()
|
|
122
|
+
const routeIn = deviceRoute.filter(p =>
|
|
123
|
+
new Date(p.fixTime).getTime() >= inDate &&
|
|
124
|
+
new Date(p.fixTime).getTime() < outDate
|
|
125
|
+
)
|
|
126
|
+
const routeAfterOut = deviceRoute.filter(p =>
|
|
127
|
+
new Date(p.fixTime).getTime() >= outDate &&
|
|
128
|
+
new Date(p.fixTime).getTime() < getNextIn(outDate, alerts, a.geofenceId, deviceRoute)
|
|
129
|
+
)
|
|
114
130
|
if (geofence) {
|
|
115
131
|
zoneInOutData.push({
|
|
116
132
|
inTime: zoneInData[a.geofenceId].position,
|
|
117
133
|
outTime: a.position,
|
|
118
134
|
totalTime: totalInTime,
|
|
119
|
-
|
|
135
|
+
distanceIn: calculateDistance(routeIn),
|
|
136
|
+
distanceOut: calculateDistance(routeAfterOut),
|
|
120
137
|
geofenceName: geofence.name,
|
|
121
|
-
stopped:
|
|
138
|
+
stopped: routeIn.filter(p => !p.attributes.ignition).length > 0,
|
|
122
139
|
driverName: zoneInData[a.geofenceId].position.driverName
|
|
123
140
|
})
|
|
124
141
|
}
|
|
@@ -170,7 +187,7 @@ function getInAndOutEvents (devices, route, userData) {
|
|
|
170
187
|
devices.forEach(d => {
|
|
171
188
|
const deviceRoute = route.filter(p => p.deviceId === d.id)
|
|
172
189
|
|
|
173
|
-
const routePoints = deviceRoute.map(p => convertPositionToFeature(p))
|
|
190
|
+
const routePoints = deviceRoute.sort(sortPositions).map(p => convertPositionToFeature(p))
|
|
174
191
|
const geofencesFeatures = userData.geofences.map(g => convertToFeature(g))
|
|
175
192
|
|
|
176
193
|
const entryMap = []
|