Пример #1
0
        public void TestSearch()
        {
            InitMPData();

            for (int i = 0; i < testCriteria_search.GetLength(0); i++)
            {
                string query       = testCriteria_search[i, 0];
                string expectedUrl = testCriteria_search[i, 1];

                _ = ResultParameters.ParseParameters(ref query); //This is here just to filter out any query items (not to be used)
                SearchParameters searchParameters = SearchParameters.ParseParameters(ref query);

                SearchResult searchResult = MountainProjectDataSearch.Search(query, searchParameters);

                if (string.IsNullOrEmpty(expectedUrl))
                {
                    Assert.IsNull(searchResult.FilteredResult, "Failed for " + testCriteria_search[i, 0]);
                }
                else
                {
                    Assert.AreEqual(Utilities.GetSimpleURL(Utilities.MPBASEURL + expectedUrl),
                                    searchResult.FilteredResult.URL, "Failed for " + testCriteria_search[i, 0]);
                }

                Assert.IsTrue(searchResult.TimeSpanTaken().TotalSeconds < 5, $"{query} took too long ({searchResult.TimeTakenMS} ms)");
            }
        }
Пример #2
0
        public static string GetReplyForRequest(string commentBody)
        {
            //Get everything AFTER the keyword, but on the same line
            string queryText = Regex.Match(commentBody, BOTKEYWORDREGEX).Groups[1].Value.Trim();

            if (string.IsNullOrWhiteSpace(queryText))
            {
                return("I didn't understand what you were looking for. Please use the Feedback button below if you think this is a bug");
            }

            ResultParameters resultParameters = ResultParameters.ParseParameters(ref queryText);
            SearchParameters searchParameters = SearchParameters.ParseParameters(ref queryText);

            SearchResult searchResult = MountainProjectDataSearch.Search(queryText, searchParameters);

            return(GetResponse(queryText, searchParameters?.SpecificLocation, searchResult, resultParameters));
        }
Пример #3
0
        public void TestLocationString()
        {
            InitMPData();

            for (int i = 0; i < testCriteria_location.GetLength(0); i++)
            {
                string       query            = testCriteria_location[i, 0];
                string       expectedLocation = testCriteria_location[i, 1];
                SearchResult searchResult     = MountainProjectDataSearch.Search(query);
                string       resultLocation   = BotReply.GetLocationString(searchResult.FilteredResult);
                resultLocation = resultLocation.Replace(Markdown.NewLine, "");       //Remove markdown newline
                resultLocation = resultLocation.Replace("Located in ", "");          //Simplify results for unit test
                resultLocation = Regex.Replace(resultLocation, @"\[|\]\(.*?\)", ""); //Remove markdown link formatting

                Assert.AreEqual(expectedLocation, resultLocation, "Failed for " + testCriteria_location[i, 0]);
                Assert.IsTrue(searchResult.TimeSpanTaken().TotalSeconds < 5, $"{query} took too long ({searchResult.TimeTakenMS} ms)");
            }
        }
Пример #4
0
        private static void ParseInputString()
        {
            MountainProjectDataSearch.InitMountainProjectData(serializationPath);
            if (MountainProjectDataSearch.DestAreas.Count() == 0)
            {
                Console.WriteLine("The xml either doesn't exist or is empty");
                Environment.Exit(0);
            }

            Console.WriteLine("File read.");

            bool keepSearching = true;

            while (keepSearching)
            {
                Console.WriteLine("\n\nPlease input the string you would like to parse: ");
                string input = Console.ReadLine();

                SearchParameters searchParameters = SearchParameters.ParseParameters(ref input);
                ResultParameters resultParameters = ResultParameters.ParseParameters(ref input);

                bool allResults = input.Contains("-all");
                if (allResults)
                {
                    input = input.Replace("-all", "").Trim();
                }

                Stopwatch    stopwatch    = Stopwatch.StartNew();
                SearchResult searchResult = MountainProjectDataSearch.Search(input, searchParameters);
                stopwatch.Stop();

                if (searchResult.IsEmpty())
                {
                    Console.WriteLine("Nothing found matching \"" + input + "\"");
                }
                else if (allResults)
                {
                    List <MPObject> matchedObjectsByPopularity = searchResult.AllResults.OrderByDescending(p => p.Popularity).ToList();
                    Console.WriteLine($"Found {matchedObjectsByPopularity.Count} items match that search query (found in {stopwatch.ElapsedMilliseconds} ms):");
                    foreach (MPObject result in matchedObjectsByPopularity)
                    {
                        string url = result.URL.Replace(Utilities.MPBASEURL, "");
                        if (result is Route)
                        {
                            Console.WriteLine($"    Route: {result.Name} (Pop: {result.Popularity}) | Location: {GetLocationString(result)} | {url}");
                        }
                        else if (result is Area)
                        {
                            Console.WriteLine($"    Area: {result.Name} (Pop: {result.Popularity}) | Location: {GetLocationString(result)} | {url}");
                        }
                    }
                }
                else
                {
                    string   resultStr = "";
                    MPObject result    = searchResult.FilteredResult;
                    if (result is Area)
                    {
                        resultStr = (result as Area).ToString();
                    }
                    else if (result is Route)
                    {
                        resultStr = (result as Route).ToString(resultParameters);
                    }

                    Console.WriteLine($"The following was found (found in {stopwatch.ElapsedMilliseconds} ms):");
                    Console.WriteLine("    " + resultStr);
                    Console.WriteLine($"    Location: {GetLocationString(result, searchResult.RelatedLocation)}");
                    Console.WriteLine("\nOpen result? (y/n) ");
                    if (Console.ReadLine().ToLower() == "y")
                    {
                        Process.Start(result.URL);
                    }
                }

                Console.WriteLine("\nSearch something else? (y/n) ");
                keepSearching = Console.ReadLine().ToLower() == "y";
            }
        }