fleetmap-reports 1.0.379 → 1.0.382
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 +1 -1
- package/src/activity-report.js +17 -15
- package/src/index.test.js +6 -6
- package/src/trip-report.js +22 -12
- package/src/util/traccar.js +0 -3
- package/src/util/trips.js +3 -16
- package/src/util/utils.js +11 -0
package/package.json
CHANGED
package/src/activity-report.js
CHANGED
|
@@ -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
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
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()})
|
package/src/index.test.js
CHANGED
|
@@ -200,9 +200,9 @@ describe('Test_Reports', function() {
|
|
|
200
200
|
assert.equal(data.length, 1)
|
|
201
201
|
const device = data[0].devices.find(d => d.device.id===22326)
|
|
202
202
|
assert.equal(device.summary[0].startOdometer, 122502742.59)
|
|
203
|
-
assert.equal(device.summary[0].distance,
|
|
203
|
+
assert.equal(device.summary[0].distance, 1423529.600000009)
|
|
204
204
|
assert.equal(device.summary[0].startTime, '2022-01-01T13:35:47.000+0000')
|
|
205
|
-
assert.equal(device.summary[0].endTime, '2022-01-
|
|
205
|
+
assert.equal(device.summary[0].endTime, '2022-01-31T17:36:27.000+0000')
|
|
206
206
|
}, 40000)
|
|
207
207
|
it('Activity 2 by device', async () => {
|
|
208
208
|
const report = await getReports()
|
|
@@ -235,16 +235,16 @@ describe('Test_Reports', function() {
|
|
|
235
235
|
const reports = await getReports()
|
|
236
236
|
const userData = await reports.getUserData()
|
|
237
237
|
const r = await require('./util/traccar').getAllInOne(reports.traccar,
|
|
238
|
-
new Date(2022, 1, 1),
|
|
239
|
-
new Date(2022, 1, 4),
|
|
238
|
+
new Date(2022, 1, 1, 0, 0, 0, 0),
|
|
239
|
+
new Date(2022, 1, 4, 23, 59, 59, 0),
|
|
240
240
|
userData.devices,
|
|
241
241
|
false,
|
|
242
242
|
true,
|
|
243
243
|
true,
|
|
244
244
|
false)
|
|
245
245
|
|
|
246
|
-
assert.equal(r.trips.filter(t => t.deviceId === 22327).length,
|
|
247
|
-
assert.equal(r.stops.filter(t => t.deviceId === 22327).length,
|
|
246
|
+
assert.equal(r.trips.filter(t => t.deviceId === 22327).length, 20)
|
|
247
|
+
assert.equal(r.stops.filter(t => t.deviceId === 22327).length, 21)
|
|
248
248
|
}, 20000)
|
|
249
249
|
it('Total KMS', async () => {
|
|
250
250
|
const report = await getReports()
|
package/src/trip-report.js
CHANGED
|
@@ -45,16 +45,28 @@ async function createTripReportByDevice(from, to, userData, traccar) {
|
|
|
45
45
|
devices.sort((a, b) => (a.name > b.name) ? 1 : -1)
|
|
46
46
|
|
|
47
47
|
const devicesToSlice = devices.slice()
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
48
|
+
const sliced = automaticReports.sliceArray(devicesToSlice, 5)
|
|
49
|
+
|
|
50
|
+
console.log('LOADING_MESSAGE:' + devices.map(d => d.name).join(', '))
|
|
51
|
+
let deviceCount = 0
|
|
52
|
+
for(const slice of sliced) {
|
|
53
|
+
const allInOne = await traccarHelper.getAllInOne(traccar, from, to, slice, true, true, true, false)
|
|
54
|
+
const tripsData = allInOne.trips
|
|
55
|
+
const stopsData = allInOne.stops
|
|
56
|
+
const routeData = allInOne.route
|
|
57
|
+
|
|
58
|
+
console.log('Trips:' + tripsData.length)
|
|
59
|
+
|
|
60
|
+
if (tripsData.length > 0) {
|
|
61
|
+
trips.checkTripsKms(traccar, from, to, slice, {trips: tripsData, route: routeData})
|
|
62
|
+
allData.devices.push(...processDevices(from, to, slice, {
|
|
63
|
+
trips: tripsData,
|
|
64
|
+
stops: stopsData,
|
|
65
|
+
route: routeData
|
|
66
|
+
}, userData))
|
|
67
|
+
}
|
|
68
|
+
deviceCount = deviceCount + slice.length
|
|
69
|
+
console.log(`PROGRESS_PERC:${deviceCount / devices.length * 100}`)
|
|
58
70
|
}
|
|
59
71
|
|
|
60
72
|
return allData
|
|
@@ -133,8 +145,6 @@ function processDevices(from, to, devices, data, userData) {
|
|
|
133
145
|
const trips = deviceTrips.filter(t => userData.allWeek || !userData.weekDays || isInsideTimetable(t, userData) || isPartialInsideTimetable(t, userData, deviceRoute))
|
|
134
146
|
const stops = data.stops.filter(s => s.deviceId === d.id)
|
|
135
147
|
|
|
136
|
-
console.log('LOADING_MESSAGE:' + d.name)
|
|
137
|
-
|
|
138
148
|
addNearestPOIs(trips, userData)
|
|
139
149
|
|
|
140
150
|
trips.forEach(trip => {
|
package/src/util/traccar.js
CHANGED
|
@@ -71,10 +71,8 @@ async function getAllInOne(traccar, from, to, devices, getRoutes, getTrips, getS
|
|
|
71
71
|
if(getTrips) url += `&type=trips`
|
|
72
72
|
if(getStops) url += `&type=stops`
|
|
73
73
|
if(getSummary) url += `&type=summary`
|
|
74
|
-
console.log('LOADING_MESSAGE:' + devices.map(d => d.name).join(', '))
|
|
75
74
|
|
|
76
75
|
const sliced = automaticReports.sliceArray(devices, 5)
|
|
77
|
-
let deviceCount = 0
|
|
78
76
|
const result = []
|
|
79
77
|
for(const chunk of sliced) {
|
|
80
78
|
const requests = chunk.map(d =>
|
|
@@ -83,7 +81,6 @@ async function getAllInOne(traccar, from, to, devices, getRoutes, getTrips, getS
|
|
|
83
81
|
withCredentials: true
|
|
84
82
|
}).then(r => r.data).then(x => {
|
|
85
83
|
console.log('LOADING_MESSAGE:' + d.name)
|
|
86
|
-
console.log(`PROGRESS_PERC:${++deviceCount / devices.length * 100}`)
|
|
87
84
|
return x
|
|
88
85
|
}))
|
|
89
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
|
|
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
|
|
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))
|