-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #168 from AirQualityControl/feature/implement-get-…
…airpollution-by-geolocation implement feature
- Loading branch information
Showing
6 changed files
with
102 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/AirSnitch.Infrastructure/Persistence/Repositories/NearestStationsAggregationPipeline.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System.Collections.Generic; | ||
using AirSnitch.Domain.Models; | ||
using MongoDB.Bson; | ||
|
||
namespace AirSnitch.Infrastructure.Persistence.Repositories; | ||
|
||
internal static class NearestStationsAggregationPipeline | ||
{ | ||
public static List<BsonDocument> Create(GeoCoordinates geoLocation, int numberOfNearestStation) | ||
{ | ||
int numOfPipelineStages = 2; | ||
|
||
var geoNearOptions = new BsonDocument | ||
{ | ||
{ | ||
"near", new BsonDocument | ||
{ | ||
{"type", "Point"}, | ||
{"coordinates", new BsonArray {geoLocation.Longitude, geoLocation.Latitude}}, | ||
} | ||
}, | ||
{"key", "geoLocation"}, | ||
{"distanceField", "dist.calculated"}, | ||
}; | ||
|
||
var limitOptions = new BsonDocument() | ||
{ | ||
{"$limit", numberOfNearestStation} | ||
}; | ||
|
||
var pipeline = new List<BsonDocument>(numOfPipelineStages) | ||
{ | ||
new BsonDocument {{"$geoNear", geoNearOptions}}, | ||
limitOptions | ||
}; | ||
|
||
return pipeline; | ||
} | ||
} |