fleetmap-reports 2.0.114 → 2.0.116
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/kms-report.js +1 -3
- package/src/trip-report.js +1 -3
- package/src/util/trips.js +18 -32
package/package.json
CHANGED
package/src/kms-report.js
CHANGED
|
@@ -9,7 +9,7 @@ const { getUserPartner } = require('fleetmap-partners')
|
|
|
9
9
|
const traccar = require('./util/traccar')
|
|
10
10
|
const { getDates, getTranslations, isClientSide, executeServerSide } = require('./util/utils')
|
|
11
11
|
const driversUtil = require('./util/driver')
|
|
12
|
-
const { isInsideTimetable, isPartialInsideTimetable, calculateTrip, getDataByDay,
|
|
12
|
+
const { isInsideTimetable, isPartialInsideTimetable, calculateTrip, getDataByDay, getKms } = require('./util/trips')
|
|
13
13
|
const { devicesToProcess } = require('./util/device')
|
|
14
14
|
const { getDriverData, reportByDriver } = require('./util/driver')
|
|
15
15
|
const automaticReports = require('./automaticReports')
|
|
@@ -87,7 +87,6 @@ async function createKmsReportByDevice (from, to, userData, traccarInstance) {
|
|
|
87
87
|
|
|
88
88
|
// Process report data
|
|
89
89
|
if (trips.length) {
|
|
90
|
-
checkTripsKms(traccarInstance, from, to, devices, { trips, route })
|
|
91
90
|
allData.devices = allData.devices.concat(await processDevices(from, to, devices, {
|
|
92
91
|
trips,
|
|
93
92
|
route
|
|
@@ -161,7 +160,6 @@ async function createKmsReportByGroup (from, to, userData, traccarInstance) {
|
|
|
161
160
|
console.log('trips:' + tripsData.length)
|
|
162
161
|
|
|
163
162
|
if (tripsData.length > 0) {
|
|
164
|
-
checkTripsKms(traccarInstance, from, to, devices, { trips: tripsData, route })
|
|
165
163
|
groupData.devices = await processDevices(from, to, devices, { trips: tripsData, route }, userData, traccarInstance)
|
|
166
164
|
}
|
|
167
165
|
|
package/src/trip-report.js
CHANGED
|
@@ -9,7 +9,6 @@ const { getUserPartner } = require('fleetmap-partners')
|
|
|
9
9
|
const { headerFromUser, addTable } = require('./util/pdfDocument')
|
|
10
10
|
const { getStyle } = require('./reportStyle')
|
|
11
11
|
const traccarHelper = require('./util/traccar')
|
|
12
|
-
const trips = require('./util/trips')
|
|
13
12
|
const {
|
|
14
13
|
isInsideTimetable, isPartialInsideTimetable, getTripIdleTime, calculateStopDuration,
|
|
15
14
|
getUncompletedTrip, getTripTotalKms
|
|
@@ -61,7 +60,6 @@ async function createTripReportByDevice (from, to, userData, traccar) {
|
|
|
61
60
|
console.log('Trips:' + tripsData.length)
|
|
62
61
|
|
|
63
62
|
if (tripsData.length > 0) {
|
|
64
|
-
trips.checkTripsKms(traccar, from, to, slice, { trips: tripsData, route: routeData })
|
|
65
63
|
allData.devices.push(...await processDevices(from, to, slice, {
|
|
66
64
|
trips: tripsData,
|
|
67
65
|
stops: stopsData,
|
|
@@ -177,7 +175,7 @@ async function processDevices (from, to, devices, data, userData, traccar) {
|
|
|
177
175
|
trips.forEach(trip => {
|
|
178
176
|
const stop = getStop(new Date(trip.startTime), stops)
|
|
179
177
|
|
|
180
|
-
trip.totalKms = getTripTotalKms(trip, stop)
|
|
178
|
+
trip.totalKms = getTripTotalKms(trip, stop, deviceRoute)
|
|
181
179
|
|
|
182
180
|
const nearestPOIs = getNearestPOIs(trip.endLon, trip.endLat, userData.geofences)
|
|
183
181
|
if (nearestPOIs.length > 0) {
|
package/src/util/trips.js
CHANGED
|
@@ -2,35 +2,6 @@ const { coordsDistance, convertFromUTC, weekDaySelected, convertFromLocal, isCli
|
|
|
2
2
|
const { isInside } = require('./timetable')
|
|
3
3
|
const traccarHelper = require('./traccar')
|
|
4
4
|
|
|
5
|
-
const minDistance = 0
|
|
6
|
-
const minAvgSpeed = 0
|
|
7
|
-
|
|
8
|
-
function checkTripsKms (traccarInstance, from, to, devices, data) {
|
|
9
|
-
const trips = data.trips.filter(t => t.distance === minDistance && t.averageSpeed > minAvgSpeed)
|
|
10
|
-
if (trips.length > 0) {
|
|
11
|
-
// Vehicles with imported positions. calculate trip distance with route positions
|
|
12
|
-
trips.forEach(t => {
|
|
13
|
-
if (t.distance === minDistance && t.averageSpeed > minAvgSpeed && data.route.find(p => p.source === 'import')) {
|
|
14
|
-
const tripRoute = data.route.filter(p => p.deviceId === t.deviceId &&
|
|
15
|
-
new Date(p.fixTime).getTime() >= new Date(t.startTime).getTime() &&
|
|
16
|
-
new Date(p.fixTime).getTime() <= new Date(t.endTime).getTime())
|
|
17
|
-
|
|
18
|
-
let current = null
|
|
19
|
-
const distances = []
|
|
20
|
-
for (const p of tripRoute) {
|
|
21
|
-
if (current) {
|
|
22
|
-
distances.push(coordsDistance(parseFloat(current.longitude), parseFloat(current.latitude),
|
|
23
|
-
parseFloat(p.longitude), parseFloat(p.latitude)))
|
|
24
|
-
}
|
|
25
|
-
current = p
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
t.distance = distances.reduce((a, b) => a + b, 0)
|
|
29
|
-
}
|
|
30
|
-
})
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
5
|
async function calculatePartialTrip (device, startDate, endDate, route, t, traccarInstance) {
|
|
35
6
|
let isPartialInside = false
|
|
36
7
|
const tripStart = new Date(t.startTime)
|
|
@@ -217,12 +188,27 @@ function calculateStopDuration (stop) {
|
|
|
217
188
|
return totalStopTime - (stop.engineHours > 0 ? stop.engineHours : 0)
|
|
218
189
|
}
|
|
219
190
|
|
|
220
|
-
function getTripTotalKms (trip, stop) {
|
|
191
|
+
function getTripTotalKms (trip, stop, route) {
|
|
221
192
|
// we need to add stop kms to ensure that the total kms for the day, calculated with the odometer difference, will be equal to the sum of kms of all trips
|
|
222
|
-
|
|
193
|
+
let distance = trip.distance + (stop ? (stop.endOdometer - stop.startOdometer) : 0)
|
|
194
|
+
if (!trip.distance && route && route.length) {
|
|
195
|
+
distance = 0
|
|
196
|
+
const positions = route.filter(p => p.deviceId === trip.deviceId &&
|
|
197
|
+
new Date(p.fixTime).getTime() >= new Date(trip.startTime).getTime() &&
|
|
198
|
+
new Date(p.fixTime).getTime() <= new Date(trip.endTime).getTime())
|
|
199
|
+
|
|
200
|
+
let current = null
|
|
201
|
+
for (const p of positions) {
|
|
202
|
+
if (current) {
|
|
203
|
+
distance += coordsDistance(parseFloat(current.longitude), parseFloat(current.latitude),
|
|
204
|
+
parseFloat(p.longitude), parseFloat(p.latitude))
|
|
205
|
+
}
|
|
206
|
+
current = p
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
return distance / 1000
|
|
223
210
|
}
|
|
224
211
|
|
|
225
|
-
exports.checkTripsKms = checkTripsKms
|
|
226
212
|
exports.isInsideTimetable = isInsideTimetable
|
|
227
213
|
exports.isPartialInsideTimetable = isPartialInsideTimetable
|
|
228
214
|
exports.getDataByDay = getDataByDay
|