fleetmap-reports 1.0.959 → 1.0.961
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/index.js +2 -1
- package/src/tests/zones.test.js +36 -0
- package/src/util/trips.js +9 -6
- package/src/zone-report.js +11 -7
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -18,7 +18,8 @@ function Reports (config, axios, cookieJar) {
|
|
|
18
18
|
groups: await this.traccar.groups.groupsGet().then(d => d.data),
|
|
19
19
|
drivers: await this.traccar.drivers.driversGet().then(d => d.data),
|
|
20
20
|
geofences: await this.traccar.geofences.geofencesGet().then(d => d.data),
|
|
21
|
-
byGroup: false
|
|
21
|
+
byGroup: false,
|
|
22
|
+
dayHours: { startTime: '00:00', endTime: '23:59' }
|
|
22
23
|
}
|
|
23
24
|
}
|
|
24
25
|
this.speedingReport = (from, to, userData) => {
|
package/src/tests/zones.test.js
CHANGED
|
@@ -78,4 +78,40 @@ describe('zones', function () {
|
|
|
78
78
|
console.log(first)
|
|
79
79
|
assert.equal(first.days[0].distanceOut, 554.6037095121401)
|
|
80
80
|
}, 4000000)
|
|
81
|
+
|
|
82
|
+
it('works with casais zones in columns 3', async () => {
|
|
83
|
+
const report = await getReports()
|
|
84
|
+
const userData = await report.getUserData()
|
|
85
|
+
userData.zonesByColumn = true
|
|
86
|
+
userData.devices = userData.devices.filter(d => d.id === 81201)
|
|
87
|
+
userData.geofences = userData.geofences.filter(g => g.name === 'baliza 1 - raio verde ' ||
|
|
88
|
+
g.name === 'baliza 2 - raio amarelo')
|
|
89
|
+
userData.onlyWithKmsOut = false
|
|
90
|
+
const result = await report.zoneReport(
|
|
91
|
+
new Date(Date.UTC(2023, 8, 1, 0, 0, 0, 0)),
|
|
92
|
+
new Date(Date.UTC(2023, 8, 10, 23, 59, 59, 0)),
|
|
93
|
+
userData)
|
|
94
|
+
const first = result[0].devices[0]
|
|
95
|
+
console.log(first)
|
|
96
|
+
assert.equal(first.days[0].distanceOut, 294.0468270741282)
|
|
97
|
+
assert.equal(first.days[1].distanceOut, 35.21209134706803)
|
|
98
|
+
}, 4000000)
|
|
99
|
+
|
|
100
|
+
it('works with casais zones in columns 4', async () => {
|
|
101
|
+
const report = await getReports()
|
|
102
|
+
const userData = await report.getUserData()
|
|
103
|
+
userData.zonesByColumn = true
|
|
104
|
+
userData.devices = userData.devices.filter(d => d.id === 81164)
|
|
105
|
+
userData.geofences = userData.geofences.filter(g => g.name === 'baliza 1 - raio verde ' ||
|
|
106
|
+
g.name === 'baliza 2 - raio amarelo')
|
|
107
|
+
userData.onlyWithKmsOut = false
|
|
108
|
+
const result = await report.zoneReport(
|
|
109
|
+
new Date(Date.UTC(2023, 8, 10, 0, 0, 0, 0)),
|
|
110
|
+
new Date(Date.UTC(2023, 8, 11, 23, 59, 59, 0)),
|
|
111
|
+
userData)
|
|
112
|
+
const first = result[0].devices[0]
|
|
113
|
+
console.log(first)
|
|
114
|
+
assert.equal(first.days[0].distanceOut, 24)
|
|
115
|
+
assert.equal(first.days[1].distanceOut, 0)
|
|
116
|
+
}, 4000000)
|
|
81
117
|
})
|
package/src/util/trips.js
CHANGED
|
@@ -116,12 +116,15 @@ async function getDataByDay (device, date, data, userData, traccarInstance) {
|
|
|
116
116
|
const startDate = isClientSide() ? startDateLocal : convertFromLocal(startDateLocal, userData.user.attributes.timezone)
|
|
117
117
|
const endDate = isClientSide() ? endDateLocal : convertFromLocal(endDateLocal, userData.user.attributes.timezone)
|
|
118
118
|
|
|
119
|
-
const tripsByDay =
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
119
|
+
const tripsByDay = []
|
|
120
|
+
if (data.trips) {
|
|
121
|
+
tripsByDay.concat(data.trips.filter(t => new Date(t.endTime) > startDate && new Date(t.startTime) < endDate).map(t => {
|
|
122
|
+
return { ...t }
|
|
123
|
+
}))
|
|
124
|
+
|
|
125
|
+
for (const t of tripsByDay) {
|
|
126
|
+
await calculatePartialTrip(device, startDate, endDate, data.route, t, traccarInstance)
|
|
127
|
+
}
|
|
125
128
|
}
|
|
126
129
|
|
|
127
130
|
const routeByDay = data.route ? data.route.filter(p => (new Date(p.fixTime) > startDate && new Date(p.fixTime) < endDate)) : []
|
package/src/zone-report.js
CHANGED
|
@@ -20,6 +20,7 @@ const {
|
|
|
20
20
|
} = require('./util/route')
|
|
21
21
|
const { checkGeofenceIn } = require('./util/geofence')
|
|
22
22
|
const { parallel } = require('./util/parallel')
|
|
23
|
+
const { getDataByDay } = require('./util/trips')
|
|
23
24
|
const sliceSize = 100
|
|
24
25
|
const deviceChunk = 5
|
|
25
26
|
const fileName = 'ZoneReport'
|
|
@@ -107,7 +108,8 @@ async function processDevices (from, to, devices, userData, data) {
|
|
|
107
108
|
const fromByDay = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0)
|
|
108
109
|
const toByDay = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 23, 59, 59)
|
|
109
110
|
|
|
110
|
-
const
|
|
111
|
+
const { routeByDay } = await getDataByDay(d, date, { route: deviceRoute }, userData)
|
|
112
|
+
|
|
111
113
|
const zoneInOutDayData = filteredByGeofence.filter(z => (!z.inTime || (new Date(z.inTime.fixTime) < toByDay)) &&
|
|
112
114
|
(!z.outTime || (new Date(z.outTime.fixTime) > fromByDay)))
|
|
113
115
|
|
|
@@ -115,8 +117,8 @@ async function processDevices (from, to, devices, userData, data) {
|
|
|
115
117
|
const lastOut = zoneInOutDayData.slice().reverse().find(z => z.outTime && new Date(z.outTime.fixTime) < toByDay)
|
|
116
118
|
|
|
117
119
|
const timeIn = calculateTimeIn(zoneInOutDayData, fromByDay, from, toByDay, to)
|
|
118
|
-
const distanceIn = calculateDistanceIn(zoneInOutDayData, deviceRoute,
|
|
119
|
-
const distanceOut = calculateDistanceOut(zoneInOutDayData,
|
|
120
|
+
const distanceIn = calculateDistanceIn(zoneInOutDayData, deviceRoute, routeByDay, fromByDay, toByDay, to, d)
|
|
121
|
+
const distanceOut = calculateDistanceOut(zoneInOutDayData, routeByDay, fromByDay, toByDay, 'distanceOut', d)
|
|
120
122
|
|
|
121
123
|
dataByDay.push({
|
|
122
124
|
date,
|
|
@@ -142,10 +144,12 @@ async function processDevices (from, to, devices, userData, data) {
|
|
|
142
144
|
const fromByDay = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0)
|
|
143
145
|
const toByDay = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 23, 59, 59)
|
|
144
146
|
|
|
147
|
+
const { routeByDay } = await getDataByDay(d, date, { route: deviceRoute }, userData)
|
|
148
|
+
|
|
145
149
|
const zoneInOutDayData = zoneInOutData.filter(z => (!z.inTime || (new Date(z.inTime.fixTime) < toByDay)) &&
|
|
146
150
|
(!z.outTime || (new Date(z.outTime.fixTime) > fromByDay)))
|
|
147
151
|
|
|
148
|
-
const distanceOut = calculateDistanceOut(zoneInOutDayData,
|
|
152
|
+
const distanceOut = calculateDistanceOut(zoneInOutDayData, routeByDay, fromByDay, toByDay, 'distanceOutAny', d)
|
|
149
153
|
|
|
150
154
|
const geofences = geofencesData.map(g => {
|
|
151
155
|
const day = g.days.find(day => day.date === date)
|
|
@@ -368,12 +372,12 @@ function analyseAlerts (alerts, deviceRoute, userData, from, to, device) {
|
|
|
368
372
|
let anyNextIn
|
|
369
373
|
let distanceOutAny = 0
|
|
370
374
|
if (zoneInData.length < 2) {
|
|
371
|
-
anyNextIn = getAnyNextIn(outDate, alerts, deviceRoute)
|
|
375
|
+
anyNextIn = getAnyNextIn(outDate, alerts, deviceRoute) || to
|
|
372
376
|
const routeAfterOutAndBeforeAnyNextIn = deviceRoute.filter(p =>
|
|
373
377
|
new Date(p.fixTime).getTime() >= outDate &&
|
|
374
378
|
new Date(p.fixTime).getTime() <= anyNextIn
|
|
375
379
|
)
|
|
376
|
-
distanceOutAny =
|
|
380
|
+
distanceOutAny = Math.round(calculateDistance(routeAfterOutAndBeforeAnyNextIn, device.attributes['report.ignoreOdometer']))
|
|
377
381
|
}
|
|
378
382
|
|
|
379
383
|
const inData = zoneInData.find(z => z.geofenceId === a.geofenceId)
|
|
@@ -399,7 +403,7 @@ function analyseAlerts (alerts, deviceRoute, userData, from, to, device) {
|
|
|
399
403
|
stopped: routeIn.filter(p => !p.attributes.ignition).length > 0,
|
|
400
404
|
driverName: inData.position.driverName
|
|
401
405
|
})
|
|
402
|
-
zoneInData = zoneInData.filter(z => z.geofenceId
|
|
406
|
+
zoneInData = zoneInData.filter(z => z.geofenceId !== a.geofenceId)
|
|
403
407
|
} else {
|
|
404
408
|
const totalInTime = new Date(a.position.fixTime).getTime() - from.getTime()
|
|
405
409
|
const routeIn = deviceRoute.filter(p =>
|