fleetmap-reports 1.0.570 → 1.0.572

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/zone-report.js +11 -47
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fleetmap-reports",
3
- "version": "1.0.570",
3
+ "version": "1.0.572",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -3,6 +3,7 @@ const automaticReports = require('./automaticReports')
3
3
  const { convertMS, convertToLocaleString, getTranslations, convertToFeature, convertPositionToFeature } = require('./util/utils')
4
4
  const jsPDF = require('jspdf')
5
5
  require('jspdf-autotable')
6
+ const traccarHelper = require('./util/traccar')
6
7
  const { headerFromUser } = require('./util/pdfDocument')
7
8
  const { getStyle } = require('./reportStyle')
8
9
  const { getUserPartner } = require('fleetmap-partners')
@@ -63,14 +64,15 @@ async function createZoneReport (from, to, userData, traccar) {
63
64
 
64
65
  let deviceCount = 0
65
66
  for (const slice of sliced) {
66
- const data = await getAllInOne(
67
+ const data = await traccarHelper.getAllInOne(
67
68
  traccar, from, to, slice, true, false, false, false,
68
- deviceCount, devices.length, sliceSize, deviceChunk, undefined, userData)
69
+ deviceCount, devices.length, sliceSize, deviceChunk, undefined)
69
70
 
70
- console.log('Geofence Enter/Exit Alerts:' + data.length)
71
+ const alerts = getInAndOutEvents(slice, data.route, userData)
72
+ console.log('Geofence Enter/Exit Alerts:' + alerts.length)
71
73
 
72
- if (data.length) {
73
- allData.devices.push(...await processDevices(from, to, devices, userData.drivers, userData.geofences, data, traccar))
74
+ if (alerts.length) {
75
+ allData.devices.push(...await processDevices(from, to, devices, userData.drivers, userData.geofences, { alerts, route: data.route }, traccar))
74
76
  }
75
77
  deviceCount = deviceCount + slice.length
76
78
  }
@@ -80,52 +82,11 @@ async function createZoneReport (from, to, userData, traccar) {
80
82
  return reportData
81
83
  }
82
84
 
83
- async function getRoute (
84
- traccar,
85
- from,
86
- to,
87
- devices,
88
- currentDeviceCount = 0,
89
- totalDevices = devices.length,
90
- sliceSize = 5,
91
- devicesPerRequest = 1,
92
- counter = undefined,
93
- userData) {
94
- const url = `/reports/allinone?from=${from.toISOString()}&to=${to.toISOString()}&type=route`
95
- const sliced = automaticReports.sliceArray(devices, sliceSize)
96
- const result = []
97
- console.log('getAll, slicing', sliceSize)
98
- let iteration = 0
99
- for (const chunk of sliced) {
100
- console.log('iteration', ++iteration)
101
- const requests = []
102
- for (const _chunk of automaticReports.sliceArray(chunk, devicesPerRequest)) {
103
- const u = url + '&' + _chunk.map(d => `deviceId=${d.id}`).join('&')
104
- requests.push(
105
- traccar.axios.get(u, {
106
- jar: traccar.cookieJar,
107
- withCredentials: true
108
- }).then(r => r.data).then(x => {
109
- if (counter) {
110
- counter.count += devicesPerRequest
111
- console.log(`PROGRESS_PERC:${counter.count / totalDevices * 100}`)
112
- } else {
113
- currentDeviceCount += devicesPerRequest
114
- console.log(`PROGRESS_PERC:${currentDeviceCount / totalDevices * 100}`)
115
- }
116
- return getInAndOutEvents(devices, x.route, userData)
117
- }))
118
- }
119
- result.push(...(await Promise.all(requests)))
120
- }
121
- return result.flat()
122
- }
123
-
124
85
  async function processDevices (from, to, devices, drivers, geofences, data) {
125
86
  const devicesResult = []
126
87
 
127
88
  for (const d of devices) {
128
- const alerts = data.filter(t => t.deviceId === d.id)
89
+ const alerts = data.alerts.filter(t => t.deviceId === d.id)
129
90
  if (alerts.length > 0) {
130
91
  // const response = await traccar.reports.reportsRouteGet(from, to, [d.id])
131
92
 
@@ -144,12 +105,15 @@ async function processDevices (from, to, devices, drivers, geofences, data) {
144
105
  const geofence = geofences.find(g => g.id === a.geofenceId)
145
106
  if (zoneInData[a.geofenceId]) {
146
107
  const totalInTime = moment(a.position.fixTime).diff(moment(zoneInData[a.geofenceId].position.fixTime), 'seconds')
108
+ const route = data.route.filter(p => p.fixTime >= zoneInData[a.geofenceId].position.fixTime &&
109
+ p.fixTime <= a.position.fixTime)
147
110
  if (geofence) {
148
111
  zoneInOutData.push({
149
112
  inTime: zoneInData[a.geofenceId].position,
150
113
  outTime: a.position,
151
114
  totalTime: totalInTime,
152
115
  geofenceName: geofence.name,
116
+ stopped: route.filter(p => !p.attributes.ignition).length > 0,
153
117
  driverName: zoneInData[a.geofenceId].position.driverName
154
118
  })
155
119
  }