fleetmap-reports 1.0.782 → 1.0.783
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/refueling-report.js +83 -45
package/package.json
CHANGED
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
|
}
|