fleetmap-reports 2.0.303 → 2.0.304

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": "2.0.303",
3
+ "version": "2.0.304",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -16,15 +16,18 @@ function processDevices (from, to, devices, data, userData) {
16
16
  for (const d of devices) {
17
17
  const positions = data.route.filter(t => t.deviceId === d.id)
18
18
 
19
- const rows = []
19
+ const rowsBySensor = {}
20
20
  const currentStatus = {}
21
21
  positions.forEach((p, index) => {
22
22
  userData.sensors.forEach(s => {
23
+ if (!rowsBySensor[s.sensor]) {
24
+ rowsBySensor[s.sensor] = []
25
+ }
23
26
  if (currentStatus[s.sensor] !== undefined) {
24
27
  if (currentStatus[s.sensor].value !== p.attributes[s.id]) {
25
- const duration = new Date(p.fixTime).getTime() - new Date(currentStatus[s.sensor].startTime).getTime()
26
- if (duration >= (userData.minimumMinutes * 60 * 1000) || rows.length === 0) {
27
- rows.push({
28
+ const duration = new Date(positions[index - 1].fixTime).getTime() - new Date(currentStatus[s.sensor].startTime).getTime()
29
+ if ((duration >= (userData.minimumMinutes * 60 * 1000)) || rowsBySensor[s.sensor].length === 0) {
30
+ rowsBySensor[s.sensor].push({
28
31
  startTime: currentStatus[s.sensor].startTime,
29
32
  endTime: positions[index - 1].fixTime,
30
33
  endAddress: positions[index - 1].address,
@@ -35,7 +38,7 @@ function processDevices (from, to, devices, data, userData) {
35
38
  })
36
39
  currentStatus[s.sensor] = { value: p.attributes[s.id], startTime: p.fixTime }
37
40
  } else {
38
- const element = rows.pop()
41
+ const element = rowsBySensor[s.sensor].pop()
39
42
  currentStatus[s.sensor] = { value: p.attributes[s.id], startTime: element.startTime }
40
43
  }
41
44
  } else {
@@ -50,6 +53,7 @@ function processDevices (from, to, devices, data, userData) {
50
53
  })
51
54
  })
52
55
 
56
+ const rows = Object.values(rowsBySensor).flat()
53
57
  rows.sort((a, b) => new Date(a.startTime).getTime() - new Date(b.startTime).getTime())
54
58
 
55
59
  if (userData.groupByDay) {