fleetmap-reports 1.0.380 → 1.0.383

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.380",
3
+ "version": "1.0.383",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -1,5 +1,5 @@
1
1
  const automaticReports = require("./automaticReports")
2
- const {convertMS, getDates, getTranslations} = require("./util/utils")
2
+ const {convertMS, getDates, getTranslations, weekDaySelected} = require("./util/utils")
3
3
  const jsPDF = require('jspdf')
4
4
  require('jspdf-autotable')
5
5
  const drivers = require("./util/driver")
@@ -169,20 +169,22 @@ function processDevices(from, to, devices, data, userData) {
169
169
  const distance = tripsByDay.reduce((a, b) => a + b.distance, 0)
170
170
 
171
171
  if(!userData.allWeek && userData.weekDays && userData.dayHours) {
172
- summary.push({
173
- date: date,
174
- deviceId: d.id,
175
- averageSpeed: distance > 0 ? ((tripsByDay.reduce((a, b) => a + (b.averageSpeed * b.distance), 0)) / distance) : 0,
176
- distance: distance,
177
- engineHours: tripsByDay.reduce((a, b) => a + b.duration, 0),
178
- maxSpeed: tripsByDay.reduce((a, b) => {
179
- return a > b.maxSpeed ? a : b.maxSpeed
180
- }, 0),
181
- endOdometer: 0,
182
- startOdometer: 0,
183
- startTime: tripsByDay.length && tripsByDay[0].startTime,
184
- endTime: tripsByDay.length && tripsByDay[tripsByDay.length-1].endTime
185
- })
172
+ if(weekDaySelected(date, userData.weekDays)) {
173
+ summary.push({
174
+ date: date,
175
+ deviceId: d.id,
176
+ averageSpeed: distance > 0 ? ((tripsByDay.reduce((a, b) => a + (b.averageSpeed * b.distance), 0)) / distance) : 0,
177
+ distance: distance,
178
+ engineHours: tripsByDay.reduce((a, b) => a + b.duration, 0),
179
+ maxSpeed: tripsByDay.reduce((a, b) => {
180
+ return a > b.maxSpeed ? a : b.maxSpeed
181
+ }, 0),
182
+ endOdometer: 0,
183
+ startOdometer: 0,
184
+ startTime: tripsByDay.length && tripsByDay[0].startTime,
185
+ endTime: tripsByDay.length && tripsByDay[tripsByDay.length - 1].endTime
186
+ })
187
+ }
186
188
  } else {
187
189
  const summaryCurrentDay = data.summaries.find(s => {
188
190
  return s.deviceId === d.id && s.date.getTime() === date.getTime()})
@@ -471,7 +471,7 @@ function exportSpeedingReportToExcel(userData, reportData) {
471
471
  distance: a.distance && new Intl.NumberFormat(lang, {maximumSignificantDigits: 1}).format(a.distance),
472
472
  maxSpeed: a.attributes.maxSpeed ? Math.round(a.attributes.maxSpeed * 1.85200) : Math.round(a.attributes.speed * 1.85200),
473
473
  duration: convertMS(a.eventTime, true),
474
- fixTime: new Date(a.position.fixTime).toLocaleString(),
474
+ fixTime: getAlertDate(a, userData.user),
475
475
  name: userData.byDriver ? a.deviceName : d.device.name,
476
476
  address: a.position.address + (a.geofenceName ? ' - ' + a.geofenceName : ''),
477
477
  roadSpeedLimit: a.roadSpeedLimit
@@ -44,12 +44,13 @@ async function createTripReportByDevice(from, to, userData, traccar) {
44
44
 
45
45
  devices.sort((a, b) => (a.name > b.name) ? 1 : -1)
46
46
 
47
- //const devicesToSlice = devices.slice()
47
+ const devicesToSlice = devices.slice()
48
+ const sliced = automaticReports.sliceArray(devicesToSlice, 5)
48
49
 
49
50
  console.log('LOADING_MESSAGE:' + devices.map(d => d.name).join(', '))
50
51
  let deviceCount = 0
51
- for(const device of devices) {
52
- const allInOne = await traccarHelper.getAllInOne(traccar, from, to, [device], true, true, true, false)
52
+ for(const slice of sliced) {
53
+ const allInOne = await traccarHelper.getAllInOne(traccar, from, to, slice, true, true, true, false)
53
54
  const tripsData = allInOne.trips
54
55
  const stopsData = allInOne.stops
55
56
  const routeData = allInOne.route
@@ -57,16 +58,15 @@ async function createTripReportByDevice(from, to, userData, traccar) {
57
58
  console.log('Trips:' + tripsData.length)
58
59
 
59
60
  if (tripsData.length > 0) {
60
- trips.checkTripsKms(traccar, from, to, [device], {trips: tripsData, route: routeData})
61
- allData.devices.push(...processDevices(from, to, [device], {
61
+ trips.checkTripsKms(traccar, from, to, slice, {trips: tripsData, route: routeData})
62
+ allData.devices.push(...processDevices(from, to, slice, {
62
63
  trips: tripsData,
63
64
  stops: stopsData,
64
65
  route: routeData
65
66
  }, userData))
66
67
  }
67
-
68
- console.log('LOADING_MESSAGE:' + device.name)
69
- console.log(`PROGRESS_PERC:${++deviceCount / devices.length * 100}`)
68
+ deviceCount = deviceCount + slice.length
69
+ console.log(`PROGRESS_PERC:${deviceCount / devices.length * 100}`)
70
70
  }
71
71
 
72
72
  return allData
@@ -80,6 +80,7 @@ async function getAllInOne(traccar, from, to, devices, getRoutes, getTrips, getS
80
80
  jar: traccar.cookieJar,
81
81
  withCredentials: true
82
82
  }).then(r => r.data).then(x => {
83
+ console.log('LOADING_MESSAGE:' + d.name)
83
84
  return x
84
85
  }))
85
86
  result.push(...(await Promise.all(requests)))
package/src/util/trips.js CHANGED
@@ -1,4 +1,4 @@
1
- const {coordsDistance, convertFromUTC} = require("./utils");
1
+ const {coordsDistance, convertFromUTC, weekDaySelected} = require("./utils");
2
2
 
3
3
  const minDistance = 0
4
4
  const minAvgSpeed = 0
@@ -57,13 +57,7 @@ function isPartialInsideTimetable(t, userData, route){
57
57
 
58
58
  let isPartialInside = false
59
59
 
60
- if((tripStart.getDay() === 0 && userData.weekDays.sunday) ||
61
- (tripStart.getDay() === 1 && userData.weekDays.monday) ||
62
- (tripStart.getDay() === 2 && userData.weekDays.tuesday) ||
63
- (tripStart.getDay() === 3 && userData.weekDays.wednesday) ||
64
- (tripStart.getDay() === 4 && userData.weekDays.thursday) ||
65
- (tripStart.getDay() === 5 && userData.weekDays.friday) ||
66
- (tripStart.getDay() === 6 && userData.weekDays.saturday)) {
60
+ if(weekDaySelected(tripStart, userData.weekDays)) {
67
61
 
68
62
  const startDate = new Date(convertFromUTC(t.startTime, userData.user.attributes.timezone).toISOString().split('T')[0] + ' '+userData.dayHours.startTime)
69
63
  const endDate = new Date(convertFromUTC(t.startTime, userData.user.attributes.timezone).toISOString().split('T')[0] + ' '+userData.dayHours.endTime)
@@ -122,14 +116,7 @@ function isInsideTimetable(t, userData){
122
116
  const tripStart = new Date(t.startTime)
123
117
  const tripEnd = new Date(t.endTime)
124
118
 
125
- if((tripStart.getDay() === 0 && userData.weekDays.sunday) ||
126
- (tripStart.getDay() === 1 && userData.weekDays.monday) ||
127
- (tripStart.getDay() === 2 && userData.weekDays.tuesday) ||
128
- (tripStart.getDay() === 3 && userData.weekDays.wednesday) ||
129
- (tripStart.getDay() === 4 && userData.weekDays.thursday) ||
130
- (tripStart.getDay() === 5 && userData.weekDays.friday) ||
131
- (tripStart.getDay() === 6 && userData.weekDays.saturday)) {
132
-
119
+ if(weekDaySelected(tripStart, userData.weekDays)) {
133
120
  const startDate = new Date(convertFromUTC(t.startTime, userData.user.attributes.timezone).toISOString().split('T')[0] + ' '+userData.dayHours.startTime)
134
121
  const endDate = new Date(convertFromUTC(t.startTime, userData.user.attributes.timezone).toISOString().split('T')[0] + ' '+userData.dayHours.endTime)
135
122
 
package/src/util/utils.js CHANGED
@@ -130,6 +130,16 @@ function convertFromUTC(value, timezone) {
130
130
  return valueDate
131
131
  }
132
132
 
133
+ function weekDaySelected(date, weekDays){
134
+ return (date.getDay() === 0 && weekDays.sunday) ||
135
+ (date.getDay() === 1 && weekDays.monday) ||
136
+ (date.getDay() === 2 && weekDays.tuesday) ||
137
+ (date.getDay() === 3 && weekDays.wednesday) ||
138
+ (date.getDay() === 4 && weekDays.thursday) ||
139
+ (date.getDay() === 5 && weekDays.friday) ||
140
+ (date.getDay() === 6 && weekDays.saturday)
141
+ }
142
+
133
143
  exports.getImgFromUrl = getImgFromUrl
134
144
  exports.convertMS = convertMS
135
145
  exports.coordsDistance = coordsDistance
@@ -140,6 +150,7 @@ exports.convertToLocaleTimeString = convertToLocaleTimeString
140
150
  exports.isClientSide = isClientSide
141
151
  exports.getTimezoneOffset = getTimezoneOffset
142
152
  exports.convertFromUTC = convertFromUTC
153
+ exports.weekDaySelected = weekDaySelected
143
154
  exports.getLogo = (user) => {
144
155
  const host = window ? window.location.hostname : getUserPartner(user).host
145
156
  return getImage(getLogoUrl(host))