Пример #1
0
        public void AddCompareListsToDB()
        {
            RestaurantsCompareList compList = new RestaurantsCompareList();
            OpenStreetMapServices osm = new OpenStreetMapServices();

            //act
            string id = osm.AddRestaurantsCompareListToImportedDB(compList);

            //assert
            Assert.IsNotNull(id);
        }
Пример #2
0
 public string AddRestaurantsCompareListToImportedDB(RestaurantsCompareList compareList)
 {
     try
     {
         compareList.CompareDate = DateTime.UtcNow;
         log.InfoFormat("[AddRestaurantsCompareListToImportedDB] compareList.CompareDate={0}, compareList.CompareSource={1}, compareList.Count={2}, compareList.Id={3}.", compareList.CompareDate, compareList.CompareSource, compareList.CompareList.Count, compareList.Id.ToString());
         //using (ImportedRestaurants restaurantsDb = new ImportedRestaurants())
         using (FinlandSwedenOSMRestaurants restaurantsDb = new FinlandSwedenOSMRestaurants())
         {
             MongoEntityRepositoryBase<RestaurantsCompareList> basicData =
                             new MongoEntityRepositoryBase<RestaurantsCompareList>(restaurantsDb.DB);
             basicData.Add(compareList);
             return compareList.Id.ToString();
         }
     }
     catch (Exception e)
     {
         log.ErrorFormat("[AddRestaurantsCompareListToImportedDB] Exception={0}.", e);
         return null;
     }
 }
Пример #3
0
        /// <summary>
        /// If find new restaurants, add them to DB, if already exists compare attributes and update if necessary
        /// </summary>
        /// <param name="compareList"></param>
        public void UpdateCompareResult(RestaurantsCompareList compareList)
        {
            try
            {
                log.InfoFormat("[UpdateCompareResult].");
                OpenStreetMapServices osmServices = new OpenStreetMapServices();

                if (compareList != null)
                {
                    foreach (var restList in compareList.CompareList)
                    {
                        if (restList.HasSimilarRest)
                        {
                            UpdateDbFromRestaurantOsmData(restList.OsmRest.Id, restList.SimilarRests[restList.IndexOfSimilarRest].Id);
                        }
                        else //HasSimilarRest = false
                        {
                            UpdateDbFromRestaurantOsmData(restList.OsmRest.Id);
                        }
                    }
                }
                else log.WarnFormat("[UpdateCompareResult] CompareList is null.)");
            }
            catch (Exception e)
            {
                log.ErrorFormat("[UpdateCompareResult] Exception={0].", e);
            }
        }
Пример #4
0
        /// <summary>
        /// Print to log compareList
        /// </summary>
        /// <param name="compareList"></param>
        public void PrintCompareListCounts(RestaurantsCompareList compareList)
        {
            log.InfoFormat("[PrintCompareListCounts].");
            int hasSimilarCount = 0;
            int noSimilarCount = 0;
            int notSimilarWithNearest = 0;
            int notSimilarWithoutNearest = 0;
            OpenStreetMapServices osmServices = new OpenStreetMapServices();

            if (compareList != null)
            {
                foreach (var restList in compareList.CompareList)
                {
                    if (restList.HasSimilarRest)
                    {
                        hasSimilarCount++;
                        string similarRest = (restList.SimilarRests != null && restList.SimilarRests[restList.IndexOfSimilarRest] != null) ? restList.SimilarRests[restList.IndexOfSimilarRest].ToString() : "uknown";
                        if (similarRest != "uknown") restList.OsmRest.ReferenceId = restList.SimilarRests[restList.IndexOfSimilarRest].Id;
                        log.InfoFormat("[PrintCompareListCounts] HasSimilarRest=True: RestaurantOSM={0}, RestaurantBasicData={1}.", restList.OsmRest.ToString(), similarRest);
                    }
                    else //HasSimilarRest = false
                    {
                        noSimilarCount++;
                        List<string> restsNames = new List<string>();
                        if (restList.SimilarRests.Count > 0)
                        {
                            notSimilarWithNearest++;
                            foreach (var rest in restList.SimilarRests)
                            {
                                restsNames.Add("Rest.Name=" + rest.Name + ", Rest.Id=" + rest.Id.ToString());
                            }
                        }
                        else notSimilarWithoutNearest++;
                        log.InfoFormat("[PrintCompareListCounts] HasSimilarRest=False: RestaurantOSM={0}, NearestRestsList={1}.", restList.OsmRest.ToString(), restsNames.ToString());
                    }
                }
                log.InfoFormat("[PrintCompareListCounts] after log loop, hasSimilarCount={0}, noSimilarCount={1}, notSimilarWithNearest={2}, notSimilarWithoutNearest={3}.", hasSimilarCount, noSimilarCount, notSimilarWithNearest, notSimilarWithoutNearest);
            }
            else log.InfoFormat("[PrintCompareListCounts] CompareList is null.)");
        }
Пример #5
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;
        }
Пример #6
0
 public void UpdateCompareResult(RestaurantsCompareList compareList)
 {
     throw new NotImplementedException();
 }