fleetmap-reports 1.0.782 → 1.0.784
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/activity-report.js +34 -29
- package/src/partnerReports/afriquia.js +2 -4
- package/src/refueling-report.js +83 -45
package/package.json
CHANGED
package/src/activity-report.js
CHANGED
|
@@ -83,15 +83,16 @@ async function createActivityReportByDevice (from, to, userData, traccarInstance
|
|
|
83
83
|
to
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
-
const sliced = automaticReports.sliceArray(allDevices,
|
|
86
|
+
const sliced = automaticReports.sliceArray(allDevices, 4)
|
|
87
87
|
let deviceCount = 0
|
|
88
88
|
for (const devices of sliced) {
|
|
89
89
|
let summaries = []
|
|
90
|
+
const needRoute = userData.groupByDay || !userData.allWeek
|
|
90
91
|
const {
|
|
91
92
|
trips,
|
|
92
93
|
route,
|
|
93
94
|
summary
|
|
94
|
-
} = await traccar.getAllInOne(traccarInstance, from, to, devices,
|
|
95
|
+
} = await traccar.getAllInOne(traccarInstance, from, to, devices, needRoute, true, false, !userData.groupByDay, deviceCount, allDevices.length)
|
|
95
96
|
|
|
96
97
|
if (userData.groupByDay) {
|
|
97
98
|
console.log('trips:' + trips.length)
|
|
@@ -400,20 +401,22 @@ function exportActivityReportToPDFVehicle (doc, translations, reportData, userDa
|
|
|
400
401
|
reportData.devices.forEach(d => {
|
|
401
402
|
const group = userData.groups.find(g => d.device.groupId === g.id)
|
|
402
403
|
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
404
|
+
if (d.summary) {
|
|
405
|
+
const temp = [
|
|
406
|
+
d.device.name,
|
|
407
|
+
group ? group.name : '',
|
|
408
|
+
d.summary[0].startTime ? new Date(d.summary[0].startTime).toLocaleString() : '',
|
|
409
|
+
d.summary[0].endTime ? new Date(d.summary[0].endTime).toLocaleString() : '',
|
|
410
|
+
Number((d.summary[0].distance / 1000).toFixed(1)),
|
|
411
|
+
Number((d.summary[0].startOdometer / 1000).toFixed(1)),
|
|
412
|
+
Number((d.summary[0].endOdometer / 1000).toFixed(1)),
|
|
413
|
+
Math.round(d.summary[0].averageSpeed * 1.85200),
|
|
414
|
+
Math.round(d.summary[0].maxSpeed * 1.85200),
|
|
415
|
+
convertMS(d.summary[0].engineHours),
|
|
416
|
+
d.summary[0].convertedSpentFuel >= 0 ? d.summary[0].convertedSpentFuel : 0
|
|
417
|
+
]
|
|
418
|
+
data.push(temp)
|
|
419
|
+
}
|
|
417
420
|
})
|
|
418
421
|
|
|
419
422
|
const footValues = ['Total:' + reportData.devices.length,
|
|
@@ -718,19 +721,21 @@ function exportActivityReportToExcelVehicle (settings, translations, reportData,
|
|
|
718
721
|
reportData.devices.forEach(d => {
|
|
719
722
|
const group = userData.groups.find(g => d.device.groupId === g.id)
|
|
720
723
|
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
724
|
+
if (d.summary) {
|
|
725
|
+
data = data.concat([{
|
|
726
|
+
name: d.device.name,
|
|
727
|
+
group: group ? group.name : '',
|
|
728
|
+
start: d.summary[0].startTime ? new Date(d.summary[0].startTime).toLocaleString() : '',
|
|
729
|
+
end: d.summary[0].endTime ? new Date(d.summary[0].endTime).toLocaleString() : '',
|
|
730
|
+
distance: Number((d.summary[0].distance / 1000).toFixed(0)),
|
|
731
|
+
startOdometer: Number((d.summary[0].startOdometer / 1000).toFixed(0)),
|
|
732
|
+
endOdometer: Number((d.summary[0].endOdometer / 1000).toFixed(0)),
|
|
733
|
+
avgSpeed: Math.round(d.summary[0].averageSpeed * 1.85200),
|
|
734
|
+
maxSpeed: Math.round(d.summary[0].maxSpeed * 1.85200),
|
|
735
|
+
engineHours: convertMS(d.summary[0].engineHours),
|
|
736
|
+
spentFuel: d.summary[0].convertedSpentFuel >= 0 ? d.summary[0].convertedSpentFuel : 0
|
|
737
|
+
}])
|
|
738
|
+
}
|
|
734
739
|
})
|
|
735
740
|
console.log(data)
|
|
736
741
|
return {
|
|
@@ -7,10 +7,6 @@ function calculateLastStopTime (stopTime, to, time) {
|
|
|
7
7
|
return stopTime + (to.getTime() - new Date(time).getTime())
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
function calculateFirstStopTime (stopTime, from, time) {
|
|
11
|
-
return stopTime + (new Date(time).getTime() - from.getTime())
|
|
12
|
-
}
|
|
13
|
-
|
|
14
10
|
async function createActivityReport (from, to, userData, traccarInstance) {
|
|
15
11
|
const unauthorizedGeofences = []
|
|
16
12
|
const authorizedGeofences = []
|
|
@@ -126,4 +122,6 @@ async function createActivityReport (from, to, userData, traccarInstance) {
|
|
|
126
122
|
return reportData
|
|
127
123
|
}
|
|
128
124
|
|
|
125
|
+
|
|
126
|
+
|
|
129
127
|
exports.createActivityReport = createActivityReport
|
package/src/refueling-report.js
CHANGED
|
@@ -7,7 +7,7 @@ const odoo = require('./util/odoo')
|
|
|
7
7
|
const traccarHelper = require('./util/traccar')
|
|
8
8
|
const { calculateFuelDiff, getRefuelingLiters } = require('./util/fuel')
|
|
9
9
|
|
|
10
|
-
const positionsToCheck = 15
|
|
10
|
+
// const positionsToCheck = 15
|
|
11
11
|
|
|
12
12
|
async function createRefuelingReport (from, to, userData, traccar) {
|
|
13
13
|
console.log('Create RefuelingReport')
|
|
@@ -119,6 +119,86 @@ function coordsDistance (lon1, lat1, lon2, lat2) {
|
|
|
119
119
|
return distance.default(from, to) * 1000
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
+
/* function isStoped (position) {
|
|
123
|
+
return !position.attributes.ignition || position.attributes.rpm === 0
|
|
124
|
+
} */
|
|
125
|
+
|
|
126
|
+
/* function analyseRouteRefuelingOnStops (data, d, refuelingPositions) {
|
|
127
|
+
let refuelingActivated = false
|
|
128
|
+
let currentValue = null
|
|
129
|
+
let positionsChecked = 0
|
|
130
|
+
let lastRefuelingIndex = 0
|
|
131
|
+
data.route.forEach(function (element, index, array) {
|
|
132
|
+
if (isStoped(element) && refuelingActivated && !currentValue) {
|
|
133
|
+
// Ignition is off and Refueling is Active and there is no current value
|
|
134
|
+
|
|
135
|
+
// Get 5 position before the ignition off to calculate the current value of the fuel tank level
|
|
136
|
+
// lastRefuelingIndex is used to avoid re-analyzing positions prior to a refueling
|
|
137
|
+
const before = (index > 5 ? array.slice((index - 6 < lastRefuelingIndex ? lastRefuelingIndex : index - 6), index - 1) : array.slice(0, index - 1)).filter(b => b.attributes.ignition && b.attributes.fuel)
|
|
138
|
+
currentValue = Math.round(before.reduce((a, b) => a + b.attributes.fuel, 0) / before.length)
|
|
139
|
+
|
|
140
|
+
positionsChecked = 0
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (element.attributes.ignition && refuelingActivated && currentValue) {
|
|
144
|
+
// Ignition is on and Refueling is Active and there is a current value
|
|
145
|
+
// Calculate the value of the fuel tank level after turning the ignition back on
|
|
146
|
+
const after = (array.length > index + 5 ? array.slice(index, index + 1) : array.slice(index)).filter(b => b.attributes.ignition && b.attributes.fuel)
|
|
147
|
+
const newValue = Math.round(after.reduce((a, b) => a + b.attributes.fuel, 0) / after.length)
|
|
148
|
+
|
|
149
|
+
const diff = calculateFuelDiff(currentValue, newValue, d, element)
|
|
150
|
+
if (diff > 20) {
|
|
151
|
+
// New refueling detected
|
|
152
|
+
const value = getRefuelingLiters(d, element, diff)
|
|
153
|
+
refuelingPositions.push({position: element, date: element.fixTime, diff: value})
|
|
154
|
+
lastRefuelingIndex = index
|
|
155
|
+
positionsChecked = positionsToCheck + 1 // to reset values
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (positionsChecked > positionsToCheck) {
|
|
159
|
+
refuelingActivated = false
|
|
160
|
+
currentValue = null
|
|
161
|
+
positionsChecked = 0
|
|
162
|
+
} else {
|
|
163
|
+
positionsChecked++
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (element.attributes.ignition && !refuelingActivated) {
|
|
168
|
+
refuelingActivated = true
|
|
169
|
+
}
|
|
170
|
+
})
|
|
171
|
+
} */
|
|
172
|
+
|
|
173
|
+
function analyseRouteRefueling (data, d, refuelingPositions) {
|
|
174
|
+
let startValue = 0
|
|
175
|
+
let currentValue = 0
|
|
176
|
+
let refuelingActivated = false
|
|
177
|
+
data.route.forEach(function (element, index, array) {
|
|
178
|
+
if (!refuelingActivated) {
|
|
179
|
+
startValue = element.attributes.fuel
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const endValue = array.length > index + 2 ? array[index + 2].attributes.fuel : undefined
|
|
183
|
+
const diff = calculateFuelDiff(startValue, endValue, d, element)
|
|
184
|
+
|
|
185
|
+
if (diff > 5 && !refuelingActivated) {
|
|
186
|
+
refuelingActivated = true
|
|
187
|
+
currentValue = diff
|
|
188
|
+
} else if (refuelingActivated && currentValue <= diff) {
|
|
189
|
+
currentValue = diff
|
|
190
|
+
} else {
|
|
191
|
+
if (currentValue > 20) {
|
|
192
|
+
// New refueling detected
|
|
193
|
+
const value = getRefuelingLiters(d, element, currentValue)
|
|
194
|
+
refuelingPositions.push({ position: element, date: element.fixTime, diff: value })
|
|
195
|
+
currentValue = 0
|
|
196
|
+
}
|
|
197
|
+
refuelingActivated = false
|
|
198
|
+
}
|
|
199
|
+
})
|
|
200
|
+
}
|
|
201
|
+
|
|
122
202
|
async function calculateRefuelingPositions (userData, d, data) {
|
|
123
203
|
const refuelingPositions = []
|
|
124
204
|
|
|
@@ -137,50 +217,8 @@ async function calculateRefuelingPositions (userData, d, data) {
|
|
|
137
217
|
}
|
|
138
218
|
})
|
|
139
219
|
} else {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
let positionsChecked = 0
|
|
143
|
-
let lastRefuelingIndex = 0
|
|
144
|
-
data.route.forEach(function (element, index, array) {
|
|
145
|
-
if (!element.attributes.ignition && refuelingActivated && !currentValue) {
|
|
146
|
-
// Ignition is off and Refueling is Active and there is no current value
|
|
147
|
-
|
|
148
|
-
// Get 5 position before the ignition off to calculate the current value of the fuel tank level
|
|
149
|
-
// lastRefuelingIndex is used to avoid re-analyzing positions prior to a refueling
|
|
150
|
-
const before = (index > 5 ? array.slice((index - 6 < lastRefuelingIndex ? lastRefuelingIndex : index - 6), index - 1) : array.slice(0, index - 1)).filter(b => b.attributes.ignition && b.attributes.fuel)
|
|
151
|
-
currentValue = Math.round(before.reduce((a, b) => a + b.attributes.fuel, 0) / before.length)
|
|
152
|
-
|
|
153
|
-
positionsChecked = 0
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
if (element.attributes.ignition && refuelingActivated && currentValue) {
|
|
157
|
-
// Ignition is on and Refueling is Active and there is a current value
|
|
158
|
-
// Calculate the value of the fuel tank level after turning the ignition back on
|
|
159
|
-
const after = (array.length > index + 5 ? array.slice(index, index + 1) : array.slice(index)).filter(b => b.attributes.ignition && b.attributes.fuel)
|
|
160
|
-
const newValue = Math.round(after.reduce((a, b) => a + b.attributes.fuel, 0) / after.length)
|
|
161
|
-
|
|
162
|
-
const diff = calculateFuelDiff(currentValue, newValue, d, element)
|
|
163
|
-
if (diff > 20) {
|
|
164
|
-
// New refueling detected
|
|
165
|
-
const value = getRefuelingLiters(d, element, diff)
|
|
166
|
-
refuelingPositions.push({ position: element, date: element.fixTime, diff: value })
|
|
167
|
-
lastRefuelingIndex = index
|
|
168
|
-
positionsChecked = positionsToCheck + 1 // to reset values
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
if (positionsChecked > positionsToCheck) {
|
|
172
|
-
refuelingActivated = false
|
|
173
|
-
currentValue = null
|
|
174
|
-
positionsChecked = 0
|
|
175
|
-
} else {
|
|
176
|
-
positionsChecked++
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
if (element.attributes.ignition && !refuelingActivated) {
|
|
181
|
-
refuelingActivated = true
|
|
182
|
-
}
|
|
183
|
-
})
|
|
220
|
+
// analyseRouteRefuelingOnStops(data, d, refuelingPositions)
|
|
221
|
+
analyseRouteRefueling(data, d, refuelingPositions)
|
|
184
222
|
}
|
|
185
223
|
return refuelingPositions
|
|
186
224
|
}
|