fleetmap-reports 1.0.340 → 1.0.345
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 +2 -1
- package/src/activity-report.js +63 -21
- package/src/index.test.js +39 -13
- package/src/util/traccar.js +2 -2
- package/src/util/trips.js +12 -1
- package/src/here.test.js +0 -25
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fleetmap-reports",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.345",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"axios-debug-log": "^0.8.4",
|
|
31
|
+
"jest": "^27.5.0",
|
|
31
32
|
"mocha": "^9.0.3",
|
|
32
33
|
"webpack": "^5.24.3",
|
|
33
34
|
"webpack-cli": "^4.5.0"
|
package/src/activity-report.js
CHANGED
|
@@ -9,7 +9,7 @@ const {getStyle} = require("./reportStyle")
|
|
|
9
9
|
const {getUserPartner} = require("fleetmap-partners")
|
|
10
10
|
const traccar = require("./util/traccar")
|
|
11
11
|
const {isInsideTimetable, isPartialInsideTimetable} = require("./util/trips");
|
|
12
|
-
const
|
|
12
|
+
const tripHelper = require("./util/trips");
|
|
13
13
|
|
|
14
14
|
const fileName = 'ActivityReport'
|
|
15
15
|
|
|
@@ -85,16 +85,14 @@ async function createActivityReportByDevice(from, to, userData, traccarInstance)
|
|
|
85
85
|
//Get report data from traccar
|
|
86
86
|
devicesToProcess.sort((a, b) => (a.name > b.name) ? 1 : -1)
|
|
87
87
|
|
|
88
|
-
let routeData = []
|
|
89
88
|
let summaries = []
|
|
90
|
-
const
|
|
89
|
+
const {trips, route, summary} = await traccar.getAllInOne(traccarInstance, from, to, devicesToProcess, userData.groupByDay && !userData.allWeek, true, false, !userData.groupByDay)
|
|
91
90
|
|
|
92
91
|
if(userData.groupByDay) {
|
|
93
|
-
|
|
94
|
-
console.log('trips:' + tripsData.length)
|
|
92
|
+
console.log('trips:' + trips.length)
|
|
95
93
|
|
|
96
|
-
if (
|
|
97
|
-
|
|
94
|
+
if (trips.length) {
|
|
95
|
+
tripHelper.checkTripsKms(traccarInstance, from, to, devicesToProcess, {trips, route})
|
|
98
96
|
}
|
|
99
97
|
|
|
100
98
|
const dates = getDates(from, to)
|
|
@@ -109,14 +107,14 @@ async function createActivityReportByDevice(from, to, userData, traccarInstance)
|
|
|
109
107
|
}
|
|
110
108
|
}
|
|
111
109
|
} else {
|
|
112
|
-
summaries =
|
|
110
|
+
summaries = summary
|
|
113
111
|
}
|
|
114
112
|
|
|
115
113
|
console.log('Summary:' + summaries.length)
|
|
116
114
|
|
|
117
115
|
//Process report data
|
|
118
|
-
if (summaries.length ||
|
|
119
|
-
allData.devices = processDevices(from, to, devicesToProcess, {summaries: summaries, trips
|
|
116
|
+
if (summaries.length || trips.length) {
|
|
117
|
+
allData.devices = processDevices(from, to, devicesToProcess, {summaries: summaries, trips, route}, userData)
|
|
120
118
|
}
|
|
121
119
|
|
|
122
120
|
return allData
|
|
@@ -174,19 +172,21 @@ function processDevices(from, to, devices, data, userData) {
|
|
|
174
172
|
return a > b.maxSpeed ? a : b.maxSpeed
|
|
175
173
|
}, 0),
|
|
176
174
|
endOdometer: 0,
|
|
177
|
-
startOdometer: 0
|
|
175
|
+
startOdometer: 0,
|
|
176
|
+
startTime: tripsByDay.length && tripsByDay[0].startTime,
|
|
177
|
+
endTime: tripsByDay.length && tripsByDay[tripsByDay.length-1].endTime
|
|
178
178
|
})
|
|
179
179
|
} else {
|
|
180
|
-
const summaryCurrentDay = data.summaries.
|
|
180
|
+
const summaryCurrentDay = data.summaries.find(s => {
|
|
181
181
|
return s.deviceId === d.id && s.date.getTime() === date.getTime()})
|
|
182
182
|
|
|
183
|
-
if (summaryCurrentDay
|
|
184
|
-
summaryCurrentDay.
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
183
|
+
if (summaryCurrentDay) {
|
|
184
|
+
summaryCurrentDay.distance = distance
|
|
185
|
+
summaryCurrentDay.convertedSpentFuel = automaticReports.calculateSpentFuel(summaryCurrentDay.spentFuel, d)
|
|
186
|
+
summaryCurrentDay.startTime = tripsByDay.length && tripsByDay[0].startTime
|
|
187
|
+
summaryCurrentDay.endTime = tripsByDay.length && tripsByDay[tripsByDay.length-1].endTime
|
|
188
188
|
|
|
189
|
-
summary.push(
|
|
189
|
+
summary.push(summaryCurrentDay)
|
|
190
190
|
}
|
|
191
191
|
}
|
|
192
192
|
}
|
|
@@ -195,8 +195,11 @@ function processDevices(from, to, devices, data, userData) {
|
|
|
195
195
|
|
|
196
196
|
if (summary.length) {
|
|
197
197
|
summary.forEach(s => {
|
|
198
|
-
|
|
198
|
+
const deviceTrips = data.trips.filter(t => t.deviceId === d.id)
|
|
199
|
+
s.distance = deviceTrips.reduce((a, b) => a + b.distance, 0)
|
|
199
200
|
s.convertedSpentFuel = automaticReports.calculateSpentFuel(s.spentFuel, d)
|
|
201
|
+
s.startTime = deviceTrips.length && deviceTrips[0].startTime
|
|
202
|
+
s.endTime = deviceTrips.length && deviceTrips[deviceTrips.length-1].endTime
|
|
200
203
|
})
|
|
201
204
|
}
|
|
202
205
|
}
|
|
@@ -236,7 +239,9 @@ function processDrivers(from, to, drivers, data, userData) {
|
|
|
236
239
|
distance: tripsByDay.filter(t => t.distance > 0).reduce((a, b) => a + b.distance, 0),
|
|
237
240
|
engineHours: tripsByDay.reduce((a, b) => a + b.duration, 0),
|
|
238
241
|
maxSpeed: tripsByDay.reduce((a, b) => Math.max(a, b.maxSpeed), 0),
|
|
239
|
-
averageSpeed: tripsByDay.length
|
|
242
|
+
averageSpeed: tripsByDay.length ? Math.round(tripsByDay.reduce((a, b) => a + b.averageSpeed, 0) / tripsByDay.length) : 0,
|
|
243
|
+
startTime: tripsByDay.length && tripsByDay[0].startTime,
|
|
244
|
+
endTime: tripsByDay.length && tripsByDay[tripsByDay.length-1].endTime
|
|
240
245
|
})
|
|
241
246
|
}
|
|
242
247
|
} else {
|
|
@@ -245,6 +250,8 @@ function processDrivers(from, to, drivers, data, userData) {
|
|
|
245
250
|
engineHours: trips.reduce((a, b) => a + b.duration, 0),
|
|
246
251
|
maxSpeed: trips.reduce((a, b) => Math.max(a, b.maxSpeed), 0),
|
|
247
252
|
averageSpeed: Math.round(trips.reduce((a, b) => a + b.averageSpeed, 0) / trips.length),
|
|
253
|
+
startTime: trips.length && trips[0].startTime,
|
|
254
|
+
endTime: trips.length && trips[trips.length-1].endTime
|
|
248
255
|
})
|
|
249
256
|
}
|
|
250
257
|
driversResult.push(driverData)
|
|
@@ -279,6 +286,8 @@ async function exportActivityReportToPDF(userData, reportData) {
|
|
|
279
286
|
|
|
280
287
|
function exportActivityReportToPDF_Driver(doc, translations, reportData, userData) {
|
|
281
288
|
const headers = [translations.report.driver,
|
|
289
|
+
translations.report.start,
|
|
290
|
+
translations.report.end,
|
|
282
291
|
translations.report.distance,
|
|
283
292
|
translations.report.speed + ' ' + translations.report.avgSpeed + ' (Km/h)',
|
|
284
293
|
translations.report.speed + ' ' + translations.report.maxSpeed + ' (Km/h)',
|
|
@@ -291,6 +300,8 @@ function exportActivityReportToPDF_Driver(doc, translations, reportData, userDat
|
|
|
291
300
|
reportData.drivers.forEach(d => {
|
|
292
301
|
const temp = [
|
|
293
302
|
d.driver.name,
|
|
303
|
+
d.summary[0].startTime ? new Date(d.summary[0].startTime).toLocaleString() : '',
|
|
304
|
+
d.summary[0].endTime ? new Date(d.summary[0].endTime).toLocaleString() : '',
|
|
294
305
|
Number((d.summary[0].distance / 1000).toFixed(2)),
|
|
295
306
|
Math.round(d.summary[0].averageSpeed * 1.85200),
|
|
296
307
|
Math.round(d.summary[0].maxSpeed * 1.85200),
|
|
@@ -300,6 +311,7 @@ function exportActivityReportToPDF_Driver(doc, translations, reportData, userDat
|
|
|
300
311
|
})
|
|
301
312
|
|
|
302
313
|
const footValues = ['Total:' + reportData.drivers.length,
|
|
314
|
+
'','',
|
|
303
315
|
(reportData.drivers.reduce((a, b) => a + b.summary[0].distance, 0) / 1000).toFixed(0),
|
|
304
316
|
getSumAvgSpeed(reportData.drivers, userData),
|
|
305
317
|
getSumMaxSpeed(reportData.drivers, userData),
|
|
@@ -312,6 +324,8 @@ function exportActivityReportToPDF_Driver(doc, translations, reportData, userDat
|
|
|
312
324
|
function exportActivityReportToPDF_Vehicle(doc, translations, reportData, userData) {
|
|
313
325
|
const headers = [translations.report.vehicle,
|
|
314
326
|
translations.report.group,
|
|
327
|
+
translations.report.start,
|
|
328
|
+
translations.report.end,
|
|
315
329
|
translations.report.distance,
|
|
316
330
|
translations.report.start + ' ' + translations.report.odometer,
|
|
317
331
|
translations.report.end + ' ' + translations.report.odometer,
|
|
@@ -330,6 +344,8 @@ function exportActivityReportToPDF_Vehicle(doc, translations, reportData, userDa
|
|
|
330
344
|
const temp = [
|
|
331
345
|
d.summary[0].deviceName,
|
|
332
346
|
group ? group.name : '',
|
|
347
|
+
d.summary[0].startTime ? new Date(d.summary[0].startTime).toLocaleString() : '',
|
|
348
|
+
d.summary[0].endTime ? new Date(d.summary[0].endTime).toLocaleString() : '',
|
|
333
349
|
Number((d.summary[0].distance / 1000).toFixed(2)),
|
|
334
350
|
Number((d.summary[0].startOdometer / 1000).toFixed(2)),
|
|
335
351
|
Number((d.summary[0].endOdometer / 1000).toFixed(2)),
|
|
@@ -342,7 +358,7 @@ function exportActivityReportToPDF_Vehicle(doc, translations, reportData, userDa
|
|
|
342
358
|
})
|
|
343
359
|
|
|
344
360
|
const footValues = ['Total:' + reportData.devices.length,
|
|
345
|
-
'',
|
|
361
|
+
'','','',
|
|
346
362
|
(reportData.devices.reduce((a, b) => a + b.summary[0].distance, 0) / 1000).toFixed(0),
|
|
347
363
|
'', '',
|
|
348
364
|
getSumAvgSpeed(reportData.devices, userData),
|
|
@@ -356,6 +372,8 @@ function exportActivityReportToPDF_Vehicle(doc, translations, reportData, userDa
|
|
|
356
372
|
|
|
357
373
|
function exportActivityReportToPDF_Vehicle_GroupByDay(doc, translations, reportData, userData) {
|
|
358
374
|
const headers = [translations.report.date,
|
|
375
|
+
translations.report.start,
|
|
376
|
+
translations.report.end,
|
|
359
377
|
translations.report.distance,
|
|
360
378
|
translations.report.start + ' ' + translations.report.odometer,
|
|
361
379
|
translations.report.end + ' ' + translations.report.odometer,
|
|
@@ -405,6 +423,8 @@ function exportActivityReportToPDF_Vehicle_GroupByDay(doc, translations, reportD
|
|
|
405
423
|
d.summary.forEach(s => {
|
|
406
424
|
const temp = [
|
|
407
425
|
new Date(s.date).toLocaleDateString() + ' - ' + weekDays[s.date.getDay()],
|
|
426
|
+
s.startTime ? new Date(s.startTime).toLocaleTimeString() : '',
|
|
427
|
+
s.endTime ? new Date(s.endTime).toLocaleTimeString() : '',
|
|
408
428
|
Number((s.distance / 1000).toFixed(2)),
|
|
409
429
|
Number((s.startOdometer / 1000).toFixed(2)),
|
|
410
430
|
Number((s.endOdometer / 1000).toFixed(2)),
|
|
@@ -418,6 +438,7 @@ function exportActivityReportToPDF_Vehicle_GroupByDay(doc, translations, reportD
|
|
|
418
438
|
})
|
|
419
439
|
|
|
420
440
|
const footValues = ['Total:' + d.summary.length,
|
|
441
|
+
'','',
|
|
421
442
|
(d.summary.reduce((a, b) => a + b.distance, 0) / 1000).toFixed(0),
|
|
422
443
|
'', '',
|
|
423
444
|
getSumAvgSpeed(d.summary, userData),
|
|
@@ -435,6 +456,8 @@ function exportActivityReportToExcel_Vehicle_GroupByDay(settings, translations,
|
|
|
435
456
|
{label: translations.report.group, value: 'group'},
|
|
436
457
|
{label: translations.report.date, value: 'date'},
|
|
437
458
|
{label: translations.report.weekDay, value: 'weekday'},
|
|
459
|
+
{label: translations.report.start, value: 'start'},
|
|
460
|
+
{label: translations.report.end, value: 'end'},
|
|
438
461
|
{label: translations.report.distance, value: 'distance'},
|
|
439
462
|
{label: translations.report.start + ' ' + translations.report.odometer, value: 'startOdometer'},
|
|
440
463
|
{label: translations.report.end + ' ' + translations.report.odometer, value: 'endOdometer'},
|
|
@@ -465,6 +488,8 @@ function exportActivityReportToExcel_Vehicle_GroupByDay(settings, translations,
|
|
|
465
488
|
group: group ? group.name : '',
|
|
466
489
|
date: new Date(s.date).toLocaleDateString(),
|
|
467
490
|
weekday: weekDays[s.date.getDay()],
|
|
491
|
+
start: s.startTime ? new Date(s.startTime).toLocaleTimeString() : '',
|
|
492
|
+
end:s.endTime ? new Date(s.endTime).toLocaleTimeString() : '',
|
|
468
493
|
distance: Number((s.distance / 1000).toFixed(0)),
|
|
469
494
|
startOdometer: Number((s.startOdometer / 1000).toFixed(0)),
|
|
470
495
|
endOdometer: Number((s.endOdometer / 1000).toFixed(0)),
|
|
@@ -486,6 +511,8 @@ function exportActivityReportToExcel_Vehicle_GroupByDay(settings, translations,
|
|
|
486
511
|
|
|
487
512
|
function exportActivityReportToPDF_Driver_GroupByDay(doc, translations, reportData, userData) {
|
|
488
513
|
const headers = [translations.report.date,
|
|
514
|
+
translations.report.start,
|
|
515
|
+
translations.report.end,
|
|
489
516
|
translations.report.distance,
|
|
490
517
|
translations.report.avgSpeed + ' (Km/h)',
|
|
491
518
|
translations.report.maxSpeed + ' (Km/h)',
|
|
@@ -532,6 +559,8 @@ function exportActivityReportToPDF_Driver_GroupByDay(doc, translations, reportDa
|
|
|
532
559
|
d.summary.forEach(s => {
|
|
533
560
|
const temp = [
|
|
534
561
|
new Date(s.date).toLocaleDateString() + ' - ' + weekDays[s.date.getDay()],
|
|
562
|
+
s.startTime ? new Date(s.startTime).toLocaleTimeString() : '',
|
|
563
|
+
s.endTime ? new Date(s.endTime).toLocaleTimeString() : '',
|
|
535
564
|
Number((s.distance / 1000).toFixed(2)),
|
|
536
565
|
Math.round(s.averageSpeed * 1.85200),
|
|
537
566
|
Math.round(s.maxSpeed * 1.85200),
|
|
@@ -542,6 +571,7 @@ function exportActivityReportToPDF_Driver_GroupByDay(doc, translations, reportDa
|
|
|
542
571
|
})
|
|
543
572
|
|
|
544
573
|
const footValues = ['Total:' + d.summary.length,
|
|
574
|
+
'','',
|
|
545
575
|
(d.summary.reduce((a, b) => a + b.distance, 0) / 1000).toFixed(0),
|
|
546
576
|
getSumAvgSpeed(d.summary, userData),
|
|
547
577
|
getSumMaxSpeed(d.summary, userData),
|
|
@@ -557,6 +587,8 @@ function exportActivityReportToExcel_Driver_GroupByDay(settings, translations, r
|
|
|
557
587
|
{label: translations.report.group, value: 'group'},
|
|
558
588
|
{label: translations.report.date, value: 'date'},
|
|
559
589
|
{label: translations.report.weekDay, value: 'weekday'},
|
|
590
|
+
{label: translations.report.start, value: 'start'},
|
|
591
|
+
{label: translations.report.end, value: 'end'},
|
|
560
592
|
{label: translations.report.distance, value: 'distance'},
|
|
561
593
|
{label: translations.report.speed + ' ' + translations.report.avgSpeed + ' (Km/h)', value: 'avgSpeed'},
|
|
562
594
|
{label: translations.report.speed + ' ' + translations.report.maxSpeed + ' (Km/h)', value: 'maxSpeed'},
|
|
@@ -584,6 +616,8 @@ function exportActivityReportToExcel_Driver_GroupByDay(settings, translations, r
|
|
|
584
616
|
group: group ? group.name : '',
|
|
585
617
|
date: new Date(s.date).toLocaleDateString(),
|
|
586
618
|
weekday: weekDays[s.date.getDay()],
|
|
619
|
+
start: s.startTime ? new Date(s.startTime).toLocaleTimeString() : '',
|
|
620
|
+
end:s.endTime ? new Date(s.endTime).toLocaleTimeString() : '',
|
|
587
621
|
distance: Number((s.distance / 1000).toFixed(0)),
|
|
588
622
|
avgSpeed: Math.round(s.averageSpeed * 1.85200),
|
|
589
623
|
maxSpeed: Math.round(s.maxSpeed * 1.85200),
|
|
@@ -602,6 +636,8 @@ function exportActivityReportToExcel_Driver_GroupByDay(settings, translations, r
|
|
|
602
636
|
|
|
603
637
|
function exportActivityReportToExcel_Driver(settings, translations, reportData) {
|
|
604
638
|
const headers = [{label: translations.report.driver, value: 'driver'},
|
|
639
|
+
{label: translations.report.start, value: 'start'},
|
|
640
|
+
{label: translations.report.end, value: 'end'},
|
|
605
641
|
{label: translations.report.distance, value: 'distance'},
|
|
606
642
|
{label: translations.report.speed + ' ' + translations.report.avgSpeed + ' (Km/h)', value: 'avgSpeed'},
|
|
607
643
|
{label: translations.report.speed + ' ' + translations.report.maxSpeed + ' (Km/h)', value: 'maxSpeed'},
|
|
@@ -612,6 +648,8 @@ function exportActivityReportToExcel_Driver(settings, translations, reportData)
|
|
|
612
648
|
reportData.drivers.forEach(d => {
|
|
613
649
|
data = data.concat([{
|
|
614
650
|
driver: d.driver.name,
|
|
651
|
+
start: d.summary[0].startTime ? new Date(d.summary[0].startTime).toLocaleString() : '',
|
|
652
|
+
end: d.summary[0].endTime ? new Date(d.summary[0].endTime).toLocaleString() : '',
|
|
615
653
|
distance: Number((d.summary[0].distance / 1000).toFixed(0)),
|
|
616
654
|
avgSpeed: Math.round(d.summary[0].averageSpeed * 1.85200),
|
|
617
655
|
maxSpeed: Math.round(d.summary[0].maxSpeed * 1.85200),
|
|
@@ -630,6 +668,8 @@ function exportActivityReportToExcel_Driver(settings, translations, reportData)
|
|
|
630
668
|
function exportActivityReportToExcel_Vehicle(settings, translations, reportData, userData) {
|
|
631
669
|
const headers = [{label: translations.report.vehicle, value: 'name'},
|
|
632
670
|
{label: translations.report.group, value: 'group'},
|
|
671
|
+
{label: translations.report.start, value: 'start'},
|
|
672
|
+
{label: translations.report.end, value: 'end'},
|
|
633
673
|
{label: translations.report.distance, value: 'distance'},
|
|
634
674
|
{label: translations.report.start + ' ' + translations.report.odometer, value: 'startOdometer'},
|
|
635
675
|
{label: translations.report.end + ' ' + translations.report.odometer, value: 'endOdometer'},
|
|
@@ -646,6 +686,8 @@ function exportActivityReportToExcel_Vehicle(settings, translations, reportData,
|
|
|
646
686
|
data = data.concat([{
|
|
647
687
|
name: d.summary[0].deviceName,
|
|
648
688
|
group: group ? group.name : '',
|
|
689
|
+
start: d.summary[0].startTime ? new Date(d.summary[0].startTime).toLocaleString() : '',
|
|
690
|
+
end: d.summary[0].endTime ? new Date(d.summary[0].endTime).toLocaleString() : '',
|
|
649
691
|
distance: Number((d.summary[0].distance / 1000).toFixed(0)),
|
|
650
692
|
startOdometer: Number((d.summary[0].startOdometer / 1000).toFixed(0)),
|
|
651
693
|
endOdometer: Number((d.summary[0].endOdometer / 1000).toFixed(0)),
|
package/src/index.test.js
CHANGED
|
@@ -16,7 +16,7 @@ describe('Test_Reports', function() {
|
|
|
16
16
|
assert.equal(device.alerts.length, 15) // Total Alerts
|
|
17
17
|
assert.equal(totalDistance, 19.605972526552154) // Total Kms
|
|
18
18
|
assert.equal(totalEventTime, 562000) // Total Duration
|
|
19
|
-
}
|
|
19
|
+
}, 20000)
|
|
20
20
|
it('Speeding by device with custom speed', async () => {
|
|
21
21
|
const report = await getReports()
|
|
22
22
|
const userData = await report.getUserData()
|
|
@@ -34,7 +34,7 @@ describe('Test_Reports', function() {
|
|
|
34
34
|
assert.equal(device.alerts.length, 24) // Total Alerts
|
|
35
35
|
assert.equal(totalDistance, 49.49653008204987) // Total Kms
|
|
36
36
|
assert.equal(totalEventTime, 1523000) // Total Duration
|
|
37
|
-
}
|
|
37
|
+
}, 20000)
|
|
38
38
|
it('Trip by device', async () => {
|
|
39
39
|
const report = await getReports()
|
|
40
40
|
const userData = await report.getUserData()
|
|
@@ -47,7 +47,7 @@ describe('Test_Reports', function() {
|
|
|
47
47
|
const device = data[0].devices.find(d => d.device.id===22326)
|
|
48
48
|
assert.equal(device.trips.length, 7) // Total Trips
|
|
49
49
|
assert.equal(device.totalDistance, 339204.53999999166) // Total Kms
|
|
50
|
-
}
|
|
50
|
+
}, 20000)
|
|
51
51
|
it('Trip by device with time period ', async () => {
|
|
52
52
|
const report = await getReports()
|
|
53
53
|
const userData = await report.getUserData()
|
|
@@ -75,7 +75,7 @@ describe('Test_Reports', function() {
|
|
|
75
75
|
const device = data[0].devices.find(d => d.device.id===22326)
|
|
76
76
|
assert.equal(device.trips.length, 4) // Total Trips
|
|
77
77
|
assert.equal(device.totalDistance, 265155.1099999994) // Total Kms
|
|
78
|
-
}
|
|
78
|
+
},20000)
|
|
79
79
|
it('Trip by device with time period 2', async () => {
|
|
80
80
|
const report = await getReports()
|
|
81
81
|
const userData = await report.getUserData()
|
|
@@ -103,7 +103,7 @@ describe('Test_Reports', function() {
|
|
|
103
103
|
const device = data[0].devices.find(d => d.device.id===22326)
|
|
104
104
|
assert.equal(device.trips.length, 18) // Total Trips
|
|
105
105
|
assert.equal(device.totalDistance, 133505.6100000143) // Total Kms
|
|
106
|
-
}
|
|
106
|
+
},20000)
|
|
107
107
|
it('Location by device', async () => {
|
|
108
108
|
const report = await getReports()
|
|
109
109
|
const userData = await report.getUserData()
|
|
@@ -115,7 +115,7 @@ describe('Test_Reports', function() {
|
|
|
115
115
|
assert.equal(data.length, 1)
|
|
116
116
|
const device = data[0].devices.find(d => d.device.id===22326)
|
|
117
117
|
assert.equal(device.positions.length, 708) // Total Positions
|
|
118
|
-
}
|
|
118
|
+
},20000)
|
|
119
119
|
it('KmsReport by device', async () => {
|
|
120
120
|
const reports = await getReports()
|
|
121
121
|
const userData = await reports.getUserData()
|
|
@@ -125,7 +125,7 @@ describe('Test_Reports', function() {
|
|
|
125
125
|
assert.equal(data.length, 1)
|
|
126
126
|
const device = data[0].devices.find(d => d.device.id===22326)
|
|
127
127
|
assert.equal(device.summary.distance, 1193284.3100000024) // Total Kms
|
|
128
|
-
})
|
|
128
|
+
},30000)
|
|
129
129
|
it('KmsReport byDevice groupByDay', async () => {
|
|
130
130
|
const reports = await getReports()
|
|
131
131
|
const userData = await reports.getUserData()
|
|
@@ -137,7 +137,7 @@ describe('Test_Reports', function() {
|
|
|
137
137
|
const device = data[0].devices.find(d => d.device.id===22326)
|
|
138
138
|
assert.equal(device.days.length, 10) // Total Kms
|
|
139
139
|
assert.equal(device.days[5].kms, 23183.010000005364) // Total Kms
|
|
140
|
-
})
|
|
140
|
+
},90000)
|
|
141
141
|
it('Idle by device', async () => {
|
|
142
142
|
const report = await getReports()
|
|
143
143
|
const userData = await report.getUserData()
|
|
@@ -150,7 +150,7 @@ describe('Test_Reports', function() {
|
|
|
150
150
|
const totalIdleTime = device.idleEvents.reduce((a, b) => a + b.idleTime, 0)
|
|
151
151
|
assert.equal(device.idleEvents.length, 8) // Total Alerts
|
|
152
152
|
assert.equal(totalIdleTime, 1294000) // Total Duration
|
|
153
|
-
}
|
|
153
|
+
},20000)
|
|
154
154
|
it('Activity by device', async () => {
|
|
155
155
|
const report = await getReports()
|
|
156
156
|
const userData = await report.getUserData()
|
|
@@ -162,7 +162,9 @@ describe('Test_Reports', function() {
|
|
|
162
162
|
const device = data[0].devices.find(d => d.device.id===22326)
|
|
163
163
|
assert.equal(device.summary[0].startOdometer, 122502742.59)
|
|
164
164
|
assert.equal(device.summary[0].distance, 1386519.1300000101)
|
|
165
|
-
|
|
165
|
+
assert.equal(device.summary[0].startTime, '2022-01-01T13:35:47.000+0000')
|
|
166
|
+
assert.equal(device.summary[0].endTime, '2022-01-30T13:48:18.000+0000')
|
|
167
|
+
}, 20000)
|
|
166
168
|
it('Activity byDevice groupByDay', async () => {
|
|
167
169
|
const report = await getReports()
|
|
168
170
|
const userData = await report.getUserData()
|
|
@@ -174,7 +176,9 @@ describe('Test_Reports', function() {
|
|
|
174
176
|
const device = data[0].devices.find(d => d.device.id===22326)
|
|
175
177
|
assert.equal(device.summary[5].startOdometer, 122923290.95)
|
|
176
178
|
assert.equal(device.summary[5].distance, 77020.37999999523)
|
|
177
|
-
|
|
179
|
+
assert.equal(device.summary[5].startTime, '2022-01-06T18:35:04.000+0000')
|
|
180
|
+
assert.equal(device.summary[5].endTime, '2022-01-06T19:54:27.000+0000')
|
|
181
|
+
}, 60000)
|
|
178
182
|
it('test allinone', async() => {
|
|
179
183
|
console.log('Start')
|
|
180
184
|
const reports = await getReports()
|
|
@@ -187,6 +191,28 @@ describe('Test_Reports', function() {
|
|
|
187
191
|
true,
|
|
188
192
|
true,
|
|
189
193
|
false)
|
|
190
|
-
|
|
191
|
-
|
|
194
|
+
|
|
195
|
+
assert.equal(r.trips.filter(t => t.deviceId === 22327).length, 10)
|
|
196
|
+
assert.equal(r.stops.filter(t => t.deviceId === 22327).length, 11)
|
|
197
|
+
}, 20000)
|
|
198
|
+
it('Total KMS', async () => {
|
|
199
|
+
const report = await getReports()
|
|
200
|
+
const userData = await report.getUserData()
|
|
201
|
+
|
|
202
|
+
const tripsReport = await report.tripReport(new Date(2022, 1, 11, 0, 0, 0, 0),
|
|
203
|
+
new Date(2022, 1, 14, 23, 59, 59, 0),
|
|
204
|
+
userData)
|
|
205
|
+
|
|
206
|
+
const kmsReport = await report.kmsReport(new Date(2022, 1, 11, 0, 0, 0, 0),
|
|
207
|
+
new Date(2022, 1, 14, 23, 59, 59, 0),
|
|
208
|
+
userData)
|
|
209
|
+
|
|
210
|
+
assert.equal(tripsReport.length, 1)
|
|
211
|
+
const device1 = tripsReport[0].devices.find(d => d.device.id===11681)
|
|
212
|
+
assert.equal(device1.trips.length, 44) // Total Trips
|
|
213
|
+
assert.equal(device1.totalDistance, 883076.9928612101) // Total Kms
|
|
214
|
+
|
|
215
|
+
const device2 = kmsReport[0].devices.find(d => d.device.id===11681)
|
|
216
|
+
assert.equal(device2.summary.distance, device1.totalDistance) // Total Kms
|
|
217
|
+
}, 30000)
|
|
192
218
|
})
|
package/src/util/traccar.js
CHANGED
|
@@ -84,8 +84,8 @@ async function getAllInOne(traccar, from, to, devices, getRoutes, getTrips, getS
|
|
|
84
84
|
return {
|
|
85
85
|
route: result.filter(t => t.route).map(r => r.route).flat(),
|
|
86
86
|
trips: result.filter(t => t.trips).map(r => r.trips).flat(),
|
|
87
|
-
stops: result.filter(t => t.
|
|
88
|
-
summary: result.filter(t => t.
|
|
87
|
+
stops: result.filter(t => t.stops).map(r => r.stops).flat(),
|
|
88
|
+
summary: result.filter(t => t.summary).map(r => r.summary).flat(),
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
91
|
|
package/src/util/trips.js
CHANGED
|
@@ -34,7 +34,18 @@ function checkTripsKms(traccarInstance, from, to, devices, data) {
|
|
|
34
34
|
const tripRoute = data.route.filter(p => p.deviceId === t.deviceId
|
|
35
35
|
&& new Date(p.fixTime).getTime() >= new Date(t.startTime).getTime()
|
|
36
36
|
&& new Date(p.fixTime).getTime() <= new Date(t.endTime).getTime())
|
|
37
|
-
|
|
37
|
+
|
|
38
|
+
let current = null
|
|
39
|
+
const distances = []
|
|
40
|
+
for(const p of tripRoute) {
|
|
41
|
+
if(current) {
|
|
42
|
+
distances.push(coordsDistance(parseFloat(current.longitude),parseFloat(current.latitude),
|
|
43
|
+
parseFloat(p.longitude),parseFloat(p.latitude)))
|
|
44
|
+
}
|
|
45
|
+
current = p
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
t.distance = distances.reduce((a, b) => a + b, 0)
|
|
38
49
|
}
|
|
39
50
|
})
|
|
40
51
|
}
|
package/src/here.test.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
const here = require('./here')
|
|
2
|
-
|
|
3
|
-
require('axios-debug-log')({
|
|
4
|
-
request: function (debug, config) {
|
|
5
|
-
console.log('Req headers:', config.headers.common)
|
|
6
|
-
},
|
|
7
|
-
response: function (debug, response) {
|
|
8
|
-
console.log(
|
|
9
|
-
'Response Headers:', response.headers,
|
|
10
|
-
'from', response.config.url
|
|
11
|
-
)
|
|
12
|
-
},
|
|
13
|
-
error: function (debug, error) {
|
|
14
|
-
// Read https://www.npmjs.com/package/axios#handling-errors for more info
|
|
15
|
-
console.error('Boom', error)
|
|
16
|
-
}
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
describe('here', async () => {
|
|
20
|
-
it('here', async () => {
|
|
21
|
-
console.log(process.env.HERE_API_KEY)
|
|
22
|
-
const rows = [{latitude:0, longitude:0, fixtime:new Date().toISOString(), speed:0, course:0}]
|
|
23
|
-
console.dir(await here.routeMatch(rows), {depth: null})
|
|
24
|
-
})
|
|
25
|
-
})
|