fleetmap-reports 1.0.942 → 1.0.943
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 -0
- package/src/util/trips.js +7 -5
package/package.json
CHANGED
package/src/kms-report.js
CHANGED
|
@@ -178,6 +178,7 @@ async function processDevices (from, to, devices, data, userData, traccarInstanc
|
|
|
178
178
|
const dates = getDates(from, to, userData.user.attributes.timezone || getUserPartner(userData.user).timezone)
|
|
179
179
|
const days = await Promise.all(dates.map(async date => {
|
|
180
180
|
const { tripsByDay } = await getDataByDay(d, date, { trips }, userData, traccarInstance)
|
|
181
|
+
console.log(date, trips.length)
|
|
181
182
|
return {
|
|
182
183
|
date,
|
|
183
184
|
kms: getKms(tripsByDay)
|
package/src/util/trips.js
CHANGED
|
@@ -36,11 +36,10 @@ async function calculatePartialTrip (device, startDate, endDate, route, t, tracc
|
|
|
36
36
|
const tripStart = new Date(t.startTime)
|
|
37
37
|
const tripEnd = new Date(t.endTime)
|
|
38
38
|
|
|
39
|
-
console.log('calculatePartialTrip', tripStart, tripEnd, endDate, startDate)
|
|
40
39
|
if (startDate.getTime() > endDate.getTime()) {
|
|
41
40
|
if (tripStart.getTime() < endDate.getTime() &&
|
|
42
41
|
tripEnd.getTime() > endDate.getTime()) {
|
|
43
|
-
|
|
42
|
+
// Trip starts inside time period and ends outside time period
|
|
44
43
|
if (!route && device) {
|
|
45
44
|
const allInOneData = await traccarHelper.getAllInOne(traccarInstance, startDate, endDate, [device], true, false, false, false, undefined, undefined, 5, 1, undefined, true)
|
|
46
45
|
route = allInOneData.route
|
|
@@ -54,7 +53,7 @@ async function calculatePartialTrip (device, startDate, endDate, route, t, tracc
|
|
|
54
53
|
|
|
55
54
|
if (tripStart.getTime() < startDate.getTime() &&
|
|
56
55
|
new Date(t.endTime).getTime() > startDate.getTime()) {
|
|
57
|
-
|
|
56
|
+
// Trip starts outside time period and ends inside time period
|
|
58
57
|
if (!route && device) {
|
|
59
58
|
const allInOneData = await traccarHelper.getAllInOne(traccarInstance, startDate, endDate, [device], true, false, false, false, undefined, undefined, 5, 1, undefined, true)
|
|
60
59
|
route = allInOneData.route
|
|
@@ -68,7 +67,7 @@ async function calculatePartialTrip (device, startDate, endDate, route, t, tracc
|
|
|
68
67
|
} else {
|
|
69
68
|
if (tripStart.getTime() < startDate.getTime() &&
|
|
70
69
|
tripEnd.getTime() > startDate.getTime()) {
|
|
71
|
-
|
|
70
|
+
// Trip starts outside time period and ends inside time period
|
|
72
71
|
if (!route && device) {
|
|
73
72
|
const allInOneData = await traccarHelper.getAllInOne(traccarInstance, startDate, endDate, [device], true, false, false, false, undefined, undefined, 5, 1, undefined, true)
|
|
74
73
|
route = allInOneData.route
|
|
@@ -82,7 +81,7 @@ async function calculatePartialTrip (device, startDate, endDate, route, t, tracc
|
|
|
82
81
|
|
|
83
82
|
if (tripStart.getTime() < endDate.getTime() &&
|
|
84
83
|
tripEnd.getTime() > endDate.getTime()) {
|
|
85
|
-
|
|
84
|
+
// Trip starts inside time period and ends outside time period
|
|
86
85
|
if (!route && device) {
|
|
87
86
|
const allInOneData = await traccarHelper.getAllInOne(traccarInstance, startDate, endDate, [device], true, false, false, false, undefined, undefined, 5, 1, undefined, true)
|
|
88
87
|
route = allInOneData.route
|
|
@@ -132,6 +131,9 @@ async function getDataByDay (device, date, data, userData, traccarInstance) {
|
|
|
132
131
|
|
|
133
132
|
function getKms (trips) {
|
|
134
133
|
const odometerKms = trips.length > 0 ? trips[trips.length - 1].endOdometer - trips[0].startOdometer : 0
|
|
134
|
+
if (trips.length > 0) {
|
|
135
|
+
console.log(trips[trips.length - 1].endOdometer, trips[0].startOdometer, odometerKms)
|
|
136
|
+
}
|
|
135
137
|
return odometerKms > 0 ? odometerKms : trips.filter(t => t.distance > 0).reduce((a, b) => a + b.distance, 0)
|
|
136
138
|
}
|
|
137
139
|
|