fleetmap-reports 1.0.881 → 1.0.883
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
|
@@ -1,25 +1,62 @@
|
|
|
1
|
+
const traccarHelper = require('../util/traccar')
|
|
2
|
+
const { isInsideTimetable, isPartialInsideTimetable } = require('../util/trips')
|
|
1
3
|
|
|
2
4
|
async function createDailyUseReport (from, to, userData, traccar) {
|
|
3
5
|
const reportData = []
|
|
4
6
|
|
|
5
7
|
const devices = userData.devices
|
|
6
8
|
|
|
9
|
+
const allInOne = await traccarHelper.getAllInOne(traccar, from, to, devices, true, true, true, true)
|
|
10
|
+
|
|
7
11
|
for (const d of devices) {
|
|
12
|
+
const group = userData.groups.find(g => g.id === d.groupId)
|
|
13
|
+
|
|
14
|
+
const deviceTrips = allInOne.trips.filter(t => t.deviceId === d.id)
|
|
15
|
+
const deviceRoute = allInOne.route.filter(t => t.deviceId === d.id)
|
|
16
|
+
const deviceStops = allInOne.stops.filter(t => t.deviceId === d.id)
|
|
17
|
+
|
|
18
|
+
userData.weekDays = {
|
|
19
|
+
sunday: true,
|
|
20
|
+
monday: true,
|
|
21
|
+
tuesday: true,
|
|
22
|
+
wednesday: true,
|
|
23
|
+
thursday: true,
|
|
24
|
+
friday: true,
|
|
25
|
+
saturday: true
|
|
26
|
+
}
|
|
27
|
+
userData.dayHours = {
|
|
28
|
+
startTime: '00:00',
|
|
29
|
+
endTime: '12:00'
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const morningTrips = deviceTrips.filter(t => isInsideTimetable(t, userData) || isPartialInsideTimetable(t, userData, deviceRoute))
|
|
33
|
+
const morningStart = morningTrips.length && new Date(morningTrips[0].startTime)
|
|
34
|
+
const morningEnd = morningTrips.length && new Date(morningTrips[morningTrips.length - 1].endTime)
|
|
35
|
+
|
|
36
|
+
userData.dayHours = {
|
|
37
|
+
startTime: '12:00',
|
|
38
|
+
endTime: '23:59'
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const afternoonTrips = deviceTrips.filter(t => isInsideTimetable(t, userData) || isPartialInsideTimetable(t, userData, deviceRoute))
|
|
42
|
+
const afternoonStart = afternoonTrips.length && new Date(afternoonTrips[0].startTime)
|
|
43
|
+
const afternoonEnd = afternoonTrips.length && new Date(afternoonTrips[afternoonTrips.length - 1].endTime)
|
|
44
|
+
|
|
8
45
|
reportData.push({
|
|
9
46
|
device: d.name,
|
|
10
47
|
licensePlate: d.attributes.license_plate,
|
|
11
|
-
group:
|
|
12
|
-
morningStart
|
|
13
|
-
morningEnd
|
|
14
|
-
morningTime:
|
|
15
|
-
lunch:
|
|
16
|
-
afternoonStart
|
|
17
|
-
afternoonEnd
|
|
18
|
-
afternoonTime:
|
|
19
|
-
totalTime:
|
|
20
|
-
totalDrivingTime:
|
|
21
|
-
totalStops:
|
|
22
|
-
totalDistance:
|
|
48
|
+
group: group ? group.name : '',
|
|
49
|
+
morningStart,
|
|
50
|
+
morningEnd,
|
|
51
|
+
morningTime: morningStart && morningEnd ? morningEnd.getTime() - morningStart.getTime() : 0,
|
|
52
|
+
lunch: morningEnd && afternoonStart ? afternoonStart.getTime() - morningEnd.getTime() : 0,
|
|
53
|
+
afternoonStart,
|
|
54
|
+
afternoonEnd,
|
|
55
|
+
afternoonTime: afternoonStart && afternoonEnd ? afternoonEnd.getTime() - afternoonStart.getTime() : 0,
|
|
56
|
+
totalTime: morningStart && afternoonEnd ? afternoonEnd.getTime() - morningStart.getTime() : 0,
|
|
57
|
+
totalDrivingTime: deviceTrips.reduce((a, b) => a + b.duration, 0),
|
|
58
|
+
totalStops: deviceStops.length,
|
|
59
|
+
totalDistance: deviceTrips.reduce((a, b) => a + b.distance, 0)
|
|
23
60
|
})
|
|
24
61
|
}
|
|
25
62
|
|
|
@@ -2,6 +2,7 @@ const { getReports } = require('./index')
|
|
|
2
2
|
const { createPerformanceReport } = require('../partnerReports/performance-report')
|
|
3
3
|
const assert = require('assert')
|
|
4
4
|
const { convertMS } = require('../util/utils')
|
|
5
|
+
const {createDailyUseReport} = require("../partnerReports/dailyuse-report");
|
|
5
6
|
// eslint-disable-next-line no-undef
|
|
6
7
|
describe('performance', function () {
|
|
7
8
|
// eslint-disable-next-line no-undef
|
|
@@ -33,4 +34,15 @@ describe('performance', function () {
|
|
|
33
34
|
console.log(data)
|
|
34
35
|
assert.equal(data[0].consumption, 168.51989999999998)
|
|
35
36
|
}, 8000000)
|
|
37
|
+
|
|
38
|
+
it('dailyuse report inofleet', async () => {
|
|
39
|
+
const report = await getReports()
|
|
40
|
+
const userData = await report.getUserData()
|
|
41
|
+
const data = await createDailyUseReport(
|
|
42
|
+
new Date(Date.UTC(2023, 9, 1, 0, 0, 0, 0)),
|
|
43
|
+
new Date(Date.UTC(2023, 9, 1, 23, 59, 59, 0)),
|
|
44
|
+
userData,
|
|
45
|
+
report.traccar)
|
|
46
|
+
console.log(data)
|
|
47
|
+
}, 8000000)
|
|
36
48
|
})
|