示例#1
0
        IEnumerable <PointsRegionsLevel> generateRegions(IEnumerable <PointBase> dataPoints, int sectionIndex)
        {
            List <PointsRegionsLevel> result = new List <PointsRegionsLevel>();


            bottomLeftCorner = new Coordinate(
                latitude: (dataPoints.Min(point => point.Latitude) - 0.00001m),
                longitude: (dataPoints.Min(point => point.Longitude) - 0.00001m));

            topRightCorner = new Coordinate(
                latitude: (dataPoints.Max(point => point.Latitude) - 0.00001m),
                longitude: (dataPoints.Max(point => point.Longitude) - 0.00001m));

            dataPoints = dataPoints.OrderBy(item => item.Latitude).ThenBy(item => item.Longitude);

            //get the base regions (zoom level 20)
            PointsRegionsLevel baseRegion = generateBaseRegions(dataPoints, sectionIndex);

            result.Add(baseRegion);

            for (int i = 19; i >= 3; i--)
            {
                result.Add(generateIntermediateRegions(baseRegion, i, sectionIndex));
            }

            return(result);
        }
示例#2
0
        public static IEnumerable <SectionedPointsRegionType> GetRegions(PointsRegionsLevel pointsRegionsModel, int datasetId)
        {
            ConcurrentBag <SectionedPointsRegionType> result = new ConcurrentBag <SectionedPointsRegionType>();

            Parallel.ForEach(pointsRegionsModel.Regions, regionModel =>
            {
                var region =
                    new SectionedPointsRegionType()
                {
                    section    = pointsRegionsModel.Section,
                    row        = regionModel.Row,
                    column     = regionModel.Column,
                    dataset_id = datasetId,
                    points     = new ConcurrentBag <BasePointType>()
                };

                var pointsBag = region.points as ConcurrentBag <BasePointType>;

                Parallel.ForEach(regionModel.Points, pointModel =>
                {
                    pointsBag.Add((BasePointType)pointModel);
                });

                result.Add(region);
            });

            return(result);
        }
示例#3
0
        private async Task <bool> insertRegion(PointsRegionsLevel regionLevel, int datasetId)
        {
            IEnumerable <SectionedPointsRegionType> regionTypes = PointsRegionType.GetRegions(regionLevel, datasetId);

            CassandraQueryBuilder queryBuilder = new CassandraQueryBuilder();

            queryBuilder.TableName = "points_region_zoom_" + regionLevel.ZoomLevel;
            queryBuilder.Type      = typeof(SectionedPointsRegionType);
            queryBuilder.QueryType = CassandraQueryBuilder.QueryTypes.InsertFromType;

            this.executionInstance.PrepareQuery(queryBuilder);

            try
            {
                ConcurrentQueue <Exception> exceptions = new ConcurrentQueue <Exception>();

                await regionTypes.ParallelForEachAsync(async regionType =>
                {
                    try
                    {
                        await executionInstance.ExecuteNonQuery(new
                        {
                            regionType.dataset_id,
                            regionType.column,
                            regionType.row,
                            regionType.points,
                            regionType.section
                        });
                    }
                    catch (Exception exception)
                    {
                        exceptions.Enqueue(exception);
                    }
                });

                if (exceptions.Count > 0)
                {
                    throw new Exception("Exceptions catched in tasks", exceptions.First());
                }
            }
            catch (Exception exception)
            {
                CoreContainers.LogsRepository.LogError(exception, Core.Database.Logs.LogTrigger.DataAccess);

                return(false);
            }

            return(true);
        }
示例#4
0
        private PointsRegionsLevel generateIntermediateRegions(PointsRegionsLevel baseRegions, int zoomLevel, int sectionIndex)
        {
            Dictionary <Tuple <int, int>, PointsRegion> pointsRegions = new Dictionary <Tuple <int, int>, PointsRegion>();

            int maxRegionPointsCount = this.getRegionPointsMaxCount(zoomLevel);

            foreach (var baseRegion in baseRegions.Regions)
            {
                var baseListPoints = baseRegion.Points as List <PointBase>;

                var key = new Tuple <int, int>(baseRegion.Row / (1 << (20 - zoomLevel)),
                                               baseRegion.Column / (1 << (20 - zoomLevel)));

                if (!pointsRegions.ContainsKey(key))
                {
                    pointsRegions.Add(key,
                                      new PointsRegion()
                    {
                        Points = new List <PointBase>(),
                        Row    = key.Item1,
                        Column = key.Item2,
                    });
                }

                (pointsRegions[key].Points as List <PointBase>).AddRange(baseListPoints);
            }



            Parallel.ForEach(pointsRegions.Values, pointsRegion => {
                int count = pointsRegion.Points.Count();

                if (count <= maxRegionPointsCount)
                {
                    return;
                }

                // exceed = (count - this.maxRegionPointsCount);
                //Random random = new Random();

                pointsRegion.Points = pointsRegion.Points.OrderByDescending(point => point.DeformationRate).Take(maxRegionPointsCount);

                /*Deprecated after using another criteria for selection. Delete the code bellow in future commits*/

                /*
                 * var points = pointsRegion.Points as List<PointBase>;
                 * int index = 0;
                 *
                 * while (pointsRegion.Points.Count() > maxRegionPointsCount)
                 * {
                 *  count = pointsRegion.Points.Count();
                 *
                 *  index += count / 4; //random.Next(0, pointsRegion.Points.Count() - 1);
                 *  index %= count;
                 *
                 *  points.RemoveAt(index);
                 * }
                 */
            });

            return(new PointsRegionsLevel()
            {
                ZoomLevel = zoomLevel,
                Section = sectionIndex,
                Regions = pointsRegions.Values
            });
        }