fleetmap-reports 1.0.823 → 1.0.825
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
CHANGED
package/src/events-report.js
CHANGED
|
@@ -9,6 +9,7 @@ const { devicesToProcess } = require('./util/device')
|
|
|
9
9
|
const { isInside } = require('./util/timetable')
|
|
10
10
|
const { getDigitalPortValue } = require('./location-report')
|
|
11
11
|
const { maxParallelRequests } = require('./automaticReports')
|
|
12
|
+
const { getNearestPOI } = require('./util/geofence')
|
|
12
13
|
|
|
13
14
|
const fileName = 'EventReport'
|
|
14
15
|
|
|
@@ -82,6 +83,10 @@ async function processDevices (from, to, devices, data, traccar, userData) {
|
|
|
82
83
|
for (const a of deviceAlerts) {
|
|
83
84
|
a.position = positions.find(p => p.id === a.positionId)
|
|
84
85
|
|
|
86
|
+
if (!a.geofenceId) {
|
|
87
|
+
const poi = getNearestPOI(a.position, userData.geofences)
|
|
88
|
+
a.geofenceId = poi && poi.p.id
|
|
89
|
+
}
|
|
85
90
|
if (a.geofenceId) {
|
|
86
91
|
const geofence = userData.geofences.find(g => g.id === a.geofenceId)
|
|
87
92
|
if (geofence) {
|
|
@@ -6,6 +6,11 @@ const { convertToFeature, convertPositionToFeature } = require('../util/utils')
|
|
|
6
6
|
function calculateLastStopTime (stopTime, to, time) {
|
|
7
7
|
return stopTime + (to.getTime() - new Date(time).getTime())
|
|
8
8
|
}
|
|
9
|
+
|
|
10
|
+
function calculateFirstStopTime (stopTime, from, time) {
|
|
11
|
+
return stopTime + (new Date(time).getTime() - from.getTime())
|
|
12
|
+
}
|
|
13
|
+
|
|
9
14
|
async function createActivityReport (from, to, userData, traccarInstance) {
|
|
10
15
|
const unauthorizedGeofences = []
|
|
11
16
|
const authorizedGeofences = []
|
|
@@ -72,14 +72,4 @@ describe('activity report', function () {
|
|
|
72
72
|
console.log(device)
|
|
73
73
|
assert.equal(device.summary.reduce((a, b) => a + b.convertedSpentFuel, 0), 168.79999999999995)
|
|
74
74
|
}, 800000)
|
|
75
|
-
it('Activity test performance', async () => {
|
|
76
|
-
const report = await getReports('q.trans', 'quality1214')
|
|
77
|
-
const userData = await report.getUserData()
|
|
78
|
-
console.log(userData)
|
|
79
|
-
userData.groupByDay = true
|
|
80
|
-
const data = await report.activityReport(new Date(2023, 7, 1, 0, 0, 0, 0),
|
|
81
|
-
new Date(2023, 31, 5, 23, 59, 59, 0),
|
|
82
|
-
userData)
|
|
83
|
-
assert.equal(data.length, 1)
|
|
84
|
-
}, 8000000)
|
|
85
75
|
})
|
package/src/tests/events.test.js
CHANGED
|
@@ -12,4 +12,16 @@ describe('events', function () {
|
|
|
12
12
|
userData)
|
|
13
13
|
console.log('result', result)
|
|
14
14
|
}, 4000000)
|
|
15
|
+
|
|
16
|
+
it('works with pois', async () => {
|
|
17
|
+
const report = await getReports(process.env.USER_NOGARTEL, process.env.PASS_NOGARTEL)
|
|
18
|
+
const userData = await report.getUserData()
|
|
19
|
+
userData.devices = userData.devices.filter(d => d.name === 'EPA5I95')
|
|
20
|
+
userData.eventTypes = ['ignitionOn']
|
|
21
|
+
const result = await report.eventsReport(
|
|
22
|
+
new Date(Date.UTC(2023, 8, 11, 0, 0, 0, 0)),
|
|
23
|
+
new Date(Date.UTC(2023, 8, 11, 23, 59, 59, 0)),
|
|
24
|
+
userData)
|
|
25
|
+
console.log('result', result)
|
|
26
|
+
}, 4000000)
|
|
15
27
|
})
|
package/src/tests/index.js
CHANGED
|
@@ -16,7 +16,7 @@ axiosCookieJarSupport(axios)
|
|
|
16
16
|
|
|
17
17
|
const getReports = async (email, password) => {
|
|
18
18
|
try {
|
|
19
|
-
console.log('email / pass', process.env.email, process.env.password)
|
|
19
|
+
console.log('email / pass', process.env.email || email, process.env.password || password)
|
|
20
20
|
await new SessionApi(traccarConfig, null, axios).sessionPost(email || process.env.email, password || process.env.password)
|
|
21
21
|
return new Index(traccarConfig, axios, cookieJar)
|
|
22
22
|
} catch (e) {
|
package/src/tests/zones.test.js
CHANGED
|
@@ -32,18 +32,6 @@ describe('zones', function () {
|
|
|
32
32
|
console.log('result', result)
|
|
33
33
|
}, 4000000)
|
|
34
34
|
|
|
35
|
-
it('works with afriquia', async () => {
|
|
36
|
-
const report = await getReports(process.env.USER_AFRIQUIA, process.env.PASS_AFRIQUIA)
|
|
37
|
-
const userData = await report.getUserData()
|
|
38
|
-
console.log(userData.devices.length)
|
|
39
|
-
console.log(userData.geofences)
|
|
40
|
-
const result = await report.zoneReport(
|
|
41
|
-
new Date(Date.UTC(2023, 5, 11, 0, 0, 0, 0)),
|
|
42
|
-
new Date(Date.UTC(2023, 5, 11, 23, 59, 59, 0)),
|
|
43
|
-
userData)
|
|
44
|
-
console.log('result', result)
|
|
45
|
-
}, 4000000)
|
|
46
|
-
|
|
47
35
|
// eslint-disable-next-line no-undef
|
|
48
36
|
it('works with casais', async () => {
|
|
49
37
|
const report = await getReports(process.env.USER_CASAIS, process.env.PASS_CASAIS)
|
package/src/util/geofence.js
CHANGED
|
@@ -16,7 +16,8 @@ exports.insideGeofence = function insideGeofence (position, geofence) {
|
|
|
16
16
|
return inside.default(pt, poly)
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
exports.
|
|
19
|
+
exports.getNearestPOI = (position, geofences) => getNearestPOIs(position.longitude, position.latitude, geofences)[0]
|
|
20
|
+
function getNearestPOIs (long, lat, geofences) {
|
|
20
21
|
const distance = geofences
|
|
21
22
|
.filter(g => g && g.area.startsWith('CIRCLE'))
|
|
22
23
|
.map(g => {
|
|
@@ -29,6 +30,7 @@ exports.getNearestPOIs = function getNearestPOIs (long, lat, geofences) {
|
|
|
29
30
|
})
|
|
30
31
|
return distance.filter(a => a.distance < 100).sort((a, b) => (a.distance > b.distance) ? 1 : -1)
|
|
31
32
|
}
|
|
33
|
+
exports.getNearestPOIs = getNearestPOIs
|
|
32
34
|
|
|
33
35
|
exports.loadGroupsData = async function loadGroupsData (userData, traccarInstance) {
|
|
34
36
|
for (const g of userData.groups) {
|