fleetmap-reports 1.0.605 → 1.0.607
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/lang/esCL.js +2 -2
- package/package.json +1 -1
- package/src/fuelconsumption-report.js +61 -14
- package/src/speeding-report.js +2 -2
- package/src/tests/speeding.test.js +1 -1
- package/src/trip-report.js +3 -1
- package/src/util/utils.js +4 -0
package/lang/esCL.js
CHANGED
|
@@ -179,7 +179,7 @@ module.exports = {
|
|
|
179
179
|
titleKmsReport: 'Informe de Kms',
|
|
180
180
|
titleIdleReport: 'Informe de Ralenti',
|
|
181
181
|
titleMachinesReport: 'Informe de Maquinas',
|
|
182
|
-
titleStopReport: 'Informe de
|
|
182
|
+
titleStopReport: 'Informe de Paradas',
|
|
183
183
|
from: 'De',
|
|
184
184
|
to: 'a',
|
|
185
185
|
headerStartAddress: 'Lugar de início',
|
|
@@ -204,7 +204,7 @@ module.exports = {
|
|
|
204
204
|
maxSpeed: 'Vel.Max',
|
|
205
205
|
driver: 'Conductor',
|
|
206
206
|
group: 'Grupo',
|
|
207
|
-
address: '
|
|
207
|
+
address: 'Dirección',
|
|
208
208
|
ignition: 'Motor',
|
|
209
209
|
ignitionOn: 'Encendido',
|
|
210
210
|
ignitionOff: 'Apagado',
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@ const refuelingReport = require('./refueling-report')
|
|
|
3
3
|
const traccarHelper = require('./util/traccar')
|
|
4
4
|
const odoo = require('./util/odoo')
|
|
5
5
|
const { devicesToProcess } = require('./util/device')
|
|
6
|
-
const { getTranslations, convertToLocaleString, getLanguage } = require('./util/utils')
|
|
6
|
+
const { getTranslations, convertToLocaleString, getLanguage, convertMS, formatNumber } = require('./util/utils')
|
|
7
7
|
const { getStyle } = require('./reportStyle')
|
|
8
8
|
const { getUserPartner } = require('fleetmap-partners')
|
|
9
9
|
const { addTable, headerFromUser } = require('./util/pdfDocument')
|
|
@@ -100,13 +100,17 @@ function getOdooAvgConsumption (refuelingPositions, trips) {
|
|
|
100
100
|
|
|
101
101
|
if (totalKms === 0 || odooTotalfuel === 0) { return { byKms: 0, byLiters: 0 } }
|
|
102
102
|
|
|
103
|
-
return
|
|
103
|
+
return calculateAvgConsumption(odooTotalfuel, totalKms)
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
function getCanAvgConsumption (distance, spentFuel) {
|
|
107
107
|
if (distance === 0 || spentFuel === 0) { return { byKms: 0, byLiters: 0 } }
|
|
108
108
|
|
|
109
|
-
return
|
|
109
|
+
return calculateAvgConsumption(spentFuel, distance)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function calculateAvgConsumption (fuel, distance) {
|
|
113
|
+
return { byKms: Math.round(fuel * 100 / (distance / 1000)), byLiters: Math.round((distance / 1000) / fuel) }
|
|
110
114
|
}
|
|
111
115
|
|
|
112
116
|
function calculateConsumption (userData, d, day, avgConsumption, data) {
|
|
@@ -144,14 +148,24 @@ function exportFuelConsumptionReportToExcel (userData, reportData) {
|
|
|
144
148
|
return {
|
|
145
149
|
name: d.device.name,
|
|
146
150
|
date: r.date,
|
|
147
|
-
kms: (r.distance / 1000)
|
|
148
|
-
consumption: r.spentFuel > 0 ? r.spentFuel : 0,
|
|
149
|
-
avg_consumption: lang === 'pt-BR' ? r.avgConsumption.byLiters : r.avgConsumption.byKms,
|
|
150
|
-
duration:
|
|
151
|
-
accumulated_kms: (r.endOdometer /
|
|
152
|
-
refueling: r.refueling
|
|
151
|
+
kms: formatNumber(r.distance / 1000, lang),
|
|
152
|
+
consumption: r.spentFuel > 0 ? formatNumber(r.spentFuel, lang) : 0,
|
|
153
|
+
avg_consumption: formatNumber(lang === 'pt-BR' ? r.avgConsumption.byLiters : r.avgConsumption.byKms, lang),
|
|
154
|
+
duration: convertMS(r.duration),
|
|
155
|
+
accumulated_kms: (r.endOdometer / 100).toFixed(1),
|
|
156
|
+
refueling: formatNumber(r.refueling, lang)
|
|
153
157
|
}
|
|
154
158
|
}))
|
|
159
|
+
// Totals
|
|
160
|
+
data = data.concat([{
|
|
161
|
+
date: 'Total:' + d.days.length,
|
|
162
|
+
kms: getTotalKms(userData.user, d.days),
|
|
163
|
+
consumption: getTotalConsumption(userData.user, d.days),
|
|
164
|
+
avg_consumption: getTotalAvgConsumption(userData.user, d.days),
|
|
165
|
+
duration: getTotalDuration(userData.user, d.days),
|
|
166
|
+
refueling: getTotalRefueling(userData.user, d.days)
|
|
167
|
+
}])
|
|
168
|
+
data = data.concat([{}])
|
|
155
169
|
})
|
|
156
170
|
return {
|
|
157
171
|
headers,
|
|
@@ -202,17 +216,22 @@ async function exportFuelConsumptionReportToPDF (userData, reportData) {
|
|
|
202
216
|
d.days.forEach(r =>
|
|
203
217
|
data.push([
|
|
204
218
|
r.date,
|
|
205
|
-
(r.distance / 1000)
|
|
206
|
-
r.spentFuel > 0 ? r.spentFuel : 0,
|
|
207
|
-
lang === 'pt-BR' ?
|
|
208
|
-
|
|
219
|
+
formatNumber(r.distance / 1000, lang),
|
|
220
|
+
r.spentFuel > 0 ? formatNumber(r.spentFuel, lang) : 0,
|
|
221
|
+
formatNumber(lang === 'pt-BR' ? r.avgConsumption.byLiters : r.avgConsumption.byKms, lang),
|
|
222
|
+
convertMS(r.duration),
|
|
209
223
|
(r.endOdometer / 1000).toFixed(1),
|
|
210
224
|
r.refueling
|
|
211
225
|
]))
|
|
212
226
|
console.log(data)
|
|
213
227
|
const footValues = [
|
|
214
228
|
'Total:' + d.days.length,
|
|
215
|
-
|
|
229
|
+
getTotalKms(userData.user, d.days),
|
|
230
|
+
getTotalConsumption(userData.user, d.days),
|
|
231
|
+
getTotalAvgConsumption(userData.user, d.days),
|
|
232
|
+
getTotalDuration(userData.user, d.days),
|
|
233
|
+
'',
|
|
234
|
+
getTotalRefueling(userData.user, d.days)
|
|
216
235
|
]
|
|
217
236
|
|
|
218
237
|
const style = getStyle(getUserPartner(userData.user))
|
|
@@ -231,6 +250,34 @@ function useOdooFuelData (d, route) {
|
|
|
231
250
|
return route.length && !route[0].attributes.fuel && d.attributes.odooId
|
|
232
251
|
}
|
|
233
252
|
|
|
253
|
+
function getTotalKms (user, data) {
|
|
254
|
+
const totalKms = data.reduce((a, b) => a + b.distance, 0)
|
|
255
|
+
return formatNumber(totalKms / 1000, user.attributes.lang)
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
function getTotalConsumption (user, data) {
|
|
259
|
+
const totalConsumption = data.reduce((a, b) => a + (b.spentFuel > 0 ? b.spentFuel : 0), 0)
|
|
260
|
+
return formatNumber(totalConsumption, user.attributes.lang)
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
function getTotalDuration (user, data) {
|
|
264
|
+
const totalDuration = data.reduce((a, b) => a + b.duration, 0)
|
|
265
|
+
return convertMS(totalDuration)
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
function getTotalRefueling (user, data) {
|
|
269
|
+
const totalRefueling = data.reduce((a, b) => a + b.refueling, 0)
|
|
270
|
+
return formatNumber(totalRefueling, user.attributes.lang)
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function getTotalAvgConsumption (user, data) {
|
|
274
|
+
const values = data.map(a => a.distance * a.avgConsumption.byKms).reduce((a, b) => a + b, 0)
|
|
275
|
+
const totalKms = data.reduce((a, b) => a + b.distance, 0)
|
|
276
|
+
|
|
277
|
+
const totalAvgConsumption = values / totalKms
|
|
278
|
+
return formatNumber(totalAvgConsumption, user.attributes.lang)
|
|
279
|
+
}
|
|
280
|
+
|
|
234
281
|
exports.createFuelConsumptionReport = createFuelConsumptionReport
|
|
235
282
|
exports.exportFuelConsumptionReportToPDF = exportFuelConsumptionReportToPDF
|
|
236
283
|
exports.exportFuelConsumptionReportToExcel = exportFuelConsumptionReportToExcel
|
package/src/speeding-report.js
CHANGED
|
@@ -135,7 +135,7 @@ async function getEvents (traccarInstance, from, to, devices, userData, deviceCo
|
|
|
135
135
|
|
|
136
136
|
const events = []
|
|
137
137
|
if (userData.roadSpeedLimits) {
|
|
138
|
-
const hereResults = await getHereEvents(devices, routes, userData.maxSpeedThreshold, userData.
|
|
138
|
+
const hereResults = await getHereEvents(devices, routes, userData.maxSpeedThreshold, userData.minimumIdleMinutes)
|
|
139
139
|
console.log('got', hereResults.length, 'from here')
|
|
140
140
|
events.push(...hereResults)
|
|
141
141
|
} else if (!userData.useVehicleSpeedLimit && userData.customSpeed) {
|
|
@@ -544,7 +544,7 @@ function exportSpeedingReportToExcel (userData, reportData) {
|
|
|
544
544
|
speedLimit: userData.roadSpeedLimits
|
|
545
545
|
? a.roadSpeedLimit
|
|
546
546
|
: userData.useVehicleSpeedLimit
|
|
547
|
-
? Math.round(
|
|
547
|
+
? Math.round(a.attributes.speedLimit * 1.85200)
|
|
548
548
|
: userData.customSpeed
|
|
549
549
|
}
|
|
550
550
|
}))
|
|
@@ -23,7 +23,7 @@ describe('speeding tests', function () {
|
|
|
23
23
|
assert.equal(device.alerts.length, 104) // Total Alerts
|
|
24
24
|
console.log(device.alerts)
|
|
25
25
|
|
|
26
|
-
userData.
|
|
26
|
+
userData.minimumIdleMinutes = 1
|
|
27
27
|
const r = await getSpeedingReport(report, userData)
|
|
28
28
|
r.device.alerts.forEach(a => assert.equal(true, a.eventTime >= 60000))
|
|
29
29
|
assert.equal(r.device.alerts.length, 6) // Total Alerts
|
package/src/trip-report.js
CHANGED
|
@@ -487,7 +487,9 @@ function getTripEnd (user, trip) {
|
|
|
487
487
|
function getDriverName (drivers, driverUniqueId) {
|
|
488
488
|
if (driverUniqueId) {
|
|
489
489
|
const driver = drivers.find(d => d.uniqueId === driverUniqueId)
|
|
490
|
-
return driver
|
|
490
|
+
return driver
|
|
491
|
+
? driver.name + ' ' + ((driver.attributes && driver.attributes.notes) || '')
|
|
492
|
+
: driverUniqueId
|
|
491
493
|
}
|
|
492
494
|
|
|
493
495
|
return ''
|
package/src/util/utils.js
CHANGED
|
@@ -35,6 +35,10 @@ function convertMS (duration, withSeconds) {
|
|
|
35
35
|
return withSeconds ? hours + ':' + minutes + ':' + seconds : hours + ':' + minutes
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
exports.formatNumber = function formatNumber (value, lang) {
|
|
39
|
+
return Intl.NumberFormat(lang, { maximumFractionDigits: 1 }).format(value)
|
|
40
|
+
}
|
|
41
|
+
|
|
38
42
|
function coordsDistance (lon1, lat1, lon2, lat2) {
|
|
39
43
|
const from = turf.point([lon1, lat1])
|
|
40
44
|
const to = turf.point([lon2, lat2])
|