fleetmap-reports 1.0.981 → 1.0.983
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/kms-report.js +22 -9
- package/src/speeding-report.js +4 -7
- package/src/tests/kms.test.js +9 -0
- package/src/tests/speeding.test.js +46 -0
- package/src/util/utils.js +11 -0
- package/src/zone-report.js +27 -10
package/package.json
CHANGED
package/src/kms-report.js
CHANGED
|
@@ -10,9 +10,8 @@ const traccar = require('./util/traccar')
|
|
|
10
10
|
const { getDates, getTranslations, isClientSide, executeServerSide } = require('./util/utils')
|
|
11
11
|
const drivers = require('./util/driver')
|
|
12
12
|
const { isInsideTimetable, isPartialInsideTimetable, calculateTrip, getDataByDay, checkTripsKms, getKms } = require('./util/trips')
|
|
13
|
-
const traccarHelper = require('./util/traccar')
|
|
14
13
|
const { devicesToProcess } = require('./util/device')
|
|
15
|
-
const { getDriverData } = require('./util/driver')
|
|
14
|
+
const { getDriverData, reportByDriver } = require('./util/driver')
|
|
16
15
|
const automaticReports = require('./automaticReports')
|
|
17
16
|
const { getSummaryByDay } = require('./util/traccar')
|
|
18
17
|
|
|
@@ -100,16 +99,30 @@ async function createKmsReportByDevice (from, to, userData, traccarInstance) {
|
|
|
100
99
|
|
|
101
100
|
async function createKmsReportByDriver (from, to, userData, traccarInstance) {
|
|
102
101
|
const devices = await drivers.devicesByDriver(traccarInstance, from, to, userData.drivers, userData.devices)
|
|
103
|
-
console.log(devices.length)
|
|
104
102
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
}
|
|
103
|
+
const results = await reportByDriver(devices, traccarInstance, from, to, userData, processDrivers)
|
|
104
|
+
|
|
105
|
+
const report = { drivers: [] }
|
|
109
106
|
|
|
110
|
-
|
|
107
|
+
results.drivers.forEach(result => {
|
|
108
|
+
const driver = report.drivers.find(d => d.driver.id === result.driver.id)
|
|
109
|
+
if (driver) {
|
|
110
|
+
if (userData.groupByDay) {
|
|
111
|
+
driver.days.forEach(day => {
|
|
112
|
+
const resultDay = result.days.find(d => d.date === day.date)
|
|
113
|
+
if (resultDay) {
|
|
114
|
+
day.kms = day.kms + resultDay.kms
|
|
115
|
+
}
|
|
116
|
+
})
|
|
117
|
+
} else {
|
|
118
|
+
driver.summary.distance = driver.summary.distance + result.summary.distance
|
|
119
|
+
}
|
|
120
|
+
} else {
|
|
121
|
+
report.drivers.push(result)
|
|
122
|
+
}
|
|
123
|
+
})
|
|
111
124
|
|
|
112
|
-
return
|
|
125
|
+
return report
|
|
113
126
|
}
|
|
114
127
|
|
|
115
128
|
async function createKmsReportByGroup (from, to, userData, traccarInstance) {
|
package/src/speeding-report.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
const jsPDF = require('jspdf')
|
|
2
|
-
const {
|
|
2
|
+
const {
|
|
3
|
+
convertMS, convertToLocaleString, convertToFeature, convertPositionToFeature, getTranslations, getLanguage,
|
|
4
|
+
getCountry
|
|
5
|
+
} = require('./util/utils')
|
|
3
6
|
const { headerFromUser, AmiriRegular } = require('./util/pdfDocument')
|
|
4
7
|
require('jspdf-autotable')
|
|
5
8
|
const { getStyle } = require('./reportStyle')
|
|
@@ -15,7 +18,6 @@ const booleanPointInPolygon = require('@turf/boolean-point-in-polygon')
|
|
|
15
18
|
const automaticReports = require('./automaticReports')
|
|
16
19
|
const { default: axios } = require('axios')
|
|
17
20
|
const { getDriverName, getDriverData } = require('./util/driver')
|
|
18
|
-
const crg = require('country-reverse-geocoding').country_reverse_geocoding()
|
|
19
21
|
|
|
20
22
|
const fileName = 'SpeedingReport'
|
|
21
23
|
const eventTypes = ['deviceOverspeed']
|
|
@@ -299,11 +301,6 @@ async function getCustomSpeedLimitEvents (devices, routes, customSpeed) {
|
|
|
299
301
|
return events
|
|
300
302
|
}
|
|
301
303
|
|
|
302
|
-
function getCountry (position) {
|
|
303
|
-
const country = crg.get_country(position.latitude, position.longitude)
|
|
304
|
-
return country && country.code
|
|
305
|
-
}
|
|
306
|
-
|
|
307
304
|
async function getRoadSpeedLimits (devices, routes, threshold, minimumMinutes = 0) {
|
|
308
305
|
const position = routes.find(p => getCountry(p))
|
|
309
306
|
const country = position && getCountry(position)
|
package/src/tests/kms.test.js
CHANGED
|
@@ -52,4 +52,13 @@ describe('Kms_Reports', function () {
|
|
|
52
52
|
assert.equal(device.days.length, 30) // Total Kms
|
|
53
53
|
assert.equal(device.days[29].kms, 136174.93281451002) // Total Kms
|
|
54
54
|
}, 30000)
|
|
55
|
+
it('KmsReport by driver', async () => {
|
|
56
|
+
const reports = await getReports()
|
|
57
|
+
const userData = await reports.getUserData()
|
|
58
|
+
userData.byDriver = true
|
|
59
|
+
console.log(userData.drivers)
|
|
60
|
+
const data = await reports.kmsReport(new Date(2024, 0, 24, 0, 0, 0), new Date(2024, 0, 24, 23, 59, 59),
|
|
61
|
+
userData)
|
|
62
|
+
assert.equal(data.length, 1)
|
|
63
|
+
}, 3000000)
|
|
55
64
|
})
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const { getReports } = require('./index')
|
|
2
2
|
const assert = require('assert')
|
|
3
|
+
const { getCountry } = require('../util/utils')
|
|
3
4
|
|
|
4
5
|
async function getSpeedingReport (report, userData) {
|
|
5
6
|
const data = await report.speedingReport(
|
|
@@ -61,4 +62,49 @@ describe('speeding tests', function () {
|
|
|
61
62
|
assert.equal(totalDistance, 46.64576895855739) // Total Kms
|
|
62
63
|
assert.equal(totalEventTime, 1402000) // Total Duration
|
|
63
64
|
}, 999990000)
|
|
65
|
+
|
|
66
|
+
// eslint-disable-next-line no-undef
|
|
67
|
+
it('detects brazil', () => {
|
|
68
|
+
const p = {
|
|
69
|
+
id: 24088423790,
|
|
70
|
+
attributes: {
|
|
71
|
+
door: false,
|
|
72
|
+
hours: 2520745000,
|
|
73
|
+
motion: false,
|
|
74
|
+
distance: 0,
|
|
75
|
+
odometer: 5973617,
|
|
76
|
+
sat: 17,
|
|
77
|
+
battery: 4.03,
|
|
78
|
+
hdop: 0.7,
|
|
79
|
+
idleTime: 0,
|
|
80
|
+
output: 0,
|
|
81
|
+
input: 0,
|
|
82
|
+
driverUniqueId: '',
|
|
83
|
+
power: 12.61,
|
|
84
|
+
event: 0,
|
|
85
|
+
totalDistance: 31419705.27,
|
|
86
|
+
ignition: false,
|
|
87
|
+
adc3: 0,
|
|
88
|
+
adc2: 0,
|
|
89
|
+
status: 61,
|
|
90
|
+
tripTime: 0
|
|
91
|
+
},
|
|
92
|
+
deviceId: 28097,
|
|
93
|
+
type: null,
|
|
94
|
+
protocol: 'startek',
|
|
95
|
+
serverTime: '2024-01-20T03:01:50.000+00:00',
|
|
96
|
+
deviceTime: '2024-01-20T03:01:50.000+00:00',
|
|
97
|
+
fixTime: '2024-01-20T03:01:50.000+00:00',
|
|
98
|
+
outdated: false,
|
|
99
|
+
valid: true,
|
|
100
|
+
latitude: -22.295906,
|
|
101
|
+
longitude: -48.576135,
|
|
102
|
+
altitude: 579,
|
|
103
|
+
speed: 0,
|
|
104
|
+
course: 80,
|
|
105
|
+
address: 'Avenida Deputado Zien Nassif, 938, Vila Industrial, Jaú - SP, 17204-212, Brazil',
|
|
106
|
+
accuracy: 0
|
|
107
|
+
}
|
|
108
|
+
assert.equal('BRA', getCountry(p))
|
|
109
|
+
})
|
|
64
110
|
})
|
package/src/util/utils.js
CHANGED
|
@@ -298,3 +298,14 @@ exports.getLogoUrl = getLogoUrl
|
|
|
298
298
|
exports.convertFromUTCDate = (value, user) => {
|
|
299
299
|
return convertFromUTC(value, user.attributes.timezone || getUserPartner(user).timezone)
|
|
300
300
|
}
|
|
301
|
+
|
|
302
|
+
const crg = require('country-reverse-geocoding').country_reverse_geocoding()
|
|
303
|
+
|
|
304
|
+
exports.getCountry = (position) => {
|
|
305
|
+
const country = crg.get_country(position.latitude, position.longitude)
|
|
306
|
+
if (!country) {
|
|
307
|
+
const country = position && position.attributes.address && position.attributes.address.split(',').slice(-1)[0].trim()
|
|
308
|
+
return { Brazil: 'BRA' }[country]
|
|
309
|
+
}
|
|
310
|
+
return country && country.code
|
|
311
|
+
}
|
package/src/zone-report.js
CHANGED
|
@@ -94,7 +94,7 @@ async function processDevices (from, to, devices, userData, data) {
|
|
|
94
94
|
for (const d of devices) {
|
|
95
95
|
const alerts = data.alerts.filter(t => t.deviceId === d.id)
|
|
96
96
|
const deviceRoute = data.route.filter(p => p.deviceId === d.id)
|
|
97
|
-
|
|
97
|
+
let zoneInOutData = analyseAlerts(alerts, deviceRoute, userData, from, to, d).filter(d => !userData.onlyWithStop || d.stopped)
|
|
98
98
|
|
|
99
99
|
if (userData.groupByDay || userData.zonesByColumn) {
|
|
100
100
|
const dates = getDates(from, to, userData.user.attributes.timezone)
|
|
@@ -191,18 +191,35 @@ async function processDevices (from, to, devices, userData, data) {
|
|
|
191
191
|
if (zoneInOutData.length > 0) {
|
|
192
192
|
if (userData.tripsBetweenZones) {
|
|
193
193
|
const tripsBetweenZones = []
|
|
194
|
-
zoneInOutData.
|
|
195
|
-
|
|
194
|
+
zoneInOutData = zoneInOutData.sort((a, b) => a.inTime && b.inTime && new Date(a.inTime.fixTime).getTime() - new Date(b.inTime.fixTime).getTime())
|
|
195
|
+
let outGeofence
|
|
196
|
+
let inGeofence
|
|
197
|
+
for (let i = 0; i < zoneInOutData.length - 1; i++) {
|
|
198
|
+
if (!outGeofence) {
|
|
199
|
+
outGeofence = zoneInOutData[i]
|
|
200
|
+
}
|
|
201
|
+
inGeofence = zoneInOutData[i + 1]
|
|
202
|
+
|
|
203
|
+
if (outGeofence.outTime &&
|
|
204
|
+
inGeofence.inTime &&
|
|
205
|
+
new Date(outGeofence.outTime.fixTime).getTime() < new Date(inGeofence.inTime.fixTime).getTime()) {
|
|
196
206
|
tripsBetweenZones.push({
|
|
197
|
-
outTime:
|
|
198
|
-
outGeofenceName:
|
|
199
|
-
inTime:
|
|
200
|
-
inGeofenceName:
|
|
201
|
-
distanceOut:
|
|
202
|
-
totalOutTime: new Date(
|
|
207
|
+
outTime: outGeofence.outTime,
|
|
208
|
+
outGeofenceName: outGeofence.geofenceName,
|
|
209
|
+
inTime: inGeofence.inTime,
|
|
210
|
+
inGeofenceName: inGeofence.geofenceName,
|
|
211
|
+
distanceOut: outGeofence.distanceOutAny,
|
|
212
|
+
totalOutTime: new Date(inGeofence.inTime.fixTime).getTime() - new Date(outGeofence.outTime.fixTime).getTime()
|
|
203
213
|
})
|
|
214
|
+
outGeofence = undefined
|
|
215
|
+
} else {
|
|
216
|
+
if (outGeofence.outTime &&
|
|
217
|
+
inGeofence.outTime &&
|
|
218
|
+
new Date(outGeofence.outTime.fixTime).getTime() <= new Date(inGeofence.outTime.fixTime).getTime()) {
|
|
219
|
+
outGeofence = undefined
|
|
220
|
+
}
|
|
204
221
|
}
|
|
205
|
-
}
|
|
222
|
+
}
|
|
206
223
|
if (tripsBetweenZones.length > 0) {
|
|
207
224
|
devicesResult.push({
|
|
208
225
|
device: d,
|