You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+69
Original file line number
Diff line number
Diff line change
@@ -56,6 +56,75 @@ To successfully send email from this sandbox domain you have to add the user to
56
56
import `test/NFZ.postman_collection.json`
57
57
it contains only endpoints for No Fly Zone endpoints
58
58
59
+
# Smart Location Updates
60
+
I added three query parameters `returnNFZ`, `nfzFields` and `nfzLimit` to API *PUT `/drones/{id}`* for getting the array of violated No fly zones in the response data.
61
+
A Sample usage to get the violated no fly zones with fields `description`, `isActive`, `isPermanent`:
62
+
```
63
+
curl -X PUT -H "Content-Type: application/json" -d '{
The response data will contain an extra field `noFlyZones`, which contains an array of `NoFlyZone` that the drone has violated.
69
+
You could specified the returned fields of `noFlyZones` by `nfzFields` parameter. If you omit the `nfzFields`, all fields except the `location` will be returned.
70
+
The parameter `nfzLimit` is for limit the number of returned `NoFlyZone`s, if it is omitted, then all the `NoFlyZone`s are returned.
71
+
Note: the `_id` of the `NoFlyZone` is always returned.
72
+
The approach to get the array of violated no fly zones is based on the `NoFlyZoneService.search`, the steps are:
73
+
1. Define the search criteria: be active, matched time, geometry is "Point" type, the point coordinate is the drone's location.
2. Call `NoFlyZoneService.search` to search no fly zones. Since we only needs to get part of the fields of `NoFlyZone`, I added a field `projFields` to the search criteria.
86
+
The field `projFields` could search in MongoDB with projection, which helps to improve the performance.
87
+
Additionally, the `projFields` could be overrided by `nfzFields` if it is provided.
88
+
`nfzFields=description,isActive,isPermanent` will be converted to `['description', 'isActive', 'isPermanent']`.
89
+
3. Retrieve the array of no fly zones from the returned object, and add the `items` field to the response of this API. It is added to the field `noFlyZones`.
90
+
# Nearest Drone Updates
91
+
I added another three query parameters `nearDronesMaxDist`, `nearDroneFields` and `nearDronesLimit` to API *PUT `/drones/{id}`* for getting the nearest drones.
92
+
A Sample usage to get 100 nearest drones within 1000 meters:
93
+
```
94
+
curl -X PUT -H "Content-Type: application/json" -d '{
The response data will contain an extra field `nearestDrones`. This field contains an array of `Drones` (100 at most) that are ordered by distance.
100
+
To avoid return all fields of drones in the response data, you could specify the fields to be returned by `nearDroneFields`. The example above returns the fields `currentLocation`, `status`, `name`, `description`, `_id`.
101
+
If the `nearDronesMaxDist` is omitted or 0, no nearest drones will be contained in the response data.
102
+
If the `nearDronesLimit` is omitted or 0, only 1 nearest drone will be returned.
103
+
If the `nearDroneFields` is omitted, all the fields of drones will be returned, which is not necessary. So this field is suggested to be provided.
104
+
A new field `dist` is contained in the response data for indicating the distance (in meter) between the drone and the current drone.
105
+
Note: the `_id` of `Drone` is always returned.
106
+
The approach to get the array of nearest drones is based on the geospatial of MongoDB. The steps are:
107
+
1. Add the `2dsphere` index to `Drone.currentLocation`, since it is not a required field, we need to specify `sparse: true`.
108
+
2. Rebuild the index. Since the data are for test, we could regenerate test data for rebuilding the index for simplicity.
109
+
3. As we need to add `dist` field to the response data, we use `$geoNear` instead of `$nearSphere`.
110
+
Set the `$geoNear` option as
111
+
```
112
+
{
113
+
near: {
114
+
type: 'Point',
115
+
coordinates: drone.currentLocation,
116
+
},
117
+
distanceField: 'dist',
118
+
maxDistance: nearDronesMaxDist,
119
+
spherical: true,
120
+
query: {
121
+
_id: { $ne: ObjectId(id) },
122
+
},
123
+
}
124
+
```
125
+
which means to search by `Point` and filter the current drone itself.
126
+
4. Add `limit` and `$project` according to the query parameter `nearDronesLimit`, `nearDroneFields`.
127
+
5. Aggregate `Drone` and add returned array to the response of this API. The array is added to the field `nearestDrones`.
59
128
# env
60
129
61
130
you also can export those values before run(data from forum).
0 commit comments