fleetmap-reports 1.0.578 → 1.0.581

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,10 +1,10 @@
1
1
  {
2
2
  "name": "fleetmap-reports",
3
- "version": "1.0.578",
3
+ "version": "1.0.581",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
7
- "test": "email=$email & password=$password & jest"
7
+ "test": "jest"
8
8
  },
9
9
  "keywords": [],
10
10
  "author": "",
@@ -20,15 +20,6 @@ function fuelSignalInverter (device) {
20
20
  return device.attributes.fuel_low_threshold <= device.attributes.fuel_high_threshold ? 1 : -1
21
21
  }
22
22
 
23
- function calculateFuelDiff (a, b, device) {
24
- const diff = (b - a) * fuelSignalInverter(device)
25
- if (device.attributes.xpert) {
26
- return diff
27
- } else {
28
- return (diff * 100) / Math.abs(device.attributes.fuel_low_threshold - device.attributes.fuel_high_threshold)
29
- }
30
- }
31
-
32
23
  function calculateXpertSpentFuel (date, positions) {
33
24
  const begin = moment(date, 'YYYY-MM-DD').startOf('day')
34
25
  const end = moment(date, 'YYYY-MM-DD').endOf('day')
@@ -66,7 +57,6 @@ function calculateSpentFuel (value, device) {
66
57
 
67
58
  exports.sliceArray = sliceArray
68
59
  exports.deviceWithFuelInfo = deviceWithFuelInfo
69
- exports.calculateFuelDiff = calculateFuelDiff
70
60
  exports.calculateSpentFuel = calculateSpentFuel
71
61
  exports.calculateXpertSpentFuel = calculateXpertSpentFuel
72
62
  exports.calculateXpertDistance = calculateXpertDistance
package/src/kms-report.js CHANGED
@@ -303,7 +303,7 @@ async function exportKmsReportToPDF (userData, reportData) {
303
303
  const data = []
304
304
  if (userData.byDriver) {
305
305
  reportData.drivers.forEach(d => {
306
- const group = userData.groups.find(g => g.drivers.includes(d.driver.id))
306
+ const group = userData.groups.find(g => g.drivers && g.drivers.includes(d.driver.id))
307
307
 
308
308
  const temp = [
309
309
  d.driver.name,
@@ -363,17 +363,15 @@ function exportLocationReportToExcel (userData, reportData) {
363
363
  { label: translations.report.address, value: 'address' },
364
364
  { label: translations.report.speed, value: 'speed' },
365
365
  { label: translations.report.ignition, value: 'ignition' },
366
- { label: translations.report.driver, value: 'driver' },
367
- { label: 'Latitude', value: 'latitude' },
368
- { label: 'Longitude', value: 'longitude' }
366
+ { label: translations.report.driver, value: 'driver' }
369
367
  ]
370
368
 
371
369
  if (userData.includeTemperature) {
372
370
  headers.push({ label: translations.report.temperature, value: 'temperature' })
373
371
  }
374
372
 
375
- headers.push({ label: 'latitude', value: 'latitude' })
376
- headers.push({ label: 'longitude', value: 'longitude' })
373
+ headers.push({ label: 'Latitude', value: 'latitude' })
374
+ headers.push({ label: 'Longitude', value: 'longitude' })
377
375
 
378
376
  let data = []
379
377
  if (positionsData) {
@@ -5,6 +5,7 @@ const distance = require('@turf/distance')
5
5
  const { getTranslations } = require('./util/utils')
6
6
  const odoo = require('./util/odoo')
7
7
  const traccarHelper = require('./util/traccar')
8
+ const { calculateFuelDiff, getRefuelingLiters } = require('./util/fuel')
8
9
 
9
10
  const positionsToCheck = 15
10
11
 
@@ -158,10 +159,10 @@ async function calculateRefuelingPositions (userData, d, data) {
158
159
  const after = (array.length > index + 5 ? array.slice(index, index + 1) : array.slice(index)).filter(b => b.attributes.ignition && b.attributes.fuel)
159
160
  const newValue = Math.round(after.reduce((a, b) => a + b.attributes.fuel, 0) / after.length)
160
161
 
161
- const diff = automaticReports.calculateFuelDiff(currentValue, newValue, d)
162
+ const diff = calculateFuelDiff(currentValue, newValue, d, element)
162
163
  if (diff > 20) {
163
164
  // New refueling detected
164
- const value = Math.round(diff * d.attributes.fuel_tank_capacity / 100)
165
+ const value = getRefuelingLiters(d, element, diff)
165
166
  refuelingPositions.push({ position: element, date: element.fixTime, diff: value })
166
167
  lastRefuelingIndex = index
167
168
  positionsChecked = positionsToCheck + 1 // to reset values
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable no-undef */
2
- const { getReports } = require('./tests')
2
+ const { getReports } = require('./index')
3
3
  const assert = require('assert')
4
4
 
5
5
  const deviceId = 122575
@@ -7,7 +7,6 @@ const deviceId = 122575
7
7
  describe('Test_Reports', function () {
8
8
  it('Trip by device', async () => {
9
9
  console.log('trip by device')
10
- this.timeout(2000000)
11
10
  const report = await getReports()
12
11
  const userData = await report.getUserData()
13
12
 
@@ -15,8 +15,12 @@ const axios = require('axios').create({ ...traccarConfig.baseOptions, baseURL: t
15
15
  axiosCookieJarSupport(axios)
16
16
 
17
17
  const getReports = async () => {
18
- await new SessionApi(traccarConfig, null, axios).sessionPost(process.env.email, process.env.password)
19
- return new Index(traccarConfig, axios, cookieJar)
18
+ try {
19
+ await new SessionApi(traccarConfig, null, axios).sessionPost(process.env.email, process.env.password)
20
+ return new Index(traccarConfig, axios, cookieJar)
21
+ } catch (e) {
22
+ console.error(e)
23
+ }
20
24
  }
21
25
 
22
26
  exports.getReports = getReports
@@ -1,7 +1,7 @@
1
1
  /* eslint-disable no-undef */
2
- const { getReports } = require('./tests')
2
+ const { getReports } = require('./index')
3
3
  const assert = require('assert')
4
- const utils = require('./util/utils')
4
+ const utils = require('../util/utils')
5
5
 
6
6
  async function getSpeedingReport (report, userData) {
7
7
  const data = await report.speedingReport(
@@ -300,7 +300,7 @@ describe('Test_Reports', function () {
300
300
  console.log('Start')
301
301
  const reports = await getReports()
302
302
  const userData = await reports.getUserData()
303
- const r = await require('./util/traccar').getAllInOne(reports.traccar,
303
+ const r = await require('../util/traccar').getAllInOne(reports.traccar,
304
304
  new Date(2022, 1, 1, 0, 0, 0, 0),
305
305
  new Date(2022, 1, 4, 23, 59, 59, 0),
306
306
  userData.devices,
@@ -0,0 +1,26 @@
1
+ function calculateFuelDiff (a, b, device, p) {
2
+ if (p.protocol === 'teltonika') {
3
+ return b - a
4
+ } else {
5
+ const diff = (b - a) * fuelSignalInverter(device)
6
+ if (device.attributes.xpert) {
7
+ return diff
8
+ } else {
9
+ return (diff * 100) / Math.abs(device.attributes.fuel_low_threshold - device.attributes.fuel_high_threshold)
10
+ }
11
+ }
12
+ }
13
+
14
+ function fuelSignalInverter (device) {
15
+ return device.attributes.fuel_low_threshold <= device.attributes.fuel_high_threshold ? 1 : -1
16
+ }
17
+
18
+ function getRefuelingLiters (d, position, diff) {
19
+ if (position.protocol === 'teltonika' && !position.attributes.io89) {
20
+ return diff
21
+ }
22
+ return Math.round(diff * d.attributes.fuel_tank_capacity / 100)
23
+ }
24
+
25
+ exports.calculateFuelDiff = calculateFuelDiff
26
+ exports.getRefuelingLiters = getRefuelingLiters