fleetmap-reports 1.0.793 → 1.0.795

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.793",
3
+ "version": "1.0.795",
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')
@@ -102,7 +101,6 @@ async function createActivityReportByDevice (from, to, userData, traccarInstance
102
101
  let deviceCount = 0
103
102
  const sliced = automaticReports.sliceArray(allDevices, 20)
104
103
  for (const devices of sliced) {
105
- let summaries = []
106
104
  const needRoute = userData.groupByDay || !userData.allWeek
107
105
  const {
108
106
  trips,
@@ -110,35 +108,9 @@ async function createActivityReportByDevice (from, to, userData, traccarInstance
110
108
  summary
111
109
  } = await traccar.getAllInOne(traccarInstance, from, to, devices, needRoute, true, false, !userData.groupByDay, deviceCount, allDevices.length, 10)
112
110
 
113
- if (userData.groupByDay) {
114
- console.log('trips:' + trips.length)
115
-
116
- if (trips.length) {
117
- tripHelper.checkTripsKms(traccarInstance, from, to, devices, { trips, route })
118
- }
119
-
120
- const dates = getDates(from, to)
121
- for (const date of dates) {
122
- if (userData.allWeek || !userData.weekDays || !userData.dayHours) {
123
- const fromByDay = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0)
124
- const toByDay = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 23, 59, 59)
125
-
126
- const summary = await traccar.getSummary(traccarInstance, fromByDay, toByDay, devices)
127
- summary.forEach(s => {
128
- s.date = date
129
- })
130
- summaries = summaries.concat(summary)
131
- }
132
- }
133
- } else {
134
- summaries = summary
135
- }
136
-
137
- console.log('Summary:' + summaries.length)
138
-
139
111
  // Process report data
140
- if (summaries.length || trips.length) {
141
- 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))
142
114
  }
143
115
  deviceCount += devices.length
144
116
  }
@@ -216,21 +188,19 @@ function processDevices (from, to, devices, data, userData) {
216
188
  })
217
189
  }
218
190
  } else {
219
- const summaryCurrentDay = data.summaries.find(s => {
220
- return s.deviceId === d.id && s.date.getTime() === date.getTime()
221
- })
222
-
223
- if (summaryCurrentDay) {
224
- summaryCurrentDay.engineHours = tripsByDay.reduce((a, b) => a + b.duration, 0)
225
- summaryCurrentDay.distance = distance
226
- summaryCurrentDay.convertedSpentFuel = calculateConsumption(d, { route: deviceRoute, summary: summaryCurrentDay })
227
- summaryCurrentDay.startTime = tripsByDay.length && tripsByDay[0].startTime
228
- summaryCurrentDay.startAddress = tripsByDay.length && tripsByDay[0].startAddress
229
- summaryCurrentDay.endTime = tripsByDay.length && tripsByDay[tripsByDay.length - 1].endTime
230
- summaryCurrentDay.endAddress = tripsByDay.length && tripsByDay[tripsByDay.length - 1].endAddress
231
-
232
- summary.push(summaryCurrentDay)
233
- }
191
+ const summaryCurrentDay = { date, deviceId: d.id }
192
+ summaryCurrentDay.engineHours = tripsByDay.reduce((a, b) => a + b.duration, 0)
193
+ summaryCurrentDay.distance = distance
194
+ summaryCurrentDay.averageSpeed = distance > 0 ? ((trips.reduce((a, b) => a + (b.averageSpeed * b.distance), 0)) / distance) : 0
195
+ summaryCurrentDay.maxSpeed = tripsByDay.reduce((a, b) => { return a > b.maxSpeed ? a : b.maxSpeed }, 0)
196
+ summaryCurrentDay.convertedSpentFuel = calculateConsumption(d, { route: deviceRoute })
197
+ summaryCurrentDay.startTime = tripsByDay.length && tripsByDay[0].startTime
198
+ summaryCurrentDay.startAddress = tripsByDay.length && tripsByDay[0].startAddress
199
+ summaryCurrentDay.endTime = tripsByDay.length && tripsByDay[tripsByDay.length - 1].endTime
200
+ summaryCurrentDay.endAddress = tripsByDay.length && tripsByDay[tripsByDay.length - 1].endAddress
201
+ summaryCurrentDay.startOdometer = trips.length ? trips[0].startOdometer : 0
202
+ summaryCurrentDay.endOdometer = trips.length ? trips[trips.length - 1].endOdometer : 0
203
+ summary.push(summaryCurrentDay)
234
204
  }
235
205
  }
236
206
  } else {
@@ -7,9 +7,9 @@ describe('activity report', function () {
7
7
  it('Activity by device', async () => {
8
8
  const report = await getReports()
9
9
  const userData = await report.getUserData()
10
-
11
- const data = await report.activityReport(new Date(2022, 0, 1, 0, 0, 0, 0),
12
- new Date(2022, 0, 31, 23, 59, 59, 0),
10
+ userData.groupByDay = true
11
+ const data = await report.activityReport(new Date(2023, 0, 1, 0, 0, 0, 0),
12
+ new Date(2023, 0, 31, 23, 59, 59, 0),
13
13
  userData)
14
14
  assert.equal(data.length, 1)
15
15
  const device = data[0].devices.find(d => d.device.id === 22326)