fleetmap-reports 1.0.977 → 1.0.978
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 +0 -21
- package/src/partnerReports/dailyuse-report.js +1 -79
- package/src/speeding-report.js +2 -2
- package/src/tests/activity.test.js +2 -2
- package/src/tests/performance.test.js +6 -48
- package/src/zone-report.js +7 -7
- package/RapportPerformance.xlsx +0 -0
- package/src/partnerReports/passenger-report.js +0 -46
- package/src/temperature-report.js +0 -11
- package/src/tests/dailyuse.test.js +0 -19
- package/src/tests/gpsjump.test.js +0 -23
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -19,7 +19,6 @@ function Reports (config, axios, cookieJar) {
|
|
|
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
21
|
byGroup: false,
|
|
22
|
-
allWeek: true,
|
|
23
22
|
dayHours: { startTime: '00:00', endTime: '23:59' }
|
|
24
23
|
}
|
|
25
24
|
}
|
|
@@ -184,25 +183,5 @@ function Reports (config, axios, cookieJar) {
|
|
|
184
183
|
this.stopReportToExcel = (userData, reportData) => {
|
|
185
184
|
return require('./stop-report').exportStopReportToExcel(userData, reportData)
|
|
186
185
|
}
|
|
187
|
-
|
|
188
|
-
this.performanceReport = (from, to, userData) => {
|
|
189
|
-
return require('./partnerReports/performance-report').createPerformanceReport(from, to, userData, this.traccar)
|
|
190
|
-
}
|
|
191
|
-
this.performanceReportToPDF = (userData, reportData) => {
|
|
192
|
-
return require('./partnerReports/performance-report').exportPerformanceReportToPDF(userData, reportData)
|
|
193
|
-
}
|
|
194
|
-
this.performanceReportToExcel = (userData, reportData) => {
|
|
195
|
-
return require('./partnerReports/performance-report').exportPerformanceReportToExcel(userData, reportData)
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
this.dailyUseReport = (from, to, userData) => {
|
|
199
|
-
return require('./partnerReports/dailyuse-report').createDailyUseReport(from, to, userData, this.traccar)
|
|
200
|
-
}
|
|
201
|
-
this.dailyUseReportToPDF = (userData, reportData) => {
|
|
202
|
-
return require('./partnerReports/dailyuse-report').exportDailyUseReportToPDF(userData, reportData)
|
|
203
|
-
}
|
|
204
|
-
this.dailyUseReportToExcel = (userData, reportData) => {
|
|
205
|
-
return require('./partnerReports/dailyuse-report').exportDailyUseReportToExcel(userData, reportData)
|
|
206
|
-
}
|
|
207
186
|
}
|
|
208
187
|
module.exports = Reports
|
|
@@ -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,78 +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
|
-
|
|
87
|
-
const headers = [
|
|
88
|
-
translations.report.vehicle,
|
|
89
|
-
'Utilisation',
|
|
90
|
-
'Conduite',
|
|
91
|
-
'Ralenti',
|
|
92
|
-
'Totale (L)',
|
|
93
|
-
'Conduite (L)',
|
|
94
|
-
'Ralenti (L)',
|
|
95
|
-
'Conduite (Km)',
|
|
96
|
-
'Économique',
|
|
97
|
-
'Économique (L)',
|
|
98
|
-
'Économique (Km)',
|
|
99
|
-
'Cruise Control',
|
|
100
|
-
'Cruise Control (L)',
|
|
101
|
-
'Cruise Control (Km)',
|
|
102
|
-
'Tour moteur élevé',
|
|
103
|
-
'Accéleration brusque (Sum)',
|
|
104
|
-
'Freinage brusque (Sum)',
|
|
105
|
-
'Virages brusque'
|
|
106
|
-
]
|
|
107
|
-
|
|
108
|
-
const data = []
|
|
109
|
-
reportData.forEach(d => {
|
|
110
|
-
const row = [
|
|
111
|
-
d.device,
|
|
112
|
-
convertMS((d.drivingTime + d.idleTime) * 1000),
|
|
113
|
-
convertMS(d.drivingTime * 1000),
|
|
114
|
-
convertMS(d.idleTime * 1000),
|
|
115
|
-
d.drivingConsumption + d.idleConsumption,
|
|
116
|
-
d.drivingConsumption,
|
|
117
|
-
d.idleConsumption,
|
|
118
|
-
d.drivingDistance.toFixed(2),
|
|
119
|
-
convertMS(d.economicTime * 1000),
|
|
120
|
-
d.economicConsumption.toFixed(1),
|
|
121
|
-
d.economicDistance.toFixed(2),
|
|
122
|
-
convertMS(d.cruiseControlTime * 1000),
|
|
123
|
-
d.cruiseControlConsumption.toFixed(1),
|
|
124
|
-
d.cruiseControlDistance.toFixed(2),
|
|
125
|
-
convertMS(d.highEngineRPM * 1000),
|
|
126
|
-
d.hardAcceleration,
|
|
127
|
-
d.hardBraking,
|
|
128
|
-
d.hardCornering
|
|
129
|
-
]
|
|
130
|
-
data.push(row)
|
|
131
|
-
})
|
|
132
|
-
|
|
133
|
-
const doc = new jsPDF.jsPDF('l')
|
|
134
|
-
await headerFromUser(doc, 'Rapport de Performance', userData.user)
|
|
135
|
-
const style = getStyle(getUserPartner(userData.user))
|
|
136
|
-
|
|
137
|
-
const footValues = []
|
|
138
|
-
|
|
139
|
-
doc.setFontSize(11)
|
|
140
|
-
doc.text(new Date(userData.from).toLocaleString() + ' - ' + new Date(userData.to).toLocaleString(), 20, 33)
|
|
141
|
-
|
|
142
|
-
style.headerFontSize = 8
|
|
143
|
-
style.bodyFontSize = 7
|
|
144
|
-
const columnStyles = {}
|
|
145
|
-
for (let i = 1; i < 18; i++) {
|
|
146
|
-
columnStyles[i] = { halign: 'right' }
|
|
147
|
-
}
|
|
148
|
-
addTable(doc, headers, data, footValues, style, 40, columnStyles)
|
|
149
|
-
return doc
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
function exportDailyUseReportToExcel (userData, reportData) {
|
|
153
|
-
|
|
154
|
-
}
|
|
155
|
-
|
|
156
80
|
exports.createDailyUseReport = createDailyUseReport
|
|
157
|
-
exports.exportDailyUseReportToPDF = exportDailyUseReportToPDF
|
|
158
|
-
exports.exportDailyUseReportToExcel = exportDailyUseReportToExcel
|
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)
|
|
@@ -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/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) {
|
package/RapportPerformance.xlsx
DELETED
|
Binary file
|
|
@@ -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,11 +0,0 @@
|
|
|
1
|
-
const traccarHelper = require('./util/traccar')
|
|
2
|
-
const { devicesToProcess } = require('./util/device')
|
|
3
|
-
|
|
4
|
-
async function createTemperatureReport (from, to, userData, traccar) {
|
|
5
|
-
const devices = devicesToProcess(userData)
|
|
6
|
-
|
|
7
|
-
const allInOne = await traccarHelper.getAllInOne(traccar, from, to, devices, true, false, false, false)
|
|
8
|
-
const routeData = allInOne.route
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
@@ -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
|
-
})
|