GetAllRestaurantsOsm() public method

public GetAllRestaurantsOsm ( ) : List
return List
Exemplo n.º 1
0
        public void GetAllRestaurantsOsm_ShouldReturnAllRestaurantsOsmFromDB()
        {
            OpenStreetMapServices osm = new OpenStreetMapServices();

            //act
            var returnedList = osm.GetAllRestaurantsOsm();

            //assert
            Assert.IsNotNull(returnedList);
        }
Exemplo n.º 2
0
        public RestaurantsCompareList FindSimilarRestaurants()
        {
            double dist100m = 0.00001573;
            // Giraf herziliya
            double lat = 32.1612206;
            double lon = 34.8065796;
            int searchCount = 20;
            OpenStreetMapServices osmServices = new OpenStreetMapServices();

            Spontaneous.WebApp.Services.SearchUtility searchEngine = new Spontaneous.WebApp.Services.SearchUtility();
            IList<BaseSearchableEnabledItem> nearestRest = searchEngine.Search(new Location() { Latitude = lat, Longitude = lon }, searchCount, null, dist100m);

            RestaurantsCompareList compareList = new RestaurantsCompareList();
            compareList.CompareDate = DateTime.UtcNow;
            compareList.CompareSource = "OpenStreetMap";
            List<RestaurantOsm> restsOsmNoName = new List<RestaurantOsm>();

            List<RestaurantOsm> restOsmList = osmServices.GetAllRestaurantsOsm();
            List<SimilarRestsList> similarList = new List<SimilarRestsList>();
            List<SimilarRestsList> notSimilarList = new List<SimilarRestsList>();

            //act
            int arabCount = 0;
            foreach (var restOsm in restOsmList)
            {
                string name = null;
                if (restOsm.LocalizedName != null && restOsm.LocalizedName.GetDescription("ar") != null) arabCount++;
                if (restOsm.Name == null && restOsm.LocalizedName != null)
                {
                    if (restOsm.LocalizedName.GetDescription("he") != null) name = restOsm.LocalizedName.GetDescription("he");
                    else
                    {
                        if (restOsm.LocalizedName.GetDescription("en") != null) name = restOsm.LocalizedName.GetDescription("en");
                        else
                        {
                            if (restOsm.LocalizedName.GetDescription("ar") != null) name = restOsm.LocalizedName.GetDescription("ar");
                        }
                    }
                }
                if (restOsm.Name != null) name = restOsm.Name;

                if (name != null)
                {
                    /// Boolean flag for restaurants names compare
                    bool contains = false;
                    SimilarRestsList tempSimRest = new SimilarRestsList()
                    {
                        OsmRest = restOsm,
                    };
                    SimilarRestsList tempNotSimRest = new SimilarRestsList()
                    {
                        OsmRest = restOsm,
                    };

                    var searchList = SearchNearestService(restOsm.ItemLocation, searchCount, dist100m);
                    var restList = searchList.OfType<RestaurantBasicData>();
                    foreach (var rest in restList)
                    {
                        rest.Menu = null;
                        contains = CompareRestaurantsNames(rest.Name, name);

                        if (contains)
                        {
                            tempSimRest.SimilarRests.Add(rest);
                            contains = false;
                        }
                        else
                        {
                            tempNotSimRest.SimilarRests.Add(rest);
                        }

                    }//foreach (var rest in restList)
                    if (tempSimRest.SimilarRests.Count > 0)
                    {
                        tempSimRest.HasSimilarRest = true;
                        tempNotSimRest.IndexOfSimilarRest = 0;
                        similarList.Add(tempSimRest);
                        compareList.CompareList.Add(tempSimRest);
                    }
                    else
                    {
                        tempNotSimRest.HasSimilarRest = false;
                        notSimilarList.Add(tempNotSimRest);
                        compareList.CompareList.Add(new SimilarRestsList() { HasSimilarRest = false, OsmRest = restOsm, SimilarRests = restList.ToList() });
                    }
                }//if (restOsm.Name != null)
                else
                {
                    restsOsmNoName.Add(restOsm);
                }
            }//foreach (var restOsm in restOsmList)

            List<SimilarRestsList> mustCheckList = notSimilarList.FindAll(s => s.SimilarRests.Count > 0);

            //Console.Write("restListTest.Count=" + restListTest.Count + "\n");
            Console.Write("similarList.Count=" + similarList.Count + "\n");
            Console.Write("notSimilarList.Count=" + notSimilarList.Count + "\n");
            Console.Write("mustCheckList.Count=" + mustCheckList.Count + "\n");
            Console.Write("arabCount=" + arabCount + "\n");
            Console.Write("restsOsmNoName.Count=" + restsOsmNoName.Count + "\n");

            int hasSimilarCount = 0;
            int noSimilarCount = 0;
            int notSimilarWithNearest = 0;
            int notSimilarWithoutNearest = 0;
            foreach (var restList in compareList.CompareList)
            {
                if (restList.HasSimilarRest)
                {
                    hasSimilarCount++;
                }
                else //HasSimilarRest = false
                {
                    noSimilarCount++;
                    if (restList.SimilarRests.Count > 0)
                    {
                        notSimilarWithNearest++;
                    }
                    else notSimilarWithoutNearest++;
                }
            }
            log.InfoFormat("[FindSimilarRestaurants] Check loop, hasSimilarCount={0}, noSimilarCount={1}, notSimilarWithNearest={2}, notSimilarWithoutNearest={3}.", hasSimilarCount, noSimilarCount, notSimilarWithNearest, notSimilarWithoutNearest);

            return compareList;
        }