fleetmap-reports 1.0.471 → 1.0.473

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,6 +1,6 @@
1
1
  {
2
2
  "name": "fleetmap-reports",
3
- "version": "1.0.471",
3
+ "version": "1.0.473",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
package/src/index.test.js CHANGED
@@ -15,7 +15,6 @@ async function getSpeedingReport (report, userData) {
15
15
 
16
16
  // eslint-disable-next-line no-undef
17
17
  describe('Test_Reports', function () {
18
- this.timeout(500000)
19
18
  // eslint-disable-next-line no-undef
20
19
  it('Speeding by device', async () => {
21
20
  const report = await getReports()
@@ -64,7 +64,7 @@ function processDevices (from, to, devices, data, userData) {
64
64
  if (userData.withDetails) {
65
65
  const ignitions = calculateIgnitions(deviceRoute)
66
66
  for (const ignition of ignitions) {
67
- const dayData = getSummaryData(new Date(ignition.on.fixTime), d, ignition.route, ignition.on, ignition.off)
67
+ const dayData = getSummaryData(new Date(ignition.on.fixTime), d, ignition.route, ignition, undefined)
68
68
  summary.push(dayData)
69
69
  }
70
70
  } else {
@@ -77,7 +77,7 @@ function processDevices (from, to, devices, data, userData) {
77
77
  routeByDay.sort((a, b) => new Date(a.fixTime).getTime() - new Date(b.fixTime).getTime())
78
78
 
79
79
  const ignitions = calculateIgnitions(routeByDay)
80
- const dayData = getSummaryData(date, d, routeByDay, ignitions.length ? ignitions[0].on : undefined, ignitions.length ? ignitions[ignitions.length - 1].off : undefined)
80
+ const dayData = getSummaryData(date, d, routeByDay, undefined, ignitions)
81
81
  summary.push(dayData)
82
82
  }
83
83
  }
@@ -94,14 +94,20 @@ function processDevices (from, to, devices, data, userData) {
94
94
  return devicesResult
95
95
  }
96
96
 
97
- function getSummaryData (date, device, route, start, end) {
97
+ function getSummaryData (date, device, route, ignition, ignitions) {
98
+ const startTime = ignition ? ignition.on.fixTime : (ignitions.length ? ignitions[0].on.fixTime : undefined)
99
+ const endTime = ignition ? ignition.off.fixTime : (ignitions.length ? ignitions[ignitions.length - 1].off.fixTime : undefined)
100
+ const engineHours = ignition
101
+ ? ignition.route[ignition.route.length - 1].attributes.hours - ignition.route[0].attributes.hours
102
+ : (ignitions ? ignitions.reduce((a, b) => a + (b.route[b.route.length - 1].attributes.hours - b.route[0].attributes.hours), 0) : undefined)
103
+
98
104
  return {
99
105
  date,
100
106
  deviceId: device.id,
101
- engineHours: start ? route[route.length - 1].attributes.hours - route[0].attributes.hours : undefined,
107
+ engineHours,
102
108
  totalHours: route.length ? route[route.length - 1].attributes.hours : undefined,
103
- startTime: start ? start.fixTime : undefined,
104
- endTime: end ? end.fixTime : undefined
109
+ startTime,
110
+ endTime
105
111
  }
106
112
  }
107
113
 
@@ -301,7 +301,7 @@ async function getHereEvents (devices, routes, threshold) {
301
301
  ? hereAlerts
302
302
  : hereAlerts.reduce((acc, cur, idx, src) => {
303
303
  if (idx === 1) {
304
- return [cur]
304
+ return [acc]
305
305
  }
306
306
  if (cur.timestamp - src[idx - 1].timestamp > 300000 || cur.roadSpeedLimit !== src[idx - 1].roadSpeedLimit) {
307
307
  return acc.concat(cur)
package/src/util/odoo.js CHANGED
@@ -1,16 +1,14 @@
1
1
 
2
- async function getOdooFuelServices (traccar, from, to) {
3
- const url = `/odoo/reports/refuelingServices?startDate=${from.toDateString()}&endDate=${to.toDateString()}`
2
+ async function getOdooFuelServices(traccar, from, to) {
3
+ const url = `/odoo/reports/refuelingServices?startDate=${from.toDateString()}&endDate=${to.toDateString()}`
4
4
 
5
- console.log('LOADING_MESSAGE:' + url)
6
- const { data } = await traccar.axios.get(url, {
7
- jar: traccar.cookieJar,
8
- withCredentials: true
9
- })
5
+ const {data} = await traccar.axios.get(url,{
6
+ jar: traccar.cookieJar,
7
+ withCredentials: true })
10
8
 
11
- console.log(data)
9
+ console.log(data)
12
10
 
13
- return data
11
+ return data
14
12
  }
15
13
 
16
14
  exports.getOdooFuelServices = getOdooFuelServices