Esempio n. 1
0
        public void GetPointsForIndexing_ShouldGetAllPointsFromGateway()
        {
            _wikipediaGateway.GetByLocation(Arg.Any <Coordinate>(), Arg.Any <string>()).Returns(new List <Feature> {
                GetValidFeature("1", Sources.WIKIPEDIA)
            });
            var points = _adapter.GetPointsForIndexing().Result;

            _wikipediaGateway.Received(1092).GetByLocation(Arg.Any <Coordinate>(), Arg.Any <string>());
            Assert.AreEqual(1, points.Count); // only 1 distinct
        }
        /// <inheritdoc />
        public override async Task <List <Feature> > GetPointsForIndexing()
        {
            _logger.LogInformation("Start getting wikipedia pages for indexing");
            var startCoordinate = new Coordinate(34, 29);
            var endCoordinate   = new Coordinate(36, 34);

            var    itmToWgs84 = _itmWgs84MathTransfromFactory.Create();
            var    wgs84ToItm = _itmWgs84MathTransfromFactory.CreateInverse();
            double step       = 10000 * 2 / Math.Sqrt(2);
            var    tasksList  = new List <Task <List <Feature> > >();

            foreach (var language in Languages.Array)
            {
                var currentCoordinate = new Coordinate(startCoordinate);
                while (currentCoordinate.X < endCoordinate.X && currentCoordinate.Y < endCoordinate.Y)
                {
                    var itm = wgs84ToItm.Transform(currentCoordinate);
                    itm.X            += step;
                    currentCoordinate = itmToWgs84.Transform(itm);
                    if (currentCoordinate.X > endCoordinate.X)
                    {
                        currentCoordinate.X = startCoordinate.X;
                        itm               = wgs84ToItm.Transform(currentCoordinate);
                        itm.Y            += step;
                        currentCoordinate = itmToWgs84.Transform(itm);
                    }
                    tasksList.Add(_wikipediaGateway.GetByLocation(currentCoordinate, language));
                }
            }

            _logger.LogInformation($"Created {tasksList.Count} tasks to fetch wikipedia data.");
            var lists = await Task.WhenAll(tasksList);

            var wikiFeatures = lists.SelectMany(l => l)
                               .GroupBy(f => f.Attributes[FeatureAttributes.ID])
                               .Select(g => g.First())
                               .ToList();

            _logger.LogInformation($"Finished getting Wikipedia pages for indexing, got {wikiFeatures.Count} pages.");
            return(wikiFeatures);
        }