コード例 #1
0
ファイル: OsmTests.cs プロジェクト: pashkov/Spontaneous
        public void GetRestaurantOsmByIdTest_ShouldGetRestaurantById()
        {
            string restaurantId = "53b126ed059232096074e61d";
            OpenStreetMapServices osm = new OpenStreetMapServices();
            var rest = osm.GetRestaurantOsmById(restaurantId);

            Assert.IsNotNull(rest);
        }
コード例 #2
0
ファイル: OsmTests.cs プロジェクト: pashkov/Spontaneous
        public void GetAllRestaurantsOsm_ShouldReturnAllRestaurantsOsmFromDB()
        {
            OpenStreetMapServices osm = new OpenStreetMapServices();

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

            //assert
            Assert.IsNotNull(returnedList);
        }
コード例 #3
0
ファイル: OsmTests.cs プロジェクト: pashkov/Spontaneous
        public void GetAllCompareListsFromDB()
        {
            OpenStreetMapServices osm = new OpenStreetMapServices();

            //act
            var allLists = osm.GetAllRestaurantsCompareLists();
            foreach (var list in allLists)
            {
                Console.Write("CompareDate: " + list.CompareDate.ToString() + "; Id: " + list.Id.ToString());
            }
        }
コード例 #4
0
ファイル: OSMTests.cs プロジェクト: pashkov/Spontaneous
        public void AddCompareListsToDB()
        {
            RestaurantsCompareList compList = new RestaurantsCompareList();
            OpenStreetMapServices osm = new OpenStreetMapServices();

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

            //assert
            Assert.IsNotNull(id);
        }
コード例 #5
0
ファイル: OSMTests.cs プロジェクト: pashkov/Spontaneous
        public void ReadOSMXmlTest_ShouldReturnNotNullListOfOsmNodeElements()
        {
            string path = @"E:\Work\osmosis-latest\bin\israel_all_foods.osm";
            OpenStreetMapServices osm = new OpenStreetMapServices();
            var nodeList = osm.ReadOSMXml(path);

            Assert.IsNotNull(nodeList);
            Assert.IsTrue(nodeList.Count > 0);
        }
コード例 #6
0
ファイル: OSMTests.cs プロジェクト: pashkov/Spontaneous
        public void PrintCompareListCountsTest()
        {
            OpenStreetMapServices osm = new OpenStreetMapServices();

            //act
            var allLists = osm.GetAllRestaurantsCompareLists();
            foreach (var list in allLists)
            {
                serviceLayer.PrintCompareListCounts(list);
            }
        }
コード例 #7
0
ファイル: OSMTests.cs プロジェクト: pashkov/Spontaneous
        public void NodesToRestaurantsOsmTest_ShouldConvertAllNodesToRestaurantsOsmList()
        {
            string path = @"E:\Work\osmosis-latest\bin\israel_all_foods.osm";
            OpenStreetMapServices osm = new OpenStreetMapServices();
            var nodeList = osm.ReadOSMXml(path);
            //act
            List<RestaurantOsm> restList = osm.NodesToRestaurantsOsm(nodeList);

            //assert
            Assert.IsNotNull(restList);
        }
コード例 #8
0
ファイル: OSMTests.cs プロジェクト: pashkov/Spontaneous
        public void ImportRestaurantsFromXmlTest_ShouldParseXml_ConverAllNodesToRestaurantOsm_AndAddToDb()
        {
            //string path = @"E:\Work\osmosis-latest\bin\israel_all_foods.osm";
            OpenStreetMapServices osm = new OpenStreetMapServices();

            //act
            //osm.ImportRestaurantsFromXml(path);
        }
コード例 #9
0
        /// <summary>
        /// Should add new restaurant if not exists or add new data to existing restaurant
        /// </summary>
        /// <param name="osmRestId">
        /// Id of RestaurantOSM
        /// </param>
        /// <param name="similarRestId">
        /// Id of existing similar restaurant in main DB
        /// </param>
        public void UpdateDbFromRestaurantOsmData(ObjectId osmRestId, ObjectId similarRestId)
        {
            try
            {
                string osmRestIdStr = osmRestId != null && osmRestId.ToString().IndexOf("000") < 0 ? osmRestId.ToString() : "";
                string similarRestIdStr = similarRestId != null && similarRestId.ToString().IndexOf("000") < 0 ? similarRestId.ToString() : "";
                log.InfoFormat("[UpdateDbFromRestaurantOsmData] osmRestId={0}, similarRestId={1}.", osmRestIdStr, similarRestIdStr);
                OpenStreetMapServices osmServices = new OpenStreetMapServices();

                RestaurantOsm tempOsmRest = osmServices.GetRestaurantOsmById(osmRestId.ToString());
                RestaurantBasicData existRest = GetRestaurantBasicById(similarRestIdStr);
                if (existRest != null)
                {
                    if (tempOsmRest.ReferenceId.ToString() != existRest.Id.ToString())
                    {
                        tempOsmRest.ReferenceId = existRest.Id;
                        osmServices.UpdateRestaurantOsm(tempOsmRest);
                    }
                    RestaurantBasicData tempBasicRest = tempOsmRest.RestaurantOsmToRestaurantBasicData(existRest);
                    if (tempBasicRest != null) // Some properties was updated
                    {
                        tempBasicRest.Source = "OpenStreetMap";
                        UpdateRestaurant(tempBasicRest);
                    }
                }
                else
                {
                    AddNewRestaurantFromOsmRest(tempOsmRest);
                }
            }
            catch (Exception e)
            {
                log.ErrorFormat("[UpdateDbFromRestaurantOsmData] Exception={0}", e);
            }
        }
コード例 #10
0
        /// <summary>
        /// Should add new restaurant if not exists or add new data to existing restaurant
        /// </summary>
        public void UpdateDbFromRestaurantOsmData(ObjectId osmRestId)
        {
            try
            {
                string id = (osmRestId != null && osmRestId.ToString().IndexOf("000000") < 0) ? osmRestId.ToString() : "";
                log.InfoFormat("[UpdateDbFromRestaurantOsmData] osmRestId={0}.", id);
                OpenStreetMapServices osmServices = new OpenStreetMapServices();

                RestaurantOsm tempOsmRest = osmServices.GetRestaurantOsmById(osmRestId.ToString());
                if (tempOsmRest != null)
                {
                    if (tempOsmRest.ReferenceId == null || tempOsmRest.ReferenceId.ToString().IndexOf("000000") >= 0)
                    {
                        AddNewRestaurantFromOsmRest(tempOsmRest);
                    }
                    else // already has reference then update if necessary
                    {
                        string existRestId = tempOsmRest.ReferenceId.ToString();
                        log.WarnFormat("[UpdateDbFromRestaurantOsmData] already has reference, existRestId={0}.", existRestId);
                        UpdateDbFromRestaurantOsmData(osmRestId, tempOsmRest.ReferenceId);
                    }
                }
            }
            catch (Exception e)
            {
                log.ErrorFormat("[UpdateDbFromRestaurantOsmData] Exception={0}", e);
            }
        }
コード例 #11
0
ファイル: OsmTests.cs プロジェクト: pashkov/Spontaneous
        public void ReadOSMXmlTest_ShouldReturnNotNullListOfOsmNodeElements()
        {
            //string path = @"C:\osmosis-latest\bin\finland_places.osm";
            OpenStreetMapServices osm = new OpenStreetMapServices();
            var nodeList = osm.ReadOSMXml(path);

            Assert.IsNotNull(nodeList);
            Assert.IsTrue(nodeList.Count > 0);
        }
コード例 #12
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.)");
        }
コード例 #13
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;
        }
コード例 #14
0
 /// <summary>
 /// Add conver RestaurantOsm to RestaurantBasicData and Add new rest to DB
 /// </summary>
 /// <param name="osmRestId">
 /// RetaurantOsm
 /// </param>
 public void AddNewRestaurantFromOsmRest(RestaurantOsm osmRest)
 {
     try
     {
         string osmRestId = osmRest.Id.ToString();
         log.InfoFormat("[AddNewRestaurantFromOsmRest] osmRest.Id={0}.", osmRestId);
         OpenStreetMapServices osmServices = new OpenStreetMapServices();
         RestaurantBasicData tempRest = osmRest.RestaurantOsmToRestaurantBasicData();
         if (tempRest != null)
         {
             tempRest.Source = "OpenStreetMap";
             string newRestId = AddRestaurantBasicToDB(tempRest);
             if (newRestId != null)
             {
                 osmRest.ReferenceId = ObjectId.Parse(newRestId);
                 osmServices.UpdateRestaurantOsm(osmRest);
             }
         }
     }
     catch (Exception e)
     {
         log.ErrorFormat("[AddNewRestaurantFromOsmRest] Exception={0}.", e);
     }
 }
コード例 #15
0
ファイル: OSMTests.cs プロジェクト: pashkov/Spontaneous
        public void UpdateCompareResult_ShouldAddNewRestaurantsToDB_if_already_exists_compare_attributes_and_update_if_necessary()
        {
            OpenStreetMapServices osm = new OpenStreetMapServices();
            var allLists = osm.GetAllRestaurantsCompareLists();

            //act
            foreach (var list in allLists)
            {
                serviceLayer.UpdateCompareResult(list);
            }
        }
コード例 #16
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);
            }
        }
コード例 #17
0
 public ActionResult UpdateComparedListConfirmed()
 {
     log.InfoFormat("[UpdateComparedListConfirmed].");
     OpenStreetMapServices osm = new OpenStreetMapServices();
     var allLists = osm.GetAllRestaurantsCompareLists();
     if (allLists != null && allLists.Count > 0)
     {
         m_serviceLayer.UpdateCompareResult(allLists[0]);
     }
     return RedirectToAction("PagedRestaurants");
 }