fleetmap-reports 1.0.648 → 1.0.649
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 +32 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fleetmap-reports",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.649",
|
|
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')
|
|
@@ -87,6 +88,19 @@ async function createZoneReport (from, to, userData, traccar) {
|
|
|
87
88
|
|
|
88
89
|
return reportData
|
|
89
90
|
}
|
|
91
|
+
function getPreviousOut(inDate, alerts, geofenceId, deviceRoute) {
|
|
92
|
+
return alerts
|
|
93
|
+
.filter(a => a.type === 'geofenceExit' && a.geofenceId === geofenceId)
|
|
94
|
+
.find(a => new Date(a.position.fixTime).getTime() < inDate) ||
|
|
95
|
+
new Date(deviceRoute[0].fixTime).getTime()
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function getNextIn(outDate, alerts, geofenceId, deviceRoute) {
|
|
99
|
+
return alerts
|
|
100
|
+
.filter(a => a.type === 'geofenceEnter' && a.geofenceId === geofenceId)
|
|
101
|
+
.find(a => new Date(a.position.fixTime).getTime() > outDate) ||
|
|
102
|
+
new Date(deviceRoute.slice(-1)[0].fixTime).getTime()
|
|
103
|
+
}
|
|
90
104
|
|
|
91
105
|
async function processDevices (from, to, devices, userData, data) {
|
|
92
106
|
const devicesResult = []
|
|
@@ -109,16 +123,28 @@ async function processDevices (from, to, devices, userData, data) {
|
|
|
109
123
|
const geofence = userData.geofences.find(g => g.id === a.geofenceId)
|
|
110
124
|
if (zoneInData[a.geofenceId]) {
|
|
111
125
|
const totalInTime = moment(a.position.fixTime).diff(moment(zoneInData[a.geofenceId].position.fixTime), 'seconds')
|
|
112
|
-
const
|
|
113
|
-
|
|
126
|
+
const inDate = new Date(zoneInData[a.geofenceId].position.fixTime).getTime()
|
|
127
|
+
const outDate = new Date(a.position.fixTime).getTime()
|
|
128
|
+
const routeBeforeIn = deviceRoute.filter(p =>
|
|
129
|
+
new Date(p.fixTime).getTime() >= getPreviousOut(inDate, alerts, a.geofenceId, deviceRoute) &&
|
|
130
|
+
new Date(p.fixTime).getTime() < inDate)
|
|
131
|
+
const routeIn = deviceRoute.filter(p =>
|
|
132
|
+
new Date(p.fixTime).getTime() >= inDate &&
|
|
133
|
+
new Date(p.fixTime).getTime() < outDate
|
|
134
|
+
)
|
|
135
|
+
const routeAfterOut = deviceRoute.filter(p =>
|
|
136
|
+
new Date(p.fixTime).getTime() >= outDate &&
|
|
137
|
+
new Date(p.fixTime).getTime() < getNextIn(outDate, alerts, a.geofenceId, deviceRoute)
|
|
138
|
+
)
|
|
114
139
|
if (geofence) {
|
|
115
140
|
zoneInOutData.push({
|
|
116
141
|
inTime: zoneInData[a.geofenceId].position,
|
|
117
142
|
outTime: a.position,
|
|
118
143
|
totalTime: totalInTime,
|
|
119
|
-
|
|
144
|
+
distanceIn: calculateDistance(routeIn),
|
|
145
|
+
distanceOut: calculateDistance(routeBeforeIn) + calculateDistance(routeAfterOut),
|
|
120
146
|
geofenceName: geofence.name,
|
|
121
|
-
stopped:
|
|
147
|
+
stopped: routeIn.filter(p => !p.attributes.ignition).length > 0,
|
|
122
148
|
driverName: zoneInData[a.geofenceId].position.driverName
|
|
123
149
|
})
|
|
124
150
|
}
|
|
@@ -170,7 +196,7 @@ function getInAndOutEvents (devices, route, userData) {
|
|
|
170
196
|
devices.forEach(d => {
|
|
171
197
|
const deviceRoute = route.filter(p => p.deviceId === d.id)
|
|
172
198
|
|
|
173
|
-
const routePoints = deviceRoute.map(p => convertPositionToFeature(p))
|
|
199
|
+
const routePoints = deviceRoute.sort(sortPositions).map(p => convertPositionToFeature(p))
|
|
174
200
|
const geofencesFeatures = userData.geofences.map(g => convertToFeature(g))
|
|
175
201
|
|
|
176
202
|
const entryMap = []
|