fleetmap-reports 1.0.977 → 1.0.979
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/partnerReports/dailyuse-report.js +30 -36
- package/src/partnerReports/delayedstart-report.js +69 -0
- package/src/speeding-report.js +2 -2
- package/src/stop-report.js +28 -16
- package/src/tests/activity.test.js +2 -2
- package/src/tests/performance.test.js +6 -48
- package/src/tests/zones.test.js +11 -0
- package/src/zone-report.js +7 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const traccarHelper = require('../util/traccar')
|
|
2
2
|
const { isInsideTimetable } = require('../util/trips')
|
|
3
|
-
const { convertFromUTCDate, getTranslations, convertMS } = require('../util/utils')
|
|
3
|
+
const { convertFromUTCDate, getTranslations, convertMS, convertToLocaleTimeString, isClientSide } = require('../util/utils')
|
|
4
4
|
const automaticReports = require('../automaticReports')
|
|
5
5
|
const jsPDF = require('jspdf')
|
|
6
6
|
const { getStyle } = require('../reportStyle')
|
|
@@ -83,49 +83,43 @@ function processDeviceData (allInOne, d, userData) {
|
|
|
83
83
|
|
|
84
84
|
async function exportDailyUseReportToPDF (userData, reportData) {
|
|
85
85
|
const translations = getTranslations(userData)
|
|
86
|
+
const timezone = userData.user.attributes.timezone
|
|
87
|
+
const lang = userData.user.attributes.lang || (isClientSide() && navigator.language)
|
|
86
88
|
|
|
87
89
|
const headers = [
|
|
88
90
|
translations.report.vehicle,
|
|
89
|
-
'
|
|
90
|
-
'
|
|
91
|
-
'
|
|
92
|
-
'
|
|
93
|
-
'
|
|
94
|
-
'
|
|
95
|
-
'
|
|
96
|
-
'
|
|
97
|
-
'
|
|
98
|
-
'
|
|
99
|
-
'
|
|
100
|
-
'
|
|
101
|
-
'
|
|
102
|
-
'Tour moteur élevé',
|
|
103
|
-
'Accéleration brusque (Sum)',
|
|
104
|
-
'Freinage brusque (Sum)',
|
|
105
|
-
'Virages brusque'
|
|
91
|
+
'Immatriculation',
|
|
92
|
+
'Groupe',
|
|
93
|
+
'Matin départ',
|
|
94
|
+
'Matin arrêt',
|
|
95
|
+
'Matin temps',
|
|
96
|
+
'Déjeuner',
|
|
97
|
+
'Après-midi départ',
|
|
98
|
+
'Après-midi arrêt',
|
|
99
|
+
'Après-midi temps',
|
|
100
|
+
'Total temps',
|
|
101
|
+
'Total conduit',
|
|
102
|
+
'Total arrêts',
|
|
103
|
+
'Total kms'
|
|
106
104
|
]
|
|
107
105
|
|
|
108
106
|
const data = []
|
|
109
107
|
reportData.forEach(d => {
|
|
110
108
|
const row = [
|
|
111
109
|
d.device,
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
d.
|
|
116
|
-
d.
|
|
117
|
-
d.
|
|
118
|
-
d.
|
|
119
|
-
|
|
120
|
-
d.
|
|
121
|
-
d.
|
|
122
|
-
convertMS(d.
|
|
123
|
-
d.
|
|
124
|
-
d.
|
|
125
|
-
convertMS(d.highEngineRPM * 1000),
|
|
126
|
-
d.hardAcceleration,
|
|
127
|
-
d.hardBraking,
|
|
128
|
-
d.hardCornering
|
|
110
|
+
d.licensePlate,
|
|
111
|
+
d.group,
|
|
112
|
+
convertToLocaleTimeString(d.morningStart, lang, timezone, userData.user),
|
|
113
|
+
convertToLocaleTimeString(d.morningEnd, lang, timezone, userData.user),
|
|
114
|
+
convertMS(d.morningTime),
|
|
115
|
+
convertMS(d.lunch),
|
|
116
|
+
convertToLocaleTimeString(d.afternoonStart, lang, timezone, userData.user),
|
|
117
|
+
convertToLocaleTimeString(d.afternoonEnd, lang, timezone, userData.user),
|
|
118
|
+
convertMS(d.afternoonTime),
|
|
119
|
+
convertMS(d.totalTime),
|
|
120
|
+
convertMS(d.totalDrivingTime),
|
|
121
|
+
d.totalStops,
|
|
122
|
+
(d.totalDistance / 100).toFixed(1)
|
|
129
123
|
]
|
|
130
124
|
data.push(row)
|
|
131
125
|
})
|
|
@@ -142,7 +136,7 @@ async function exportDailyUseReportToPDF (userData, reportData) {
|
|
|
142
136
|
style.headerFontSize = 8
|
|
143
137
|
style.bodyFontSize = 7
|
|
144
138
|
const columnStyles = {}
|
|
145
|
-
for (let i =
|
|
139
|
+
for (let i = 3; i < 14; i++) {
|
|
146
140
|
columnStyles[i] = { halign: 'right' }
|
|
147
141
|
}
|
|
148
142
|
addTable(doc, headers, data, footValues, style, 40, columnStyles)
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
const automaticReports = require('../automaticReports')
|
|
2
|
+
const traccarHelper = require('../util/traccar')
|
|
3
|
+
const { getDates, getTranslations } = require('../util/utils')
|
|
4
|
+
const { getUserPartner } = require('fleetmap-partners')
|
|
5
|
+
const { getDataByDay } = require('../util/trips')
|
|
6
|
+
|
|
7
|
+
async function createDelayedStartReport (from, to, userData, traccar) {
|
|
8
|
+
const reportData = []
|
|
9
|
+
|
|
10
|
+
const devices = userData.devices
|
|
11
|
+
|
|
12
|
+
const sliced = automaticReports.sliceArray(devices, 5)
|
|
13
|
+
let deviceCount = 0
|
|
14
|
+
for (const slice of sliced) {
|
|
15
|
+
const allInOne = await traccarHelper.getAllInOne(traccar, from, to, slice, false, true, true, false, deviceCount, devices.length)
|
|
16
|
+
|
|
17
|
+
for (const d of slice) {
|
|
18
|
+
const deviceData = await processDeviceData(from, to, allInOne, d, userData, traccar)
|
|
19
|
+
reportData.push(deviceData)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
deviceCount = deviceCount + slice.length
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return reportData
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async function processDeviceData (from, to, allInOne, d, userData, traccar) {
|
|
29
|
+
const group = userData.groups.find(g => g.id === d.groupId)
|
|
30
|
+
const trips = allInOne.trips.filter(t => t.deviceId === d.id)
|
|
31
|
+
const translations = getTranslations(userData)
|
|
32
|
+
|
|
33
|
+
const weekDays = [
|
|
34
|
+
translations.report.sunday,
|
|
35
|
+
translations.report.monday,
|
|
36
|
+
translations.report.tuesday,
|
|
37
|
+
translations.report.wednesday,
|
|
38
|
+
translations.report.thursday,
|
|
39
|
+
translations.report.friday,
|
|
40
|
+
translations.report.saturday
|
|
41
|
+
]
|
|
42
|
+
|
|
43
|
+
const dates = getDates(from, to, userData.user.attributes.timezone || getUserPartner(userData.user).timezone)
|
|
44
|
+
|
|
45
|
+
const deviceData = {
|
|
46
|
+
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
for (const date of dates) {
|
|
50
|
+
const { tripsByDay } = await getDataByDay(d, date, { trips }, userData, traccar)
|
|
51
|
+
|
|
52
|
+
if (tripsByDay.length > 0) {
|
|
53
|
+
const startTime = tripsByDay[0].startTime
|
|
54
|
+
const stopTime = tripsByDay[tripsByDay.length].endTime
|
|
55
|
+
|
|
56
|
+
const deviceDayData = {
|
|
57
|
+
device: d.name,
|
|
58
|
+
licensePlate: d.attributes.license_plate,
|
|
59
|
+
group: group ? group.name : '',
|
|
60
|
+
driver: '',
|
|
61
|
+
weekDay: weekDays[new Date(date).getDay()],
|
|
62
|
+
startDate: '',
|
|
63
|
+
startTime: '',
|
|
64
|
+
delayDescription: '',
|
|
65
|
+
stopTime: ''
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
package/src/speeding-report.js
CHANGED
|
@@ -366,13 +366,13 @@ async function invokeValhalla (route, i, chunk, country, threshold, results, ret
|
|
|
366
366
|
console.log(e.message, 'retry:', retry)
|
|
367
367
|
return invokeValhalla(route, i, chunk, country, threshold, results, retry)
|
|
368
368
|
} else {
|
|
369
|
-
console.error(e.message, e.response && e.response.data, slice[0])
|
|
369
|
+
console.error(e.message, e.response && e.response.data, 'deviceId', slice[0] && slice[0].deviceId, slice[0] && slice[0].address)
|
|
370
370
|
}
|
|
371
371
|
}
|
|
372
372
|
}
|
|
373
373
|
|
|
374
374
|
async function getOSMSpeedingEvents (devices, routes, threshold, minimumMinutes = 0, country) {
|
|
375
|
-
const chunk =
|
|
375
|
+
const chunk = 500
|
|
376
376
|
const events = []
|
|
377
377
|
for (const d of devices) {
|
|
378
378
|
const route = routes.filter(r => r.deviceId === d.id)
|
package/src/stop-report.js
CHANGED
|
@@ -57,33 +57,45 @@ function processDevices (from, to, devices, data, userData) {
|
|
|
57
57
|
const route = data.route.filter(t => t.deviceId === d.id)
|
|
58
58
|
|
|
59
59
|
deviceStops.forEach(stop => {
|
|
60
|
+
stop.stopDuration = calculateStopDuration(stop)
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
if (deviceStops.length && route.length && !route[0].attributes.ignition) {
|
|
64
|
+
deviceStops[0].startTime = undefined
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const filteredStops = deviceStops.filter(s => s.stopDuration > (userData.minimumStopMinutes ? userData.minimumStopMinutes * 60 * 1000 : 0))
|
|
68
|
+
|
|
69
|
+
filteredStops.forEach(stop => {
|
|
70
|
+
const routeInsideGeofence = route.filter(p =>
|
|
71
|
+
new Date(p.fixTime).getTime() >= new Date(stop.startTime).getTime() &&
|
|
72
|
+
new Date(p.fixTime).getTime() <= new Date(stop.endTime).getTime())
|
|
73
|
+
|
|
60
74
|
const nearestPOIs = getNearestPOIs(stop.longitude, stop.latitude, userData.geofences)
|
|
61
75
|
if (nearestPOIs.length > 0) {
|
|
62
76
|
stop.endPOIName = nearestPOIs[0].p.name
|
|
63
77
|
}
|
|
64
78
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
79
|
+
routeInsideGeofence.every(p => {
|
|
80
|
+
const geofence = userData.geofences.filter(g => g && g.area.startsWith('POLYGON')).find(g =>
|
|
81
|
+
insideGeofence({ latitude: p.latitude, longitude: p.longitude }, g)
|
|
82
|
+
)
|
|
83
|
+
if (geofence) {
|
|
84
|
+
const group = userData.groups.find(g => g.geofenceIds && g.geofenceIds.includes(geofence.id))
|
|
85
|
+
stop.geofenceName = geofence.name
|
|
86
|
+
stop.geofenceGroup = (group && group.name) || ''
|
|
87
|
+
return false
|
|
88
|
+
}
|
|
89
|
+
return true
|
|
90
|
+
})
|
|
75
91
|
})
|
|
76
92
|
|
|
77
|
-
if (
|
|
78
|
-
if (route.length && !route[0].attributes.ignition) {
|
|
79
|
-
deviceStops[0].startTime = undefined
|
|
80
|
-
}
|
|
81
|
-
|
|
93
|
+
if (filteredStops.length > 0) {
|
|
82
94
|
const deviceData = {
|
|
83
95
|
device: d,
|
|
84
96
|
from,
|
|
85
97
|
to,
|
|
86
|
-
stops:
|
|
98
|
+
stops: filteredStops
|
|
87
99
|
}
|
|
88
100
|
|
|
89
101
|
devicesResult.push(deviceData)
|
|
@@ -35,8 +35,8 @@ describe('activity report', function () {
|
|
|
35
35
|
const report = await getReports()
|
|
36
36
|
const userData = await report.getUserData()
|
|
37
37
|
userData.groupByDay = true
|
|
38
|
-
const data = await report.activityReport(new Date(
|
|
39
|
-
new Date(
|
|
38
|
+
const data = await report.activityReport(new Date(2022, 0, 1, 0, 0, 0, 0),
|
|
39
|
+
new Date(2022, 0, 20, 23, 59, 59, 0),
|
|
40
40
|
userData)
|
|
41
41
|
assert.equal(data.length, 1)
|
|
42
42
|
const device = data[0].devices.find(d => d.device.id === 22326)
|
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
const { getReports } = require('./index')
|
|
2
|
-
const { createPerformanceReport
|
|
2
|
+
const { createPerformanceReport } = require('../partnerReports/performance-report')
|
|
3
3
|
const assert = require('assert')
|
|
4
4
|
const { convertMS } = require('../util/utils')
|
|
5
|
-
const xlsx = require('@jcardus/json-as-xlsx')
|
|
6
|
-
const { createActivityReport } = require('../activity-report')
|
|
7
|
-
const { createFuelConsumptionReport } = require('../fuelconsumption-report')
|
|
8
|
-
const { createPassengerReport } = require('../partnerReports/passenger-report')
|
|
9
|
-
|
|
10
5
|
// eslint-disable-next-line no-undef
|
|
11
6
|
describe('performance', function () {
|
|
12
7
|
// eslint-disable-next-line no-undef
|
|
@@ -20,59 +15,22 @@ describe('performance', function () {
|
|
|
20
15
|
userData,
|
|
21
16
|
report.traccar)
|
|
22
17
|
console.log(data)
|
|
23
|
-
|
|
24
18
|
assert.equal(data[0].consumption, 19.799999999999997)
|
|
25
|
-
assert.equal(data[0].distance, 326.
|
|
26
|
-
assert.equal(convertMS(data[1].time * 1000, false), '08:
|
|
19
|
+
assert.equal(data[0].distance, 326.7657)
|
|
20
|
+
assert.equal(convertMS(data[1].time * 1000, false), '08:19')
|
|
27
21
|
}, 8000000)
|
|
28
22
|
|
|
29
23
|
// eslint-disable-next-line no-undef
|
|
30
24
|
it('performance report inofleet', async () => {
|
|
31
25
|
const report = await getReports()
|
|
32
26
|
const userData = await report.getUserData()
|
|
33
|
-
userData.devices = userData.devices.filter(d => d.id ===
|
|
27
|
+
userData.devices = userData.devices.filter(d => d.id === 69114)
|
|
34
28
|
const data = await createPerformanceReport(
|
|
35
|
-
new Date(Date.UTC(2023,
|
|
36
|
-
new Date(Date.UTC(2023,
|
|
29
|
+
new Date(Date.UTC(2023, 5, 11, 0, 0, 0, 0)),
|
|
30
|
+
new Date(Date.UTC(2023, 6, 11, 23, 59, 59, 0)),
|
|
37
31
|
userData,
|
|
38
32
|
report.traccar)
|
|
39
33
|
console.log(data)
|
|
40
|
-
|
|
41
|
-
const data2 = await createFuelConsumptionReport(
|
|
42
|
-
new Date(Date.UTC(2023, 11, 9, 14, 58, 0, 0)),
|
|
43
|
-
new Date(Date.UTC(2023, 11, 18, 9, 28, 0, 0)),
|
|
44
|
-
userData,
|
|
45
|
-
report.traccar)
|
|
46
|
-
console.log(data2)
|
|
47
|
-
|
|
48
34
|
assert.equal(data[0].consumption, 168.51989999999998)
|
|
49
35
|
}, 8000000)
|
|
50
|
-
|
|
51
|
-
it('performance report export excel', async () => {
|
|
52
|
-
const report = await getReports()
|
|
53
|
-
const userData = await report.getUserData()
|
|
54
|
-
const data = await createPerformanceReport(
|
|
55
|
-
new Date(Date.UTC(2023, 6, 1, 0, 0, 0, 0)),
|
|
56
|
-
new Date(Date.UTC(2023, 6, 17, 23, 59, 59, 0)),
|
|
57
|
-
userData,
|
|
58
|
-
report.traccar)
|
|
59
|
-
console.log(data)
|
|
60
|
-
const excel = exportPerformanceReportToExcel(userData, data)
|
|
61
|
-
xlsx([{
|
|
62
|
-
sheet: 'Sheet1',
|
|
63
|
-
columns: excel.headers,
|
|
64
|
-
content: excel.data
|
|
65
|
-
}], excel.settings)
|
|
66
|
-
}, 8000000)
|
|
67
|
-
|
|
68
|
-
it('passenger report export excel', async () => {
|
|
69
|
-
const report = await getReports()
|
|
70
|
-
const userData = await report.getUserData()
|
|
71
|
-
const data = await createPassengerReport(
|
|
72
|
-
new Date(Date.UTC(2023, 11, 1, 0, 0, 0, 0)),
|
|
73
|
-
new Date(Date.UTC(2023, 11, 20, 23, 59, 59, 0)),
|
|
74
|
-
userData,
|
|
75
|
-
report.traccar)
|
|
76
|
-
console.log(data)
|
|
77
|
-
}, 8000000)
|
|
78
36
|
})
|
package/src/tests/zones.test.js
CHANGED
|
@@ -27,6 +27,17 @@ describe('zones', function () {
|
|
|
27
27
|
console.log('result', result)
|
|
28
28
|
}, 4000000)
|
|
29
29
|
|
|
30
|
+
it('trips between geofences', async () => {
|
|
31
|
+
const report = await getReports(process.env.USER_MOVIFLOTTE, process.env.PASS_MOVIFLOTTE)
|
|
32
|
+
const userData = await report.getUserData()
|
|
33
|
+
userData.tripsBetweenZones = true
|
|
34
|
+
const result = await report.zoneReport(
|
|
35
|
+
new Date(Date.UTC(2024, 0, 8, 0, 0, 0, 0)),
|
|
36
|
+
new Date(Date.UTC(2024, 0, 8, 23, 59, 59, 0)),
|
|
37
|
+
userData)
|
|
38
|
+
console.log('result', result)
|
|
39
|
+
}, 4000000)
|
|
40
|
+
|
|
30
41
|
// eslint-disable-next-line no-undef
|
|
31
42
|
it('works with casais', async () => {
|
|
32
43
|
const report = await getReports(process.env.USER_CASAIS, process.env.PASS_CASAIS)
|
package/src/zone-report.js
CHANGED
|
@@ -307,33 +307,33 @@ function calculateDistanceIn (zoneInOutDayData, deviceRoute, dayRoute, fromByDay
|
|
|
307
307
|
return distanceIn
|
|
308
308
|
}
|
|
309
309
|
|
|
310
|
-
function calculateDistanceOut (zoneInOutDayData, dayRoute,
|
|
310
|
+
function calculateDistanceOut (zoneInOutDayData, dayRoute, fromByDay, toByDay, field, device) {
|
|
311
311
|
if (zoneInOutDayData.length) {
|
|
312
|
-
const dataInsideDay = zoneInOutDayData.filter(z => z.outTime && new Date(z.outTime.fixTime) <
|
|
312
|
+
const dataInsideDay = zoneInOutDayData.filter(z => z.outTime && new Date(z.outTime.fixTime) < toByDay)
|
|
313
313
|
let distanceOut = dataInsideDay.reduce((a, b) => a + (b[field] || 0), 0)
|
|
314
314
|
|
|
315
|
-
if (zoneInOutDayData[0].inTime && new Date(zoneInOutDayData[0].inTime.fixTime) >
|
|
315
|
+
if (zoneInOutDayData[0].inTime && new Date(zoneInOutDayData[0].inTime.fixTime) > fromByDay && (field !== 'distanceOutAny' || zoneInOutDayData[0].anyLastExit)) {
|
|
316
316
|
// Add distanceOut before the first entry
|
|
317
317
|
const routeOut = dayRoute.filter(p =>
|
|
318
318
|
new Date(p.fixTime).getTime() < new Date(zoneInOutDayData[0].inTime.fixTime).getTime() &&
|
|
319
|
-
new Date(p.fixTime).getTime() >=
|
|
319
|
+
new Date(p.fixTime).getTime() >= fromByDay.getTime()
|
|
320
320
|
)
|
|
321
321
|
distanceOut = distanceOut + calculateDistance(routeOut, device.attributes['report.ignoreOdometer'])
|
|
322
322
|
}
|
|
323
323
|
|
|
324
|
-
if (zoneInOutDayData[zoneInOutDayData.length - 1].outTime && new Date(zoneInOutDayData[zoneInOutDayData.length - 1].outTime.fixTime) <
|
|
324
|
+
if (zoneInOutDayData[zoneInOutDayData.length - 1].outTime && new Date(zoneInOutDayData[zoneInOutDayData.length - 1].outTime.fixTime) < toByDay && (field !== 'distanceOutAny' || zoneInOutDayData[zoneInOutDayData.length - 1].anyNextIn)) {
|
|
325
325
|
// Add distanceOut after last exit
|
|
326
326
|
distanceOut = distanceOut - zoneInOutDayData[zoneInOutDayData.length - 1][field]
|
|
327
327
|
const routeOut = dayRoute.filter(p =>
|
|
328
328
|
new Date(p.fixTime) >= new Date(zoneInOutDayData[zoneInOutDayData.length - 1].outTime.fixTime).getTime() &&
|
|
329
|
-
new Date(p.fixTime) <
|
|
329
|
+
new Date(p.fixTime) < toByDay.getTime())
|
|
330
330
|
distanceOut = distanceOut + calculateDistance(routeOut, device.attributes['report.ignoreOdometer'])
|
|
331
331
|
}
|
|
332
332
|
|
|
333
333
|
return distanceOut
|
|
334
334
|
}
|
|
335
335
|
|
|
336
|
-
return calculateDistance(dayRoute.filter(p => new Date(p.fixTime) >=
|
|
336
|
+
return calculateDistance(dayRoute.filter(p => new Date(p.fixTime) >= fromByDay && new Date(p.fixTime) < toByDay), device.attributes['report.ignoreOdometer'])
|
|
337
337
|
}
|
|
338
338
|
|
|
339
339
|
function analyseAlerts (alerts, deviceRoute, userData, from, to, device) {
|