Ejemplo n.º 1
0
        internal static BusStop ClosestStop(ParkAndRide pr, List <BusStop> stops)
        {
            List <string> common = new List <string>();

            common.Add("north");
            common.Add("south");
            common.Add("west");
            common.Add("east");
            common.Add("valley");

            BusStop[] sarr      = new BusStop[stops.Count];
            double[]  distances = new double[stops.Count];
            for (int i = 0; i < stops.Count; i++)
            {
                string[] streets = stops[i].CrossStreet.Split('&');

                double score = 0.5 * Levenshtein.Compute(pr.Address, stops[i].CrossStreet) +
                               0.25 * Levenshtein.Compute(pr.Name, stops[i].Name) +
                               Levenshtein.Compute(pr.City, stops[i].Name) +
                               Levenshtein.Compute(pr.Address, stops[i].Name);
                distances[i] = score;
                sarr[i]      = stops[i];
            }



            Array.Sort(distances, sarr);

            return(sarr[0]);
        }
Ejemplo n.º 2
0
        internal static List <ParkAndRide> ScrapeParkAndRides()
        {
            List <ParkAndRide> parkAndRides = new List <ParkAndRide>();

            HtmlWeb      webLoader = new HtmlWeb();
            HtmlDocument doc       = webLoader.Load("https://www.wsdot.wa.gov/Choices/parkride.htm");

            var    prNode = doc.DocumentNode.SelectSingleNode("//*[@id=\"block-system-main\"]/div/div/div/table[25]/tbody");
            string city   = null;

            foreach (HtmlNode node in prNode.ChildNodes.Skip(1))
            {
                int startIndex = 0;
                if (string.Compare(node.ChildNodes[0].GetAttributeValue("align", null), "left") == 0)
                {
                    city        = node.ChildNodes[0].InnerText;
                    startIndex += 2;
                }

                if (node.ChildNodes.Count >= 4)
                {
                    string name             = node.ChildNodes[startIndex].InnerText;
                    string address          = node.ChildNodes[startIndex + 2].InnerText;
                    string parkingSpacesStr = node.ChildNodes[startIndex + 4].InnerText;
                    int    parkingSpaces    = -1;
                    if (!int.TryParse(parkingSpacesStr, out parkingSpaces))
                    {
                        continue;
                    }

                    ParkAndRide parkAndRide = new ParkAndRide(city, address, name, parkingSpaces);
                    parkAndRides.Add(parkAndRide);
                }
            }

            return(parkAndRides);
        }