fleetmap-reports 2.0.159 → 2.0.161
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/index.js +4 -0
- package/src/sensor-report.js +65 -0
- package/src/util/fuel.js +2 -0
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -233,5 +233,9 @@ function Reports (config, axios) {
|
|
|
233
233
|
this.driverRankingReportToExcel = (userData, reportData) => {
|
|
234
234
|
return require('./partnerReports/driverranking-report').exportToExcel(userData, reportData)
|
|
235
235
|
}
|
|
236
|
+
|
|
237
|
+
this.sensorReport = (from, to, userData) => {
|
|
238
|
+
return require('./sensor-report').create(from, to, userData, this.traccar)
|
|
239
|
+
}
|
|
236
240
|
}
|
|
237
241
|
module.exports = Reports
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
const automaticReports = require('./automaticReports')
|
|
2
|
+
const traccarHelper = require('./util/traccar')
|
|
3
|
+
const { devicesToProcess } = require('./util/device')
|
|
4
|
+
|
|
5
|
+
function processDevices (from, to, devices, data, userData) {
|
|
6
|
+
const result = []
|
|
7
|
+
|
|
8
|
+
for (const d of devices) {
|
|
9
|
+
const positions = data.route.filter(t => t.deviceId === d.id)
|
|
10
|
+
|
|
11
|
+
const rows = []
|
|
12
|
+
const currentStatus = {}
|
|
13
|
+
positions.forEach(p => {
|
|
14
|
+
userData.sensors.forEach(s => {
|
|
15
|
+
if (currentStatus[s.sensor] !== undefined) {
|
|
16
|
+
if (currentStatus[s.sensor].value !== p.attributes[s.id]) {
|
|
17
|
+
rows.push({
|
|
18
|
+
startTime: currentStatus[s.sensor].startTime,
|
|
19
|
+
endTime: p.fixTime,
|
|
20
|
+
value: currentStatus[s.sensor].value,
|
|
21
|
+
valueDescription: currentStatus[s.sensor].value ? d.attributes[s.sensor + 'on'] : d.attributes[s.sensor + 'off'],
|
|
22
|
+
name: s.name,
|
|
23
|
+
duration: new Date(p.fixTime).getTime() - new Date(currentStatus[s.sensor].startTime).getTime()
|
|
24
|
+
})
|
|
25
|
+
currentStatus[s.sensor] = { value: p.attributes[s.id], startTime: p.fixTime }
|
|
26
|
+
}
|
|
27
|
+
} else {
|
|
28
|
+
currentStatus[s.sensor] = { value: p.attributes[s.id], startTime: p.fixTime }
|
|
29
|
+
}
|
|
30
|
+
})
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
rows.sort((a, b) => new Date(a.startTime).getTime() - new Date(b.startTime).getTime())
|
|
34
|
+
|
|
35
|
+
result.push({
|
|
36
|
+
device: d,
|
|
37
|
+
from,
|
|
38
|
+
to,
|
|
39
|
+
rows
|
|
40
|
+
})
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return result
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async function create (from, to, userData, traccar) {
|
|
47
|
+
const devices = devicesToProcess(userData)
|
|
48
|
+
const sliced = automaticReports.sliceArray(devices, 5)
|
|
49
|
+
const result = []
|
|
50
|
+
|
|
51
|
+
let deviceCount = 0
|
|
52
|
+
for (const slice of sliced) {
|
|
53
|
+
const allInOne = await traccarHelper.getAllInOne(traccar, from, to, slice, true, false, false, false, deviceCount, devices.length)
|
|
54
|
+
const routeData = allInOne.route
|
|
55
|
+
|
|
56
|
+
if (routeData.length > 0) {
|
|
57
|
+
result.push(...processDevices(from, to, slice, { route: routeData }, userData))
|
|
58
|
+
}
|
|
59
|
+
deviceCount = deviceCount + slice.length
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return result
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
exports.create = create
|
package/src/util/fuel.js
CHANGED
|
@@ -35,6 +35,8 @@ function calculateConsumption (d, data) {
|
|
|
35
35
|
fuelConsumption = calculateSpentFuel(spentFuel, d, withFuelUsed)
|
|
36
36
|
} else if (data.route && data.route.length > 1 && data.route[0].attributes.fuelUsed) {
|
|
37
37
|
fuelConsumption = data.route[data.route.length - 1].attributes.fuelUsed - data.route[0].attributes.fuelUsed
|
|
38
|
+
} else if (data.summary) {
|
|
39
|
+
fuelConsumption = data.summary.spentFuel
|
|
38
40
|
}
|
|
39
41
|
return fuelConsumption > 0 ? fuelConsumption : 0
|
|
40
42
|
}
|