fleetmap-reports 1.0.869 → 1.0.871
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/events-report.js +16 -8
- package/src/partnerReports/afriquia.js +5 -0
- package/src/speeding-report.js +50 -42
- package/src/tests/activity.test.js +0 -10
- package/src/tests/index.test.js +3 -11
- package/src/tests/zones.test.js +0 -12
package/package.json
CHANGED
package/src/events-report.js
CHANGED
|
@@ -4,7 +4,7 @@ require('jspdf-autotable')
|
|
|
4
4
|
const { getStyle } = require('./reportStyle')
|
|
5
5
|
const { headerFromUser } = require('./util/pdfDocument')
|
|
6
6
|
const { getUserPartner } = require('fleetmap-partners')
|
|
7
|
-
const { convertToLocaleString, getTranslations } = require('./util/utils')
|
|
7
|
+
const { convertToLocaleString, getTranslations, convertMS } = require('./util/utils')
|
|
8
8
|
const { devicesToProcess } = require('./util/device')
|
|
9
9
|
const { isInside } = require('./util/timetable')
|
|
10
10
|
const { getDigitalPortValue } = require('./location-report')
|
|
@@ -139,8 +139,10 @@ async function exportSpeedingReportToPDF (userData, reportData) {
|
|
|
139
139
|
|
|
140
140
|
const headers = [
|
|
141
141
|
translations.report.eventType,
|
|
142
|
-
translations.report.
|
|
142
|
+
translations.report.start,
|
|
143
|
+
translations.report.end,
|
|
143
144
|
translations.report.address,
|
|
145
|
+
translations.report.duration,
|
|
144
146
|
translations.report.info
|
|
145
147
|
]
|
|
146
148
|
if (reportData.devices) {
|
|
@@ -192,8 +194,10 @@ async function exportSpeedingReportToPDF (userData, reportData) {
|
|
|
192
194
|
d.alerts.forEach(a => {
|
|
193
195
|
const temp = [
|
|
194
196
|
getEventType(a, translations, d.device),
|
|
195
|
-
getAlertDate(userData.user, a),
|
|
197
|
+
getAlertDate(userData.user, a.position),
|
|
198
|
+
getAlertDate(userData.user, a.endPosition),
|
|
196
199
|
a.geofenceName || (a.position ? a.position.address : ''),
|
|
200
|
+
a.position && a.endPosition ? convertMS(new Date(a.endPosition.fixTime).getTime() - new Date(a.position.fixTime).getTime()) : '',
|
|
197
201
|
getAlertInfo(userData.drivers, a, d.device, translations)
|
|
198
202
|
]
|
|
199
203
|
data.push(temp)
|
|
@@ -254,8 +258,10 @@ function exportSpeedingReportToExcel (userData, reportData) {
|
|
|
254
258
|
const headers = [
|
|
255
259
|
{ label: translations.report.vehicle, value: 'name' },
|
|
256
260
|
{ label: translations.report.eventType, value: 'eventType' },
|
|
257
|
-
{ label: translations.report.
|
|
261
|
+
{ label: translations.report.start, value: 'fixTime' },
|
|
262
|
+
{ label: translations.report.end, value: 'endFixTime' },
|
|
258
263
|
{ label: translations.report.address, value: 'address' },
|
|
264
|
+
{ label: translations.report.duration, value: 'duration' },
|
|
259
265
|
{ label: translations.report.zone, value: 'geofenceName' },
|
|
260
266
|
{ label: translations.report.driver, value: 'driver' },
|
|
261
267
|
{ label: translations.report.info, value: 'info' },
|
|
@@ -269,8 +275,10 @@ function exportSpeedingReportToExcel (userData, reportData) {
|
|
|
269
275
|
return {
|
|
270
276
|
name: d.device.name,
|
|
271
277
|
eventType: getEventType(a, translations, d.device),
|
|
272
|
-
fixTime: getAlertDate(userData.user, a),
|
|
278
|
+
fixTime: getAlertDate(userData.user, a.position),
|
|
279
|
+
endFixTime: getAlertDate(userData.user, a.endPosition),
|
|
273
280
|
address: a.position && a.position.address,
|
|
281
|
+
duration: a.position && a.endPosition ? convertMS(new Date(a.endPosition.fixTime).getTime() - new Date(a.position.fixTime).getTime()) : '',
|
|
274
282
|
geofenceName: a.geofenceName,
|
|
275
283
|
info: getAlertInfo(userData.drivers, a, d.device, translations),
|
|
276
284
|
driver: a.driver,
|
|
@@ -316,9 +324,9 @@ function getAlertInfo (drivers, alert, device, translations) {
|
|
|
316
324
|
return ''
|
|
317
325
|
}
|
|
318
326
|
|
|
319
|
-
function getAlertDate (user,
|
|
320
|
-
if (
|
|
321
|
-
return convertToLocaleString(
|
|
327
|
+
function getAlertDate (user, position) {
|
|
328
|
+
if (position) {
|
|
329
|
+
return convertToLocaleString(position.fixTime, user.attributes.lang, user.attributes.timezone)
|
|
322
330
|
}
|
|
323
331
|
}
|
|
324
332
|
|
|
@@ -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 = []
|
package/src/speeding-report.js
CHANGED
|
@@ -315,6 +315,55 @@ async function getRoadSpeedLimits (devices, routes, threshold, minimumMinutes =
|
|
|
315
315
|
return method(devices, routes, threshold, minimumMinutes, country && country.code)
|
|
316
316
|
}
|
|
317
317
|
|
|
318
|
+
async function invokeValhalla (route, i, chunk, country, threshold, results, retry = 3) {
|
|
319
|
+
const slice = route.slice(i, i + chunk)
|
|
320
|
+
try {
|
|
321
|
+
const {
|
|
322
|
+
// eslint-disable-next-line camelcase
|
|
323
|
+
matched_points,
|
|
324
|
+
edges
|
|
325
|
+
} = await axios.post(`http://valhalla-${getCountry(slice[0]) || country}.pinme.io:8002/trace_attributes`,
|
|
326
|
+
{
|
|
327
|
+
costing: 'auto',
|
|
328
|
+
shape_match: 'map_snap',
|
|
329
|
+
filters: {
|
|
330
|
+
attributes: [
|
|
331
|
+
'admin.country_code',
|
|
332
|
+
'admin.country_text',
|
|
333
|
+
'admin.state_code',
|
|
334
|
+
'admin.state_text',
|
|
335
|
+
'edge.names',
|
|
336
|
+
'edge.way_id',
|
|
337
|
+
'edge.speed_limit',
|
|
338
|
+
'matched.point',
|
|
339
|
+
'matched.type',
|
|
340
|
+
'matched.edge_index'
|
|
341
|
+
],
|
|
342
|
+
action: 'include'
|
|
343
|
+
},
|
|
344
|
+
shape: slice.map(p => ({
|
|
345
|
+
lon: p.longitude,
|
|
346
|
+
lat: p.latitude
|
|
347
|
+
}))
|
|
348
|
+
})
|
|
349
|
+
.then(r => r.data)
|
|
350
|
+
// eslint-disable-next-line camelcase
|
|
351
|
+
matched_points.forEach((mp, mIndex) => {
|
|
352
|
+
const edge = edges[mp.edge_index]
|
|
353
|
+
const position = route[mIndex + i]
|
|
354
|
+
if (edge && (edge.speed_limit + (threshold || 0)) < position.speed * 1.852) {
|
|
355
|
+
results.push({ ...mp, ...edge, ...position })
|
|
356
|
+
}
|
|
357
|
+
})
|
|
358
|
+
} catch (e) {
|
|
359
|
+
if (--retry) {
|
|
360
|
+
return invokeValhalla(route, i, chunk, country, threshold, results, retry)
|
|
361
|
+
} else {
|
|
362
|
+
console.error(e.message, e.response && e.response.data, slice[0])
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
|
|
318
367
|
async function getOSMSpeedingEvents (devices, routes, threshold, minimumMinutes = 0, country) {
|
|
319
368
|
const chunk = 1000
|
|
320
369
|
const events = []
|
|
@@ -322,48 +371,7 @@ async function getOSMSpeedingEvents (devices, routes, threshold, minimumMinutes
|
|
|
322
371
|
const route = routes.filter(r => r.deviceId === d.id)
|
|
323
372
|
const results = []
|
|
324
373
|
for (let i = 0; i < route.length; i += chunk) {
|
|
325
|
-
|
|
326
|
-
try {
|
|
327
|
-
const {
|
|
328
|
-
// eslint-disable-next-line camelcase
|
|
329
|
-
matched_points,
|
|
330
|
-
edges
|
|
331
|
-
} = await axios.post(`http://valhalla-${getCountry(slice[0]) || country}.pinme.io:8002/trace_attributes`,
|
|
332
|
-
{
|
|
333
|
-
costing: 'auto',
|
|
334
|
-
shape_match: 'map_snap',
|
|
335
|
-
filters: {
|
|
336
|
-
attributes: [
|
|
337
|
-
'admin.country_code',
|
|
338
|
-
'admin.country_text',
|
|
339
|
-
'admin.state_code',
|
|
340
|
-
'admin.state_text',
|
|
341
|
-
'edge.names',
|
|
342
|
-
'edge.way_id',
|
|
343
|
-
'edge.speed_limit',
|
|
344
|
-
'matched.point',
|
|
345
|
-
'matched.type',
|
|
346
|
-
'matched.edge_index'
|
|
347
|
-
],
|
|
348
|
-
action: 'include'
|
|
349
|
-
},
|
|
350
|
-
shape: slice.map(p => ({
|
|
351
|
-
lon: p.longitude,
|
|
352
|
-
lat: p.latitude
|
|
353
|
-
}))
|
|
354
|
-
})
|
|
355
|
-
.then(r => r.data)
|
|
356
|
-
// eslint-disable-next-line camelcase
|
|
357
|
-
matched_points.forEach((mp, mIndex) => {
|
|
358
|
-
const edge = edges[mp.edge_index]
|
|
359
|
-
const position = route[mIndex + i]
|
|
360
|
-
if (edge && (edge.speed_limit + (threshold || 0)) < position.speed * 1.852) {
|
|
361
|
-
results.push({ ...mp, ...edge, ...position })
|
|
362
|
-
}
|
|
363
|
-
})
|
|
364
|
-
} catch (e) {
|
|
365
|
-
console.error(e.message, e.response && e.response.data, slice[0])
|
|
366
|
-
}
|
|
374
|
+
await invokeValhalla(route, i, chunk, country, threshold, results)
|
|
367
375
|
}
|
|
368
376
|
const reduced = results.reduce((acc, cur, idx, src) => {
|
|
369
377
|
const last = acc.length && acc.slice(-1)[0]
|
|
@@ -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/index.test.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
const { getReports } = require('./index')
|
|
3
3
|
const assert = require('assert')
|
|
4
4
|
const utils = require('../util/utils')
|
|
5
|
-
const { createGPSJumpReport } = require('../partnerReports/gpsjump-report')
|
|
6
5
|
|
|
7
6
|
// eslint-disable-next-line no-undef
|
|
8
7
|
describe('Test_Reports', function () {
|
|
@@ -19,19 +18,12 @@ describe('Test_Reports', function () {
|
|
|
19
18
|
const pdf = await report.speedingReportToPDF(userData, data[0])
|
|
20
19
|
pdf.save()
|
|
21
20
|
}, 40000)
|
|
21
|
+
|
|
22
22
|
it('converts madrid time', async () => {
|
|
23
23
|
assert.equal(false, utils.isClientSide())
|
|
24
24
|
console.log(utils.convertToLocaleString(new Date(), 'es-CL', 'Europe/Madrid'))
|
|
25
25
|
})
|
|
26
|
-
|
|
27
|
-
const report = await getReports('HASSANE', 'movitec.1637')
|
|
28
|
-
const userData = await report.getUserData()
|
|
29
|
-
userData.devices = userData.devices.filter(d => d.id === 148725)
|
|
30
|
-
const data = await createGPSJumpReport(new Date(2023, 8, 22, 0, 0, 0, 0),
|
|
31
|
-
new Date(2023, 8, 24, 23, 59, 59, 0),
|
|
32
|
-
userData, report.traccar)
|
|
33
|
-
console.log(data)
|
|
34
|
-
}, 40000)
|
|
26
|
+
|
|
35
27
|
it('Idle by device', async () => {
|
|
36
28
|
const report = await getReports()
|
|
37
29
|
const userData = await report.getUserData()
|
|
@@ -62,7 +54,7 @@ describe('Test_Reports', function () {
|
|
|
62
54
|
const totalIdleTime = driver.idleEvents.reduce((a, b) => a + b.idleTime, 0)
|
|
63
55
|
assert.equal(driver.idleEvents.length, 15) // Total Alerts
|
|
64
56
|
assert.equal(totalIdleTime, 16000) // Total Duration
|
|
65
|
-
}, 20000)
|
|
57
|
+
}, 20000)
|
|
66
58
|
// eslint-disable-next-line no-undef
|
|
67
59
|
it('test allinone', async () => {
|
|
68
60
|
console.log('Start')
|
package/src/tests/zones.test.js
CHANGED
|
@@ -27,18 +27,6 @@ describe('zones', function () {
|
|
|
27
27
|
console.log('result', result)
|
|
28
28
|
}, 4000000)
|
|
29
29
|
|
|
30
|
-
it('works with afriquia', async () => {
|
|
31
|
-
const report = await getReports(process.env.USER_AFRIQUIA, process.env.PASS_AFRIQUIA)
|
|
32
|
-
const userData = await report.getUserData()
|
|
33
|
-
console.log(userData.devices.length)
|
|
34
|
-
console.log(userData.geofences)
|
|
35
|
-
const result = await report.zoneReport(
|
|
36
|
-
new Date(Date.UTC(2023, 5, 11, 0, 0, 0, 0)),
|
|
37
|
-
new Date(Date.UTC(2023, 5, 11, 23, 59, 59, 0)),
|
|
38
|
-
userData)
|
|
39
|
-
console.log('result', result)
|
|
40
|
-
}, 4000000)
|
|
41
|
-
|
|
42
30
|
// eslint-disable-next-line no-undef
|
|
43
31
|
it('works with casais', async () => {
|
|
44
32
|
const report = await getReports(process.env.USER_CASAIS, process.env.PASS_CASAIS)
|