fleetmap-reports 1.0.792 → 1.0.794

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.792",
3
+ "version": "1.0.794",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -10,7 +10,6 @@ const { getStyle } = require('./reportStyle')
10
10
  const { getUserPartner } = require('fleetmap-partners')
11
11
  const traccar = require('./util/traccar')
12
12
  const { isInsideTimetable, isPartialInsideTimetable, calculateTrip } = require('./util/trips')
13
- const tripHelper = require('./util/trips')
14
13
  const { devicesToProcess } = require('./util/device')
15
14
  const { getDriverData } = require('./util/driver')
16
15
  const { calculateConsumption } = require('./util/fuel')
@@ -74,16 +73,15 @@ async function createActivityReportByGroup (from, to, userData, traccarInstance)
74
73
  return reportData
75
74
  }
76
75
 
77
- async function executeServerSide (allData, sliced, from, to, userData) {
78
- const requests = []
76
+ async function executeServerSide (allData, sliced, from, to, userData, totalDevices) {
77
+ let deviceCount = 0
79
78
  for (const devices of sliced) {
80
79
  const url = `https://${process.env.SERVER_HOST}/reports/activity-report`
81
- requests.push(axios.post(url, { from, to, userData: { ...userData, devices } }, { withCredentials: true }).then(d => {
82
- const result = d.data
83
- allData.devices.push(...(result[0].devices))
84
- }))
80
+ const data = await axios.post(url, { from, to, userData: { ...userData, devices } }, { withCredentials: true }).then(d => d.data)
81
+ allData.devices.push(...(data[0].devices))
82
+ deviceCount = deviceCount + devices.length
83
+ console.log(`PROGRESS_PERC:${deviceCount / totalDevices * 100}`)
85
84
  }
86
- await Promise.all(requests)
87
85
  }
88
86
 
89
87
  async function createActivityReportByDevice (from, to, userData, traccarInstance) {
@@ -97,13 +95,12 @@ async function createActivityReportByDevice (from, to, userData, traccarInstance
97
95
  }
98
96
 
99
97
  if (isClientSide() && allDevices.length > 200) {
100
- const sliced = automaticReports.sliceArray(allDevices, 60)
98
+ const sliced = automaticReports.sliceArray(allDevices, 50)
101
99
  await executeServerSide(allData, sliced, from, to, userData, allDevices.length)
102
100
  } else {
103
101
  let deviceCount = 0
104
102
  const sliced = automaticReports.sliceArray(allDevices, 20)
105
103
  for (const devices of sliced) {
106
- let summaries = []
107
104
  const needRoute = userData.groupByDay || !userData.allWeek
108
105
  const {
109
106
  trips,
@@ -111,35 +108,9 @@ async function createActivityReportByDevice (from, to, userData, traccarInstance
111
108
  summary
112
109
  } = await traccar.getAllInOne(traccarInstance, from, to, devices, needRoute, true, false, !userData.groupByDay, deviceCount, allDevices.length, 10)
113
110
 
114
- if (userData.groupByDay) {
115
- console.log('trips:' + trips.length)
116
-
117
- if (trips.length) {
118
- tripHelper.checkTripsKms(traccarInstance, from, to, devices, { trips, route })
119
- }
120
-
121
- const dates = getDates(from, to)
122
- for (const date of dates) {
123
- if (userData.allWeek || !userData.weekDays || !userData.dayHours) {
124
- const fromByDay = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0)
125
- const toByDay = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 23, 59, 59)
126
-
127
- const summary = await traccar.getSummary(traccarInstance, fromByDay, toByDay, devices)
128
- summary.forEach(s => {
129
- s.date = date
130
- })
131
- summaries = summaries.concat(summary)
132
- }
133
- }
134
- } else {
135
- summaries = summary
136
- }
137
-
138
- console.log('Summary:' + summaries.length)
139
-
140
111
  // Process report data
141
- if (summaries.length || trips.length) {
142
- allData.devices = allData.devices.concat(processDevices(from, to, devices, { summaries, trips, route }, userData))
112
+ if (summary.length || trips.length) {
113
+ allData.devices = allData.devices.concat(processDevices(from, to, devices, { summary, trips, route }, userData))
143
114
  }
144
115
  deviceCount += devices.length
145
116
  }