示例#1
0
        public void Resolve()
        {
            LocationHierarchyAnalysis previousProcessedLocation = null;
            LocationHierarchyAnalysis indexedLocation           = null;

            var pName = string.Empty;
            var cnt   = 0;
            var uCnt  = 0;

            Console.WriteLine("STARTING...");

            var countries = _adoClientService.GetCountryCodes();

            foreach (var country in countries)
            {
                Console.WriteLine(string.Format("Country being processed: {0}.", country));

                var notMappedDuplicateLocations = _adoClientService.GetDuplicatesWithoutMappedToId(country);
                Console.WriteLine(string.Format("Unmapped locations: {0}.", notMappedDuplicateLocations.Count));

                foreach (var location in notMappedDuplicateLocations)
                {
                    cnt++;

                    if (previousProcessedLocation == null || !previousProcessedLocation.PName.Equals(location.PName))
                    {
                        if (location.PName.Contains("'"))
                        {
                            pName = location.PName.Replace("'", "''");
                        }
                        else
                        {
                            pName = location.PName;
                        }

                        indexedLocation = _adoClientService.GetIndexedHierarchyAnalysis(location.CountryCode, pName);
                        if (indexedLocation != null)
                        {
                            uCnt++;
                            _adoClientService.UpdateHierarchyAnalysis(location.Id, indexedLocation.Id);
                            previousProcessedLocation = indexedLocation;
                        }
                        else
                        {
                            Console.WriteLine("-------------- > NOT INDEXED: {0}, {1}", location.Id, location.PName);
                        }
                    }
                    else
                    {
                        uCnt++;
                        _adoClientService.UpdateHierarchyAnalysis(location.Id, previousProcessedLocation.Id);
                    }
                }
            }
            Console.WriteLine("{0} locations processed. {1} updated.", cnt, uCnt);
            Console.WriteLine("FINISHED...");
        }
示例#2
0
        public void Analyze()
        {
            var processSelectedCountries = ConfigurationManager.AppSettings["ProcessSelectedCountries"];
            var countryCodes             = (processSelectedCountries.ToLower().Equals("true"))
                ? ConfigurationManager.AppSettings["Countries"].Split(',').ToList()
                : _adoClientService.GetCountryCodes();

            if (countryCodes.Any())
            {
                var service = new ElasticClientService();
                var client  = service.GetClient();

                foreach (var countryCode in countryCodes)
                {
                    Console.WriteLine(String.Format("--> Country being processed: {0}", countryCode));

                    var locationIds    = _adoClientService.GetLocationIds(countryCode);
                    var formattedNames = new List <LocationFormattedNamesAnalysis>();
                    if (locationIds.Any())
                    {
                        foreach (var id in locationIds)
                        {
                            var result = client.Get <ElasticsearchLocation>(g => g.Index("locations-07.20.16.15.44.58").Type("location").Id(id));

                            if (result.Found && result.Source != null && result.Source.Suggest != null && result.Source.Suggest.Output != null)
                            {
                                formattedNames.Add(new LocationFormattedNamesAnalysis
                                {
                                    ID               = result.Source.Suggest.Payload.ID,
                                    CountryCode      = result.Source.Suggest.Payload.CountryCode,
                                    LanguageCode     = "en",
                                    FormattedName    = result.Source.Suggest.Output,
                                    FormattedNameNon = result.Source.Suggest.Output,
                                    TypeId           = result.Source.Suggest.Payload.TypeID,
                                    Formatting       = 0
                                });
                            }
                        }
                    }
                    try
                    {
                        _adoClientService.FormattedNameForAnalysis(formattedNames, DataTableBuilder.GetFormattedNamesAnalysisTable());
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                        Console.ReadLine();
                    }
                }
            }
        }
        public void Process()
        {
            List <Tuple <long, string, string> > missingLocations = new List <Tuple <long, string, string> >();
            var cnt          = 0;
            var countryCodes = _adoClientService.GetCountryCodes();

            var client = _esClient.GetClient();

            foreach (var countryCode in countryCodes)
            {
                Console.WriteLine("Processing: {0}", countryCode);

                var ids = _adoClientService.GetLocationIds(countryCode);
                Console.WriteLine("---> {0} locations to process.", ids.Count());
                Console.WriteLine(" ");

                foreach (var id in ids)
                {
                    var locationForLargerIndex = client.Get <ElasticsearchLocation>(g => g.Index("locations-en-08.29.16.13.25.30").Type("location").Id(id));
                    if (locationForLargerIndex != null && locationForLargerIndex.Source != null)
                    {
                        var locationForSmallerIndex = client.Get <ElasticsearchLocation>(g => g.Index("locations-en-08.29.16.11.52.46").Type("location").Id(id));
                        if (locationForSmallerIndex == null || locationForSmallerIndex.Source == null || locationForSmallerIndex.Source.ID != locationForLargerIndex.Source.ID)
                        {
                            cnt++;
                            Console.WriteLine(string.Format("{0} : {1}, {2} -- {3}", cnt, locationForLargerIndex.Source.ID, locationForLargerIndex.Source.FormattedName, locationForLargerIndex.Source.CountryCode));
                            missingLocations.Add(new Tuple <long, string, string>(locationForLargerIndex.Source.ID, locationForLargerIndex.Source.FormattedName, locationForLargerIndex.Source.CountryCode));
                        }
                    }
                }
            }
            Console.WriteLine("-----");
            Console.WriteLine("Total number of locations: {0}.", cnt);
            Console.WriteLine("-----");
            foreach (var location in missingLocations)
            {
                Console.WriteLine("{0}, {1} -- {2}", location.Item1, location.Item2, location.Item3);
            }

            Console.WriteLine("-----");
            Console.WriteLine("Processing completed.");
            Console.ReadLine();

            // Get all indexed locations from database.
            // Look for location in first index.
            // If found look for the location in the second index.
            // If not found increment counter and display location id and name.
            // when finished display count.
        }
示例#4
0
        /// <summary>
        /// executes the process to determine the formatting code for duplicate FormattedNames.
        /// </summary>
        public void Configure()
        {
            var countryCodes = _adoClientService.GetCountryCodes();

            foreach (var countryCode in countryCodes)
            {
                Console.WriteLine(string.Format("--> Processing: '{0}'", countryCode));

                var duplicateFormattedNames = _adoClientService.GetDuplicateFormattedNames(countryCode);
                if (duplicateFormattedNames.Count() == 0)
                {
                    continue;
                }

                var formattedNamesObjects = _adoClientService.GetDuplicates(duplicateFormattedNames, countryCode);

                foreach (var formattedName in duplicateFormattedNames)
                {
                    var names   = formattedNamesObjects.Where(x => x.FormattedNameNon.Equals(formattedName)).ToList();
                    var typeIds = names.Select(x => x.TypeId).Distinct().ToList();

                    if (typeIds.Count() == 1)
                    {
                        _adoClientService.SetFormatting(names.ToList(), 1);
                    }
                    if (typeIds.Count() == 2)
                    {
                        if (names.Count() == 2)
                        {
                            _adoClientService.SetFormatting(names.ToList(), 2);
                        }
                        else
                        {
                            _adoClientService.SetFormatting(names.ToList(), 3);
                        }
                    }
                }
            }
        }