fleetmap-reports 1.0.390 → 1.0.393
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 +2 -1
- package/src/util/utils.js +23 -4
- package/src/zone-report.js +29 -26
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fleetmap-reports",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.393",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
"author": "",
|
|
11
11
|
"license": "ISC",
|
|
12
12
|
"dependencies": {
|
|
13
|
+
"@turf/turf": "^6.5.0",
|
|
13
14
|
"axios": "^0.21.1",
|
|
14
15
|
"axios-cookiejar-support": "^1.0.1",
|
|
15
16
|
"docx": "^7.3.0",
|
package/src/util/utils.js
CHANGED
|
@@ -64,7 +64,7 @@ function convertToFeature(geofence) {
|
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
if(geofence.area.startsWith('CIRCLE')) {
|
|
67
|
-
const str = geofence.area.substring('CIRCLE(
|
|
67
|
+
const str = geofence.area.substring('CIRCLE ('.length, geofence.area.length - 1)
|
|
68
68
|
const coord_list = str.split(',')
|
|
69
69
|
const coord = coord_list[0].trim().split(' ')
|
|
70
70
|
const point = turf.point([parseFloat(coord[1]), parseFloat(coord[0])])
|
|
@@ -73,6 +73,25 @@ function convertToFeature(geofence) {
|
|
|
73
73
|
console.log(point)
|
|
74
74
|
return point
|
|
75
75
|
}
|
|
76
|
+
|
|
77
|
+
if(geofence.area.startsWith('LINESTRING')) {
|
|
78
|
+
const str = geofence.area.substring('LINESTRING ('.length, geofence.area.length - 1)
|
|
79
|
+
const coord_list = str.split(',')
|
|
80
|
+
const coordinates = coord_list.map(c => {
|
|
81
|
+
const coord = c.trim().split(' ')
|
|
82
|
+
return [parseFloat(coord[1]), parseFloat(coord[0])]
|
|
83
|
+
})
|
|
84
|
+
return {
|
|
85
|
+
"type": "Feature",
|
|
86
|
+
"properties": {
|
|
87
|
+
"geofence": geofence
|
|
88
|
+
},
|
|
89
|
+
"geometry": {
|
|
90
|
+
"type": "LineString",
|
|
91
|
+
"coordinates": coordinates
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
76
95
|
}
|
|
77
96
|
|
|
78
97
|
function getDates(startDate, endDate) {
|
|
@@ -130,7 +149,7 @@ function convertToLocaleString(value, lang, timezone){
|
|
|
130
149
|
}
|
|
131
150
|
|
|
132
151
|
function convertToLocaleDateString(value, lang, timezone){
|
|
133
|
-
if(isClientSide){
|
|
152
|
+
if(isClientSide()){
|
|
134
153
|
return new Date(value).toLocaleDateString()
|
|
135
154
|
} else {
|
|
136
155
|
return new Date(value).toLocaleDateString(lang, {
|
|
@@ -141,7 +160,7 @@ function convertToLocaleDateString(value, lang, timezone){
|
|
|
141
160
|
}
|
|
142
161
|
|
|
143
162
|
function convertToLocaleTimeString(value, lang, timezone){
|
|
144
|
-
if(isClientSide){
|
|
163
|
+
if(isClientSide()){
|
|
145
164
|
return new Date(value).toLocaleTimeString()
|
|
146
165
|
} else {
|
|
147
166
|
return new Date(value).toLocaleTimeString(lang, {
|
|
@@ -152,7 +171,7 @@ function convertToLocaleTimeString(value, lang, timezone){
|
|
|
152
171
|
}
|
|
153
172
|
|
|
154
173
|
function getTimezoneOffset(timezone){
|
|
155
|
-
if(isClientSide){
|
|
174
|
+
if(isClientSide()){
|
|
156
175
|
return new Date().getTimezoneOffset()
|
|
157
176
|
} else {
|
|
158
177
|
const utcDate = new Date(new Date().toLocaleString('en-US', { timeZone: 'UTC' }))
|
package/src/zone-report.js
CHANGED
|
@@ -9,6 +9,7 @@ const {getUserPartner} = require("fleetmap-partners")
|
|
|
9
9
|
const {devicesToProcess} = require("./util/device")
|
|
10
10
|
const traccarHelper = require("./util/traccar")
|
|
11
11
|
const turf = require('turf')
|
|
12
|
+
const {pointToLineDistance} = require("@turf/turf");
|
|
12
13
|
|
|
13
14
|
const fileName = 'ZoneReport'
|
|
14
15
|
|
|
@@ -147,14 +148,13 @@ async function processDevices(from, to, devices, drivers, geofences, data, tracc
|
|
|
147
148
|
return devicesResult
|
|
148
149
|
}
|
|
149
150
|
|
|
150
|
-
|
|
151
151
|
function getInAndOutEvents(devices, route, userData) {
|
|
152
152
|
const events = []
|
|
153
153
|
devices.forEach(d => {
|
|
154
154
|
const deviceRoute = route.filter(p => p.deviceId === d.id)
|
|
155
155
|
|
|
156
156
|
const routePoints = deviceRoute.map(p => convertPositionToFeature(p))
|
|
157
|
-
const geofencesFeatures = userData.geofences.
|
|
157
|
+
const geofencesFeatures = userData.geofences.map(g => convertToFeature(g))
|
|
158
158
|
|
|
159
159
|
const entryMap = []
|
|
160
160
|
routePoints.forEach(p => {
|
|
@@ -162,22 +162,12 @@ function getInAndOutEvents(devices, route, userData) {
|
|
|
162
162
|
if(g.geometry.type === 'Polygon') {
|
|
163
163
|
if (turf.inside(p, g)) {
|
|
164
164
|
if (!entryMap.includes(g)) {
|
|
165
|
-
events.push(
|
|
166
|
-
type: "geofenceEnter",
|
|
167
|
-
position: p.properties.position,
|
|
168
|
-
geofenceId: g.properties.geofence.id,
|
|
169
|
-
deviceId: d.id
|
|
170
|
-
})
|
|
165
|
+
events.push(createEvent('geofenceEnter',d.id,p,g))
|
|
171
166
|
entryMap.push(g)
|
|
172
167
|
}
|
|
173
168
|
} else {
|
|
174
169
|
if (entryMap.includes(g)) {
|
|
175
|
-
events.push(
|
|
176
|
-
type: "geofenceExit",
|
|
177
|
-
position: p.properties.position,
|
|
178
|
-
geofenceId: g.properties.geofence.id,
|
|
179
|
-
deviceId: d.id
|
|
180
|
-
})
|
|
170
|
+
events.push(createEvent('geofenceExit',d.id,p,g))
|
|
181
171
|
const index = entryMap.indexOf(g)
|
|
182
172
|
entryMap.splice(index, 1)
|
|
183
173
|
}
|
|
@@ -186,22 +176,26 @@ function getInAndOutEvents(devices, route, userData) {
|
|
|
186
176
|
if(g.geometry.type === 'Point') {
|
|
187
177
|
if (turf.distance(p, g, 'meters') < g.properties.distance) {
|
|
188
178
|
if (!entryMap.includes(g)) {
|
|
189
|
-
events.push(
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
179
|
+
events.push(createEvent('geofenceEnter',d.id,p,g))
|
|
180
|
+
entryMap.push(g)
|
|
181
|
+
}
|
|
182
|
+
} else {
|
|
183
|
+
if (entryMap.includes(g)) {
|
|
184
|
+
events.push(createEvent('geofenceExit',d.id,p,g))
|
|
185
|
+
const index = entryMap.indexOf(g)
|
|
186
|
+
entryMap.splice(index, 1)
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
if(g.geometry.type === 'LineString') {
|
|
191
|
+
if (pointToLineDistance(p, g,{units: 'meters'}) < (g.properties.geofence.attributes.polylineDistance || 25)) {
|
|
192
|
+
if (!entryMap.includes(g)) {
|
|
193
|
+
events.push(createEvent('geofenceEnter',d.id,p,g))
|
|
195
194
|
entryMap.push(g)
|
|
196
195
|
}
|
|
197
196
|
} else {
|
|
198
197
|
if (entryMap.includes(g)) {
|
|
199
|
-
events.push(
|
|
200
|
-
type: "geofenceExit",
|
|
201
|
-
position: p.properties.position,
|
|
202
|
-
geofenceId: g.properties.geofence.id,
|
|
203
|
-
deviceId: d.id
|
|
204
|
-
})
|
|
198
|
+
events.push(createEvent('geofenceExit',d.id,p,g))
|
|
205
199
|
const index = entryMap.indexOf(g)
|
|
206
200
|
entryMap.splice(index, 1)
|
|
207
201
|
}
|
|
@@ -214,6 +208,15 @@ function getInAndOutEvents(devices, route, userData) {
|
|
|
214
208
|
return events
|
|
215
209
|
}
|
|
216
210
|
|
|
211
|
+
function createEvent(type, deviceId, p, g) {
|
|
212
|
+
return {
|
|
213
|
+
type: type,
|
|
214
|
+
position: p.properties.position,
|
|
215
|
+
geofenceId: g.properties.geofence.id,
|
|
216
|
+
deviceId: deviceId
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
217
220
|
async function exportZoneReportToPDF(userData, reportData) {
|
|
218
221
|
console.log('Export to PDF')
|
|
219
222
|
|