fleetmap-reports 1.0.284 → 1.0.288

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.
@@ -1,72 +0,0 @@
1
- const automaticReports = require("../automaticReports");
2
-
3
- async function getRoute(traccar, from, to, devices){
4
- const devicesToSlice = devices.slice()
5
-
6
- const arrayOfArrays = automaticReports.sliceArray(devicesToSlice)
7
- let requests = []
8
- for (const a of arrayOfArrays) {
9
- const promise = traccar.reports.reportsRouteGet(from, to, a.map(d => d.id))
10
- requests = requests.concat(promise)
11
- }
12
-
13
- const result = await Promise.all(requests)
14
- return result.map(r => r.data).flat()
15
- }
16
-
17
- async function getTrips(traccar, from, to, devices){
18
- const devicesToSlice = devices.slice()
19
- const arrayOfArrays = automaticReports.sliceArray(devicesToSlice)
20
- let requests = []
21
- for (const a of arrayOfArrays) {
22
- const promise = traccar.reports.reportsTripsGet(from, to, a.map(d => d.id))
23
- requests = requests.concat(promise)
24
- }
25
-
26
- const result = await Promise.all(requests)
27
- return result.map(r => r.data).flat()
28
- }
29
-
30
- async function getStops(traccar, from, to, devices){
31
- const devicesToSlice = devices.slice()
32
- const arrayOfArrays = automaticReports.sliceArray(devicesToSlice)
33
- let requests = []
34
- for (const a of arrayOfArrays) {
35
- const promise = traccar.reports.reportsStopsGet(from, to, a.map(d => d.id))
36
- requests = requests.concat(promise)
37
- }
38
-
39
- const result = await Promise.all(requests)
40
- return result.map(r => r.data).flat()
41
- }
42
-
43
- async function getEvents(traccar, from, to, devices, events){
44
- const devicesToSlice = devices.slice()
45
- const arrayOfArrays = automaticReports.sliceArray(devicesToSlice)
46
- let requests = []
47
- for (const a of arrayOfArrays) {
48
- const promise = traccar.reports.reportsEventsGet(from, to, a.map(d => d.id), null, events)
49
- requests = requests.concat(promise)
50
- }
51
- const result = await Promise.all(requests)
52
- return result.map(r => r.data).flat()
53
- }
54
-
55
- async function getSummary(traccar, from, to, devices){
56
- const devicesToSlice = devices.slice()
57
- const arrayOfArrays = automaticReports.sliceArray(devicesToSlice)
58
- let requests = []
59
- for (const a of arrayOfArrays) {
60
- const promise = traccar.reports.reportsSummaryGet(from, to, a.map(d => d.id))
61
- requests = requests.concat(promise)
62
- }
63
-
64
- const result = await Promise.all(requests)
65
- return result.map(r => r.data).flat()
66
- }
67
-
68
- exports.getRoute = getRoute
69
- exports.getTrips = getTrips
70
- exports.getStops = getStops
71
- exports.getEvents = getEvents
72
- exports.getSummary = getSummary
package/src/util/trips.js DELETED
@@ -1,76 +0,0 @@
1
- const traccar = require("./traccar");
2
- const {coordsDistance} = require("./utils");
3
-
4
- const minDistance = 0
5
- const minAvgSpeed = 0
6
-
7
- function addNearestPOIs(trips, userData){
8
- trips.forEach(t => {
9
- t.totalKms = t.distance / 1000
10
-
11
- const distance = userData.geofences
12
- .filter(g => g && g.area.startsWith('CIRCLE'))
13
- .map(g => {
14
- const str = g.area.substring('CIRCLE ('.length, g.area.indexOf(','))
15
- const coord = str.trim().split(' ')
16
- return {
17
- p: g,
18
- distance: Math.round(coordsDistance(parseFloat(coord[1]), parseFloat(coord[0]), t.endLon, t.endLat))
19
- }
20
- })
21
- const nearestPOIs = distance.filter(a => a.distance < 100).sort((a, b) => (a.distance > b.distance) ? 1 : -1)
22
- if (nearestPOIs.length > 0) {
23
- t.endPOIName = nearestPOIs[0].p.name
24
- }
25
- })
26
- }
27
-
28
- async function checkTripsKms(traccarInstance, from, to, routeData, tripsData, devices) {
29
- console.log('checkTripsKms')
30
- const trips = tripsData.filter(t => t.distance === minDistance && t.averageSpeed > minAvgSpeed)
31
- if(trips.length > 0) {
32
- //Vehicles with imported positions. calculate trip distance with route positions
33
- const route = routeData.length === 0 ? await traccar.getRoute(traccarInstance, from, to, devices) : routeData
34
- trips.forEach(t => {
35
- if(t.distance === minDistance && t.averageSpeed > minAvgSpeed) {
36
- const tripRoute = route.filter(p => p.deviceId === t.deviceId
37
- && new Date(p.fixTime).getTime() >= new Date(t.startTime).getTime()
38
- && new Date(p.fixTime).getTime() <= new Date(t.endTime).getTime())
39
- t.distance = tripRoute.reduce((a, b) => a + b.attributes.distance, 0)
40
- }
41
- })
42
- }
43
- }
44
-
45
- function isInsideTimetable(t, userData){
46
- const tripStart = new Date(t.startTime)
47
- const tripEnd = new Date(t.endTime)
48
-
49
- if((tripStart.getDay() === 0 && userData.weekDays.sunday) ||
50
- (tripStart.getDay() === 1 && userData.weekDays.monday) ||
51
- (tripStart.getDay() === 2 && userData.weekDays.tuesday) ||
52
- (tripStart.getDay() === 3 && userData.weekDays.wednesday) ||
53
- (tripStart.getDay() === 4 && userData.weekDays.thursday) ||
54
- (tripStart.getDay() === 5 && userData.weekDays.friday) ||
55
- (tripStart.getDay() === 6 && userData.weekDays.saturday)) {
56
-
57
- const startDate = new Date(new Date(tripStart).toISOString().split('T')[0] + ' '+userData.dayHours.startTime)
58
- const endDate = new Date(new Date(tripStart).toISOString().split('T')[0] + ' '+userData.dayHours.endTime)
59
-
60
- console.log(tripStart, startDate, endDate)
61
-
62
- //Trips inside time period
63
- if(startDate.getTime() < endDate.getTime()) {
64
- return tripStart.getTime() > startDate.getTime() && tripEnd.getTime() < endDate.getTime()
65
- } else {
66
- return (tripStart.getTime() < endDate.getTime() && tripEnd.getTime() < endDate.getTime()) ||
67
- (tripStart.getTime() > startDate.getTime())
68
- }
69
- }
70
-
71
- return false
72
- }
73
-
74
- exports.checkTripsKms = checkTripsKms
75
- exports.isInsideTimetable = isInsideTimetable
76
- exports.addNearestPOIs = addNearestPOIs