fleetmap-reports 2.0.99 → 2.0.101
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 +1 -73
- package/src/partnerReports/gpsjump-report.js +0 -3
- package/src/speeding-report.js +5 -7
- package/src/tests/kms.test.js +1 -2
- package/src/tests/speeding.test.js +14 -0
- package/src/tests/zones.test.js +0 -17
- package/src/util/geofence.js +1 -1
- package/src/util/utils.js +1 -1
- package/RapportPerformance.xlsx +0 -0
- package/src/partnerReports/delayedstart-report.js +0 -92
- package/src/partnerReports/passenger-report.js +0 -46
- package/src/tests/dailyuse.test.js +0 -19
- package/src/tests/gpsjump.test.js +0 -23
package/package.json
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
const traccarHelper = require('../util/traccar')
|
|
2
2
|
const { isInsideTimetable } = require('../util/trips')
|
|
3
|
-
const { convertFromUTCDate
|
|
3
|
+
const { convertFromUTCDate } = require('../util/utils')
|
|
4
4
|
const automaticReports = require('../automaticReports')
|
|
5
|
-
const jsPDF = require('jspdf')
|
|
6
|
-
const { getStyle } = require('../reportStyle')
|
|
7
|
-
const { getUserPartner } = require('fleetmap-partners')
|
|
8
|
-
const { addTable, headerFromUser } = require('../util/pdfDocument')
|
|
9
5
|
|
|
10
6
|
async function createDailyUseReport (from, to, userData, traccar) {
|
|
11
7
|
const reportData = []
|
|
@@ -81,72 +77,4 @@ function processDeviceData (allInOne, d, userData) {
|
|
|
81
77
|
}
|
|
82
78
|
}
|
|
83
79
|
|
|
84
|
-
async function exportDailyUseReportToPDF (userData, reportData) {
|
|
85
|
-
const translations = getTranslations(userData)
|
|
86
|
-
const timezone = userData.user.attributes.timezone
|
|
87
|
-
const lang = userData.user.attributes.lang || (isClientSide() && navigator.language)
|
|
88
|
-
|
|
89
|
-
const headers = [
|
|
90
|
-
translations.report.vehicle,
|
|
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'
|
|
104
|
-
]
|
|
105
|
-
|
|
106
|
-
const data = []
|
|
107
|
-
reportData.forEach(d => {
|
|
108
|
-
const row = [
|
|
109
|
-
d.device,
|
|
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)
|
|
123
|
-
]
|
|
124
|
-
data.push(row)
|
|
125
|
-
})
|
|
126
|
-
|
|
127
|
-
const doc = new jsPDF.jsPDF('l')
|
|
128
|
-
await headerFromUser(doc, 'Rapport de Performance', userData.user)
|
|
129
|
-
const style = getStyle(getUserPartner(userData.user))
|
|
130
|
-
|
|
131
|
-
const footValues = []
|
|
132
|
-
|
|
133
|
-
doc.setFontSize(11)
|
|
134
|
-
doc.text(new Date(userData.from).toLocaleString() + ' - ' + new Date(userData.to).toLocaleString(), 20, 33)
|
|
135
|
-
|
|
136
|
-
style.headerFontSize = 8
|
|
137
|
-
style.bodyFontSize = 7
|
|
138
|
-
const columnStyles = {}
|
|
139
|
-
for (let i = 3; i < 14; i++) {
|
|
140
|
-
columnStyles[i] = { halign: 'right' }
|
|
141
|
-
}
|
|
142
|
-
addTable(doc, headers, data, footValues, style, 40, columnStyles)
|
|
143
|
-
return doc
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
function exportDailyUseReportToExcel (userData, reportData) {
|
|
147
|
-
|
|
148
|
-
}
|
|
149
|
-
|
|
150
80
|
exports.createDailyUseReport = createDailyUseReport
|
|
151
|
-
exports.exportDailyUseReportToPDF = exportDailyUseReportToPDF
|
|
152
|
-
exports.exportDailyUseReportToExcel = exportDailyUseReportToExcel
|
|
@@ -63,6 +63,3 @@ async function exportGPSJumpReportToExcel (userData, reportData) {
|
|
|
63
63
|
exports.createGPSJumpReport = createGPSJumpReport
|
|
64
64
|
exports.exportGPSJumpReportToPDF = exportGPSJumpReportToPDF
|
|
65
65
|
exports.exportGPSJumpReportToExcel = exportGPSJumpReportToExcel
|
|
66
|
-
exports.create = createGPSJumpReport
|
|
67
|
-
exports.exportToPDF = exportGPSJumpReportToPDF
|
|
68
|
-
exports.exportToExcel = exportGPSJumpReportToExcel
|
package/src/speeding-report.js
CHANGED
|
@@ -111,13 +111,13 @@ async function createSpeedingReportByDriver (from, to, userData, traccarInstance
|
|
|
111
111
|
const sliced = automaticReports.sliceArray(devices, 5)
|
|
112
112
|
let deviceCount = 0
|
|
113
113
|
for (const slice of sliced) {
|
|
114
|
-
const
|
|
114
|
+
const eventsByDevice = await getEvents(traccarInstance, from, to, slice, userData, deviceCount, devices.length, slice.length)
|
|
115
115
|
if (processServerSide()) {
|
|
116
116
|
console.log('LOADING_MESSAGE:' + slice[0].name)
|
|
117
117
|
console.log(`PROGRESS_PERC:${deviceCount / devices.length * 100}`)
|
|
118
118
|
}
|
|
119
|
-
if (
|
|
120
|
-
_drivers.push(...(await processDrivers(from, to,
|
|
119
|
+
if (eventsByDevice && eventsByDevice.length > 0) {
|
|
120
|
+
_drivers.push(...(await processDrivers(from, to, eventsByDevice, userData)))
|
|
121
121
|
}
|
|
122
122
|
deviceCount = deviceCount + slice.length
|
|
123
123
|
}
|
|
@@ -193,13 +193,11 @@ function getGeofenceSpeedLimitEvents (geofencesFeatures, routes, devices) {
|
|
|
193
193
|
return events
|
|
194
194
|
}
|
|
195
195
|
|
|
196
|
-
async function processDrivers (from, to,
|
|
196
|
+
async function processDrivers (from, to, eventsByDevice, userData) {
|
|
197
197
|
const driversResult = []
|
|
198
198
|
|
|
199
|
-
findEventsPosition(from, to, userData.devices, events, routes, userData)
|
|
200
|
-
|
|
201
199
|
for (const d of userData.drivers) {
|
|
202
|
-
const driverEvents = await getDriverData(d, { events }, userData).events
|
|
200
|
+
const driverEvents = (await getDriverData(d, { events: eventsByDevice.map(d => d.alerts).flat() }, userData)).events
|
|
203
201
|
if (driverEvents.length > 0) {
|
|
204
202
|
driverEvents.sort((a, b) => a.positionId - b.positionId)
|
|
205
203
|
driversResult.push({
|
package/src/tests/kms.test.js
CHANGED
|
@@ -65,11 +65,10 @@ describe('Kms_Reports', function () {
|
|
|
65
65
|
it('KmsReport by timezone marrocos', async () => {
|
|
66
66
|
const reports = await getReports(process.env.email, process.env.password)
|
|
67
67
|
const userData = await reports.getUserData()
|
|
68
|
-
userData.groupByDay = true
|
|
69
68
|
userData.devices = userData.devices.filter(d => d.id === 93497)
|
|
70
69
|
const data = await reports.kmsReport(convertFromLocal(new Date(2024, 2, 18, 0, 0, 0), userData.user.attributes.timezone), convertFromLocal(new Date(2024, 2, 18, 23, 59, 59), userData.user.attributes.timezone),
|
|
71
70
|
userData)
|
|
72
71
|
const device = data[0].devices.find(d => d.device.id === 93497)
|
|
73
|
-
assert.equal(device
|
|
72
|
+
assert.equal(device, 1)
|
|
74
73
|
}, 3000000)
|
|
75
74
|
})
|
|
@@ -64,6 +64,20 @@ describe('speeding tests', function () {
|
|
|
64
64
|
assert.equal(totalEventTime, 1402000) // Total Duration
|
|
65
65
|
}, 999990000)
|
|
66
66
|
|
|
67
|
+
// eslint-disable-next-line no-undef
|
|
68
|
+
it('Speeding by driver', async () => {
|
|
69
|
+
const report = await getReports(process.env.email, process.env.password)
|
|
70
|
+
const userData = await report.getUserData()
|
|
71
|
+
userData.byDriver = true
|
|
72
|
+
userData.useVehicleSpeedLimit = false
|
|
73
|
+
userData.customSpeed = 60
|
|
74
|
+
const data = await report.speedingReport(
|
|
75
|
+
new Date(Date.UTC(2024, 4, 2, 0, 0, 0, 0)),
|
|
76
|
+
new Date(Date.UTC(2024, 4, 2, 23, 59, 59, 0)),
|
|
77
|
+
userData)
|
|
78
|
+
assert.equal(data.drivers[0].alerts.length, 2) // Total Alerts
|
|
79
|
+
}, 999990000)
|
|
80
|
+
|
|
67
81
|
// eslint-disable-next-line no-undef
|
|
68
82
|
it('detects brazil', () => {
|
|
69
83
|
const p = {
|
package/src/tests/zones.test.js
CHANGED
|
@@ -159,21 +159,4 @@ describe('zones', function () {
|
|
|
159
159
|
console.log(first)
|
|
160
160
|
assert.equal(first.days[6].distanceOut, 867.0554430738234)
|
|
161
161
|
}, 4000000)
|
|
162
|
-
|
|
163
|
-
it('works with casais zones in columns 7', async () => {
|
|
164
|
-
const report = await getReports()
|
|
165
|
-
const userData = await report.getUserData()
|
|
166
|
-
userData.zonesByColumn = true
|
|
167
|
-
userData.devices = userData.devices.filter(d => d.id === 81166)
|
|
168
|
-
userData.geofences = userData.geofences.filter(g => g.name === 'baliza 1 - raio verde ' ||
|
|
169
|
-
g.name === 'baliza 2 - raio amarelo')
|
|
170
|
-
userData.onlyWithKmsOut = false
|
|
171
|
-
const result = await report.zoneReport(
|
|
172
|
-
new Date(Date.UTC(2023, 9, 9, 0, 0, 0, 0)),
|
|
173
|
-
new Date(Date.UTC(2023, 9, 31, 23, 59, 59, 0)),
|
|
174
|
-
userData)
|
|
175
|
-
const first = result[0].devices[0]
|
|
176
|
-
console.log(first)
|
|
177
|
-
assert.equal(first.days[17].distanceOut, 720.7985320478997)
|
|
178
|
-
}, 4000000)
|
|
179
162
|
})
|
package/src/util/geofence.js
CHANGED
|
@@ -19,7 +19,7 @@ exports.insideGeofence = function insideGeofence (position, geofence) {
|
|
|
19
19
|
exports.getNearestPOI = (position, geofences) => getNearestPOIs(position.longitude, position.latitude, geofences)[0]
|
|
20
20
|
function getNearestPOIs (long, lat, geofences) {
|
|
21
21
|
const distance = geofences
|
|
22
|
-
.filter(g => g && g.area.startsWith('CIRCLE'))
|
|
22
|
+
.filter(g => g && g.area && g.area.startsWith('CIRCLE'))
|
|
23
23
|
.map(g => {
|
|
24
24
|
const str = g.area.substring('CIRCLE ('.length, g.area.indexOf(','))
|
|
25
25
|
const radius = g.area.substring(g.area.indexOf(',') + 1, g.area.indexOf(')'))
|
package/src/util/utils.js
CHANGED
|
@@ -19,7 +19,7 @@ exports.getLanguage = (userData) => {
|
|
|
19
19
|
return userData.user.attributes.lang ||
|
|
20
20
|
((typeof navigator !== 'undefined') && navigator.language) ||
|
|
21
21
|
getUserPartner(userData.user).lang ||
|
|
22
|
-
'
|
|
22
|
+
'pt-BR'
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
function convertMS (duration, withSeconds) {
|
package/RapportPerformance.xlsx
DELETED
|
Binary file
|
|
@@ -1,92 +0,0 @@
|
|
|
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
|
-
devices: [],
|
|
10
|
-
from,
|
|
11
|
-
to
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const devices = userData.devices
|
|
15
|
-
|
|
16
|
-
const sliced = automaticReports.sliceArray(devices, 5)
|
|
17
|
-
let deviceCount = 0
|
|
18
|
-
for (const slice of sliced) {
|
|
19
|
-
const allInOne = await traccarHelper.getAllInOne(traccar, from, to, slice, false, true, true, false, deviceCount, devices.length)
|
|
20
|
-
|
|
21
|
-
for (const d of slice) {
|
|
22
|
-
const deviceData = await processDeviceData(from, to, allInOne, d, userData, traccar)
|
|
23
|
-
reportData.devices.push(deviceData)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
deviceCount = deviceCount + slice.length
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return reportData
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function getDelayDescription (startTime, activityStart, lowDelay, mediumDelay, highDelay) {
|
|
33
|
-
return 'Low'
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
async function processDeviceData (from, to, allInOne, d, userData, traccar) {
|
|
37
|
-
const group = userData.groups.find(g => g.id === d.groupId)
|
|
38
|
-
const trips = allInOne.trips.filter(t => t.deviceId === d.id)
|
|
39
|
-
const translations = getTranslations(userData)
|
|
40
|
-
|
|
41
|
-
const weekDays = [
|
|
42
|
-
translations.report.sunday,
|
|
43
|
-
translations.report.monday,
|
|
44
|
-
translations.report.tuesday,
|
|
45
|
-
translations.report.wednesday,
|
|
46
|
-
translations.report.thursday,
|
|
47
|
-
translations.report.friday,
|
|
48
|
-
translations.report.saturday
|
|
49
|
-
]
|
|
50
|
-
|
|
51
|
-
const dates = getDates(from, to, userData.user.attributes.timezone || getUserPartner(userData.user).timezone)
|
|
52
|
-
|
|
53
|
-
const days = []
|
|
54
|
-
for (const date of dates) {
|
|
55
|
-
const { tripsByDay } = await getDataByDay(d, date, { trips }, userData, traccar)
|
|
56
|
-
|
|
57
|
-
if (tripsByDay.length > 0) {
|
|
58
|
-
const startTime = tripsByDay[0].startTime
|
|
59
|
-
const endTime = tripsByDay[tripsByDay.length].endTime
|
|
60
|
-
|
|
61
|
-
const deviceDayData = {
|
|
62
|
-
device: d.name,
|
|
63
|
-
licensePlate: d.attributes.license_plate,
|
|
64
|
-
group: group ? group.name : '',
|
|
65
|
-
driver: '',
|
|
66
|
-
weekDay: weekDays[new Date(date).getDay()],
|
|
67
|
-
startTime: startTime,
|
|
68
|
-
delayDescription: getDelayDescription(startTime, userData.activityStart, userData.lowDelay, userData.mediumDelay, userData.highDelay),
|
|
69
|
-
endTime: endTime
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
days.push(deviceDayData)
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
return {
|
|
77
|
-
device: d,
|
|
78
|
-
days
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
async function exportDelayedStartReportToPDF (userData, reportData) {
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
async function exportDelayedStartReportToExcel (userData, reportData) {
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
exports.create = createDelayedStartReport
|
|
91
|
-
exports.exportToPDF = exportDelayedStartReportToPDF
|
|
92
|
-
exports.exportToExcel = exportDelayedStartReportToExcel
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
async function createPassengerReport (from, to, userData, traccar) {
|
|
2
|
-
//const allDevices = await traccar.axios.get('/devices').then(d => d.data)
|
|
3
|
-
const devices = userData.devices
|
|
4
|
-
const drivers = await traccar.axios.get('/drivers').then(d => d.data)
|
|
5
|
-
const groups = await traccar.axios.get('/groups').then(d => d.data)
|
|
6
|
-
await Promise.all(groups.map(async g => {
|
|
7
|
-
const driversByGroup = await traccar.axios.get(`/drivers?groupId=${g.id}`).then(d => d.data)
|
|
8
|
-
driversByGroup.forEach(d => {
|
|
9
|
-
const _driver = drivers.find(a => a.id === d.id)
|
|
10
|
-
if (_driver) {
|
|
11
|
-
_driver.groupName = g.name
|
|
12
|
-
}
|
|
13
|
-
})
|
|
14
|
-
}))
|
|
15
|
-
const eventsUrl = `/reports/events?${devices.map(d => 'deviceId=' + d.id).join('&')
|
|
16
|
-
}&from=${from.toISOString()
|
|
17
|
-
}&to=${to.toISOString()
|
|
18
|
-
}`
|
|
19
|
-
const positionsUrl = `/reports/route?${devices.map(d => 'deviceId=' + d.id).join('&')
|
|
20
|
-
}&from=${from.toISOString()
|
|
21
|
-
}&to=${to.toISOString()
|
|
22
|
-
}`
|
|
23
|
-
const events = await traccar.axios.get(eventsUrl).then(d => d.data)
|
|
24
|
-
const positions = await traccar.axios.get(positionsUrl).then(d => d.data)
|
|
25
|
-
events.forEach(e => {
|
|
26
|
-
delete e.attributes
|
|
27
|
-
const driver = getDriver(e, positions, drivers)
|
|
28
|
-
const position = positions.find(p => p.id === e.positionId)
|
|
29
|
-
e.deviceName = devices.find(d => d.id === e.deviceId).name
|
|
30
|
-
e.groupName = driver.groupName || ''
|
|
31
|
-
e.fixtime = position && new Date(position.fixTime)
|
|
32
|
-
e.notes = driver && driver.attributes.notes
|
|
33
|
-
e.driverName = (driver && driver.name) || (position && position.attributes.driverUniqueId)
|
|
34
|
-
})
|
|
35
|
-
return events
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function getDriver (event, positions, drivers) {
|
|
39
|
-
const p = positions.find(p => p.id === event.positionId)
|
|
40
|
-
if (!p) { return '' }
|
|
41
|
-
const d = drivers.find(d => d.uniqueId === p.attributes.driverUniqueId)
|
|
42
|
-
if (!d) { return '' }
|
|
43
|
-
return d
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
exports.createPassengerReport = createPassengerReport
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
const { getReports } = require('./index')
|
|
2
|
-
const assert = require('assert')
|
|
3
|
-
const { createDailyUseReport } = require('../partnerReports/dailyuse-report')
|
|
4
|
-
|
|
5
|
-
describe('dailyuse', function () {
|
|
6
|
-
// eslint-disable-next-line no-undef
|
|
7
|
-
it('dailyuse report', async () => {
|
|
8
|
-
const report = await getReports()
|
|
9
|
-
const userData = await report.getUserData()
|
|
10
|
-
|
|
11
|
-
const data = await createDailyUseReport(
|
|
12
|
-
new Date(Date.UTC(2023, 10, 1, 0, 0, 0, 0)),
|
|
13
|
-
new Date(Date.UTC(2023, 10, 6, 23, 59, 59, 0)),
|
|
14
|
-
userData,
|
|
15
|
-
report.traccar)
|
|
16
|
-
console.log(data)
|
|
17
|
-
assert.equal(data[0].consumption, 19.799999999999997)
|
|
18
|
-
}, 8000000)
|
|
19
|
-
})
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
const { getReports } = require('./index')
|
|
2
|
-
const assert = require('assert')
|
|
3
|
-
const { convertMS } = require('../util/utils')
|
|
4
|
-
const { createGPSJumpReport } = require('../partnerReports/gpsjump-report')
|
|
5
|
-
|
|
6
|
-
// eslint-disable-next-line no-undef
|
|
7
|
-
describe('gpsjump', function () {
|
|
8
|
-
// eslint-disable-next-line no-undef
|
|
9
|
-
it('gpsjump report', async () => {
|
|
10
|
-
const report = await getReports()
|
|
11
|
-
const userData = await report.getUserData()
|
|
12
|
-
userData.devices = userData.devices.filter(d => d.id === 22326)
|
|
13
|
-
const data = await createGPSJumpReport(
|
|
14
|
-
new Date(Date.UTC(2023, 6, 1, 0, 0, 0, 0)),
|
|
15
|
-
new Date(Date.UTC(2023, 6, 17, 23, 59, 59, 0)),
|
|
16
|
-
userData,
|
|
17
|
-
report.traccar)
|
|
18
|
-
console.log(data)
|
|
19
|
-
assert.equal(data[0].consumption, 19.799999999999997)
|
|
20
|
-
assert.equal(data[0].distance, 326.7657)
|
|
21
|
-
assert.equal(convertMS(data[1].time * 1000, false), '08:19')
|
|
22
|
-
}, 8000000)
|
|
23
|
-
})
|