private List <AreaMaster> filterRegionList(List <AreaMaster> areas, decimal lat, decimal lng) { List <AreaMaster> filteredAreas = new List <AreaMaster>(); Parallel.ForEach(areas, area => { if (isPointInPolygon(GooglePoints.DecodeBase64(area.EncodedPolygon).Select(x => new LocationPoint(x.Latitude, x.Longitude)).ToList(), lat, lng)) { area.EncodedPolygon = ASCIIEncoding.ASCII.GetString(Convert.FromBase64String(area.EncodedPolygon)); filteredAreas.Add(area); } }); return(filteredAreas); }
public async Task <GetAreaListingWrapper> GetArea(string id, string north = null, string east = null, string south = null, string west = null, string beds = null, string bathsFull = null, string bathsHalf = null, string propertyAddressId = null, string averageValue = null, string averageRent = null) { DateTime startQueryTime = DateTime.Now; List <AreaMaster> listingArea = new List <AreaMaster>(); List <List <Property> > areaProperties = new List <List <Property> >(); Dictionary <string, Condition> areaKeyConditions = new Dictionary <string, Condition>(); Dictionary <string, Condition> areaQueryFilter = new Dictionary <string, Condition>(); areaKeyConditions.Add("AreaID", new Condition() { ComparisonOperator = "EQ", AttributeValueList = new List <AttributeValue>() { new AttributeValue(id) } }); areaQueryFilter.Add("IsPredefine", new Condition() { ComparisonOperator = "EQ", AttributeValueList = new List <AttributeValue>() { new AttributeValue() { N = "1" } } }); QueryRequest queryRequest = new QueryRequest() { TableName = areaMasterTableName, ReturnConsumedCapacity = "TOTAL", KeyConditions = areaKeyConditions, QueryFilter = areaQueryFilter }; var result = dynamoDBClient.QueryAsync(queryRequest).Result; listingArea = AreaMaster.ConvertToEntity(result.Items); DateTime endQueryTime = DateTime.Now; if (listingArea.Count() > 0) { var tempArea = new Area() { EncodedPolygon = listingArea.First().EncodedPolygon, Points = GooglePoints.DecodeBase64(listingArea.First().EncodedPolygon).Select(x => new LocationPoint(x.Latitude, x.Longitude)).ToList() }; GetListingWrapper output = await GetListing(tempArea, north, east, south, west, beds, bathsFull, bathsHalf, propertyAddressId, averageValue, averageRent, listingArea.First().EncodedCompletedTiles, listingArea.First().EncodedPartialTiles); foreach (var area in listingArea) { area.EncodedPolygon = ASCIIEncoding.ASCII.GetString(Convert.FromBase64String(area.EncodedPolygon)); area.EncodedCompletedTiles = null; area.EncodedPartialTiles = null; } return(new GetAreaListingWrapper { PropertyCount = output.PropertyCount, ScanCount = output.ScanCount, ConsumedCapacityCount = output.ConsumedCapacityCount, TotalQueryExecutionTime = output.TotalQueryExecutionTime, TotalLambdaExecutionTime = output.TotalLambdaExecutionTime, TotalContainsExecutionTime = output.TotalContainsExecutionTime, TotalAreaQueryTime = (endQueryTime - startQueryTime).TotalMilliseconds, Properties = output.Properties, Area = listingArea, }); } else { return(null); } }
public async Task <GetListingWrapper> GetListing(Area area, string north = null, string east = null, string south = null, string west = null, string beds = null, string bathsFull = null, string bathsHalf = null, string propertyAddressId = null, string averageValue = null, string averageRent = null, string encodedCompletedTiles = null, string encodedPartialTiles = null) { List <Listing> listings = new List <Listing>(); List <PointF> boundingBox = null; if (!string.IsNullOrEmpty(north) && !string.IsNullOrEmpty(east) && !string.IsNullOrEmpty(south) && !string.IsNullOrEmpty(west)) { boundingBox = new List <PointF>(); boundingBox.Add(new PointF((float)Convert.ToDouble(north), (float)Convert.ToDouble(east))); boundingBox.Add(new PointF((float)Convert.ToDouble(north), (float)Convert.ToDouble(west))); boundingBox.Add(new PointF((float)Convert.ToDouble(south), (float)Convert.ToDouble(west))); boundingBox.Add(new PointF((float)Convert.ToDouble(south), (float)Convert.ToDouble(east))); } DateTime startLambdaTime = DateTime.Now; List <Tile> tiles = new List <Tile>(); if (!string.IsNullOrEmpty(encodedCompletedTiles) || !string.IsNullOrEmpty(encodedPartialTiles)) { if (!string.IsNullOrEmpty(area.EncodedPolygon)) { area.Points = GooglePoints.DecodeBase64(area.EncodedPolygon).Select(x => new LocationPoint(x.Latitude, x.Longitude)).ToList(); } if (boundingBox == null || boundingBox.Count() == 0) { tiles.AddRange(GooglePoints.DecodeBase64(encodedCompletedTiles).Select(x => new Tile() { Row = (int)x.Latitude, Column = (int)x.Longitude, IsPartialTile = false }).ToList()); tiles.AddRange(GooglePoints.DecodeBase64(encodedPartialTiles).Select(x => new Tile() { Row = (int)x.Latitude, Column = (int)x.Longitude, IsPartialTile = true }).ToList()); } else { RasterizeObject rasterizeObject = this.GetCoordinateTile(area.Points.Select(x => new PointF((float)x.Lat, (float)x.Lng)).ToList(), true, boundingBox); tiles = rasterizeObject.tiles; area.Points = new WKTReader().Read(rasterizeObject.intersectionPolygon).Coordinates.Select(x => new LocationPoint(x.X, x.Y)).ToList(); } } else { if (!string.IsNullOrEmpty(area.EncodedPolygon)) { area.Points = GooglePoints.Decode(area.EncodedPolygon).Select(x => new LocationPoint(x.Latitude, x.Longitude)).ToList(); } RasterizeObject rasterizeObject = this.GetCoordinateTile(area.Points.Select(x => new PointF((float)x.Lat, (float)x.Lng)).ToList(), true, boundingBox); tiles = rasterizeObject.tiles; if (boundingBox != null && boundingBox.Count() > 0) { area.Points = new WKTReader().Read(rasterizeObject.intersectionPolygon).Coordinates.Select(x => new LocationPoint(x.X, x.Y)).ToList(); } } DateTime endLambdaTime = DateTime.Now; //if (tiles == null || tiles.Count() == 0) //{ // throw new Exception("Unable To Calculate Tiles"); //} DateTime startQueryTime = DateTime.Now; GetRegionByPropertyWrapper listing = getRegionByProperty(tiles, beds, bathsFull, bathsHalf, propertyAddressId, averageValue, averageRent).Result; DateTime endQueryTime = DateTime.Now; foreach (var item in listing.CompleteProperties) { if (item != null) { listings.Add(new Listing { Name = item.PropertyAddressName, Lat = item.Latitude, Lng = item.Longitude }); } } Stopwatch containsStopwatch = Stopwatch.StartNew(); Parallel.ForEach(listing.PartialProperties, item => { if (item != null && this.polyCheck(new Vector2((float)item.Latitude, (float)item.Longitude), area.Points.Select(x => new Vector2((float)x.Lat, (float)x.Lng)).ToArray())) { listings.Add(new Listing { Name = item.PropertyAddressName, Lat = item.Latitude, Lng = item.Longitude }); } }); containsStopwatch.Stop(); List <ListingMaster> customProperties = listings.Select(x => new ListingMaster() { Lat = x.Lat, Lng = x.Lng, Name = x.Name }).ToList(); return(new GetListingWrapper { PropertyCount = listing.TotalRecordCount, ScanCount = listing.ScanCount, ConsumedCapacityCount = listing.ConsumedCapacityCount, TotalQueryExecutionTime = (endQueryTime - startQueryTime).TotalMilliseconds, TotalLambdaExecutionTime = (endLambdaTime - startLambdaTime).TotalMilliseconds, TotalContainsExecutionTime = containsStopwatch.ElapsedMilliseconds, Properties = customProperties, }); }