Пример #1
0
        static void Main(string[] args)
        {
            // TODO:  Find the two Taco Bells that are the furthest from one another.
            // HINT:  You'll need two nested forloops ---------------------------

            logger.LogInfo("Log initialized");

            // use File.ReadAllLines(path) to grab all the lines from your csv file
            // Log and error if you get 0 lines and a warning if you get 1 line
            var lines = File.ReadAllLines(csvPath);

            logger.LogInfo($"Lines: {lines[0]}");

            // Create a new instance of your TacoParser class
            var parser = new TacoParser();

            var locations = lines.Select(line => parser.Parse(line)).ToArray();

            ITrackable location1 = new TacoBell();
            ITrackable location2 = new TacoBell();

            double distance = 0;

            for (int i = 0; i < locations.Length; i++)
            {
                var locA = locations[i];
                var corA = new GeoCoordinate();
                corA.Latitude  = locA.Location.Latitude;
                corA.Longitude = locA.Location.Longitude;

                for (int j = 0; j < locations.Length; j++)
                {
                    var locB = locations[j];
                    var corB = new GeoCoordinate(locB.Location.Latitude, locB.Location.Longitude);

                    if (corA.GetDistanceTo(corB) > distance)
                    {
                        distance  = corA.GetDistanceTo(corB);
                        location1 = locA;
                        location2 = locB;
                    }
                }
            }
            var distanceInMile = Math.Round(distance * .0006231, 2);

            Console.WriteLine($"  {location1.Name} and {location2.Name} are {distanceInMile} miles apart");
        }
Пример #2
0
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("You must provide a filename as an argument");
                Logger.Fatal("Cannot import without filename specified as an argument");
                return;
            }

            Logger.Info("Log initialized");
            var lines     = File.ReadAllLines(args[0]);
            var parser    = new TacoParser();
            var locations = lines.Select(line => parser.Parse(line));

            //TODO:  Find the two TacoBells in Alabama that are the furthurest from one another.
            //HINT:  You'll need two nested forloops

            /*for (int i = 0; i < 10; i++)
             * {
             *
             * }*/

            // DON'T FORGET TO LOG YOUR STEPS
            // Grab the path from Environment.CurrentDirectory + the name of your file

            // use File.ReadAllLines(path) to grab all the lines from your csv file
            // Log and error if you get 0 lines and a warning if you get 1 line

            // Create a new instance of your TacoParser class
            // Grab an IEnumerable of locations using the Select command: var locations = lines.Select(line => parser.Parse(line));

            // Now, here's the new code

            // Create two `ITrackable` variables with initial values of `null`. These will be used to store your two taco bells that are the furthest from each other.
            // Create a `double` variable to store the distance

            // Include the Geolocation toolbox, so you can compare locations
            // Do a loop for your locations to grab each location as the origin (perhaps: `locA`)
            // Create a new Coordinate with your locA's lat and long

            // Now, do another loop on the locations with the scope of your first loop, so you can grab the "destination" location (perhaps: `locB`)
            // Create a new Coordinate with your locB's lat and long
            // Now, compare the two using `GeoCalculator.GetDistance(origin, destination)`, which returns a double
            // If the distance is greater than the currently saved distance, update the distance and the two `ITrackable` variables you set above

            // Once you've looped through everything, you've found the two Taco Bells furthest away from each other.
        }
Пример #3
0
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("You must provide a filename as an argument");
                Logger.Fatal("Cannot import without filename specified as an argument");
                return;
            }

            Logger.Info("Log initialized");
            var lines     = File.ReadAllLines(args[0]);
            var parser    = new TacoParser();
            var locations = lines.Select(line => parser.Parse(line));

            //TODO:  Find the two TacoBells in Alabama that are the furthurest from one another.
            //HINT:  You'll need two nested forloops
        }
Пример #4
0
        static void Main(string[] args)
        {
            var path = Environment.CurrentDirectory + "\\Taco_Bell-US-AL-Alabama.csv";

            if (path.Length == 0)
            {
                Console.WriteLine("You must provide a filename as an argument");
                Logger.Fatal("Cannot import without filename specified as an argument");
                Console.ReadLine();
                return;
            }
            Logger.Info("Log initialized");
            Logger.Info("Grabbing form path:" + path);
            var lines = File.ReadAllLines(path);

            if (lines.Length == 0)
            {
                Logger.Error("No Locations to check. Must have atleast one Location");
            }
            else if (lines.Length == 1)
            {
                Logger.Warn("Only one Location is provided");
            }

            var parser = new TacoParser();

            Logger.Debug("Initialized our parser");
            var        locations = lines.Select(line => parser.Parse(line));
            ITrackable a         = null;
            ITrackable b         = null;
            double     distance  = 0;

            foreach (var locA in locations)
            {
                Logger.Debug("Checking Origin Location");
                var origin = new Coordinate
                {
                    Latitude  = locA.Location.Latitude,
                    Longitude = locA.Location.Longitude
                };
                foreach (var locB in locations)
                {
                    Logger.Debug("Checking origin against destination location");
                    var destination = new Coordinate
                    {
                        Latitude  = locB.Location.Latitude,
                        Longitude = locB.Location.Longitude
                    };
                    Logger.Debug("Getting distance in miles");
                    var nDistance = GeoCalculator.GetDistance(origin, destination);
                    if (nDistance > distance)
                    {
                        Logger.Info("Found the next furthest part");
                        a        = locA;
                        b        = locB;
                        distance = nDistance;
                    }
                }
            }

            if (a == null || b == null)
            {
                Logger.Error("Failed to find the farthest location");
                Console.WriteLine("Couldn't find the furthest apart");
                Console.ReadLine();
                return;
            }

            Console.WriteLine($"The two tacobells that are farthest apart are: {a.Name} and {b.Name}");
            Console.WriteLine($"These two locations are {distance} apart");
            Console.ReadLine();
        }
Пример #5
0
        static void Main(string[] args)
        {
            var path = Environment.CurrentDirectory + "\\Taco_Bell-US-AL-Alabama.csv";

            if (path.Length == 0)
            {
                Console.WriteLine("You must provide a filename as an argument");
                Logger.Fatal("Cannot import without filename specified as an argument");
                Console.ReadLine();
                return;
            }
            Logger.Info("Log initialized");
            Logger.Info("Grabbing from path: = + path");
            var lines = File.ReadAllLines(path);

            if (lines.Length == 0)
            {
                Logger.Error("No Locations to check. Must have atleast one Location");
            }
            else if (lines.Length == 1)
            {
                Logger.Warn("Only one Location is provided");
            }

            Console.WriteLine("Initializing TacoParser");

            var parser    = new TacoParser();
            var locations = lines.Select(line => parser.Parse(line));

            Console.WriteLine("Parsed Locations");

            //TODO:  Find the two TacoBells in Alabama that are the furthurest from one another.
            //HINT:  You'll need two nested forloops
            ITrackable a = null;
            ITrackable b = null;

            double distance = 0;

            Console.WriteLine("Starting Foreach");

            foreach (var locA in locations)
            {
                var origin = new Coordinate
                {
                    Latitude  = locA.Location.Latitude,
                    Longitude = locA.Location.Longitude
                };

                foreach (var locB in locations)
                {
                    var destination = new Coordinate
                    {
                        Latitude  = locB.Location.Latitude,
                        Longitude = locB.Location.Longitude
                    };

                    var nDist = GeoCalculator.GetDistance(origin, destination);

                    if (!(nDist > distance))
                    {
                        continue;
                    }
                    Console.WriteLine("Found the next furthest apart");
                    a        = locA;
                    b        = locB;
                    distance = nDist;
                }
            }

            Console.WriteLine("Finished foreach loops");

            if (a == null || b == null)
            {
                Logger.Error("Failed to find the furthest location");
                Console.WriteLine("Couldn't find the locations furthest apart");
                Console.ReadLine();
                return;
            }
            Console.WriteLine($"The two Taco Bells that are furthest apart are: {a.Name} and {b.Name}");
            Console.WriteLine($"These two locations are {distance} apart");
            Console.ReadLine();
        }
Пример #6
0
        static void Main(string[] args)
        {
            // TODO:  Find the two Taco Bells that are the furthest from one another.
            // HINT:  You'll need two nested forloops ---------------------------

            logger.LogInfo("Log initialized");

            // use File.ReadAllLines(path) to grab all the lines from your csv file
            // Log and error if you get 0 lines and a warning if you get 1 line
            var lines = File.ReadAllLines(csvPath);

            logger.LogInfo($"Lines: {lines[0]}");

            // Create a new instance of your TacoParser class


            // Grab an IEnumerable of locations using the Select command: var locations = lines.Select(parser.Parse);


            // DON'T FORGET TO LOG YOUR STEPS

            // Now that your Parse method is completed, START BELOW ----------

            // TODO: Create two `ITrackable` variables with initial values of `null`.
            // These will be used to store your two taco bells that are the farthest from each other.
            ITrackable locA = null;
            ITrackable locB = null;

            // Create a `double` variable to store the distance
            var parser = new TacoParser();

            var locations = lines.Select(line => parser.Parse(line)).ToArray();

            ITrackable tacoBell1 = new TacoBell();
            ITrackable tacoBell2 = new TacoBell();

            double distance = 0;

            for (int i = 0; i < locations.Length; i++)
            {
                var locationOne = locations[i];
                var corA        = new GeoCoordinate();
                corA.Latitude  = locationOne.Location.Latitude;
                corA.Longitude = locationOne.Location.Longitude;

                for (int j = 0; j < locations.Length; j++)
                {
                    var locationTwo = locations[j];
                    var corB        = new GeoCoordinate(locationTwo.Location.Latitude, locationTwo.Location.Longitude);

                    if (corA.GetDistanceTo(corB) > distance)
                    {
                        distance  = corA.GetDistanceTo(corB);
                        tacoBell1 = locA;
                        tacoBell2 = locB;
                    }
                }
            }

            logger.LogInfo($"The two farthest apart are {locA.Name} and {locB.Name} at {distance * 0.0000621371} miles apart");
        }
Пример #7
0
        static void Main(string[] args)
        {
            Logger.Info("Log initialized");

            var csvPath = Environment.CurrentDirectory + "\\Taco_Bell-US-AL-Alabama.csv";

            Logger.Debug("Created csvPath variable: " + csvPath);

            var rows = File.ReadAllLines(csvPath);

            switch (rows.Length)
            {
            case 1:
                Logger.Error("Our csv file is missing or empty of content");
                break;

            case 2:
                Logger.Warn("Can't compare. There is only one element");
                break;
            }

            var parser = new TacoParser();

            Logger.Debug("Initialized our Parser");

            var locations = rows.Select(row => parser.Parse(row))
                            .OrderBy(loc => loc.Location.Longitude)
                            .ThenBy(loc => loc.Location.Latitude)
                            .ToArray();

            ITrackable a = null;

            ITrackable b = null;

            double distance = 0;

            //TODO:  Find the two TacoBells in Alabama that are the furthurest from one another.
            foreach (var locA in locations)
            {
                var origin = new Coordinate {
                    Latitude = locA.Location.Latitude, Longitude = locA.Location.Longitude
                };
                foreach (var locB in locations)
                {
                    var destination = new Coordinate {
                        Latitude = locB.Location.Latitude, Longitude = locB.Location.Longitude
                    };
                    var nDist = GeoCalculator.GetDistance(origin, destination);

                    if (!(nDist > distance))
                    {
                        continue;
                    }
                    Logger.Info("Found two furthest locations");
                    a        = locA;
                    b        = locB;
                    distance = nDist;
                }
            }
            if (a == null || b == null)
            {
                Logger.Error("Failed to find two furthest locations");
                Console.WriteLine("Couldn't find the two furthest locations");
                Console.ReadLine();
                return;
            }
            var logMessage =
                $"The two Taco Bells that are furthest apart are: {a.Name} and: {b.Name}. These two locations are {distance} miles apart.";

            Logger.Info(logMessage);
            Console.WriteLine(logMessage);
            Console.ReadLine();
        }
Пример #8
0
        static void Main(string[] args)

        {
            var path = Environment.CurrentDirectory + "//Taco_Bell-US-AL-Alabama.csv";



            if (path.Length == 0)

            {
                Console.WriteLine("You must provide a filename as an argument");

                Logger.Fatal("Cannot import without filename specified in our path variable");

                return;
            }



            Logger.Info("Log initialized");

            Logger.Info("Grabbing from path" + path);



            var lines = File.ReadAllLines(path);



            if (lines.Length == 0)

            {
                Logger.Error("No locations to check for");
            }

            else if (lines.Length == 1)

            {
                Logger.Warn("Only one location provided");
            }

            var parser = new TacoParser();

            Logger.Debug("Initialized our Parser");



            var locations = lines.Select(line => parser.Parse(line))

                            .OrderBy(loc => loc.Location.Latitude)

                            .ThenBy(loc => loc.Location.Longitude)

                            .ToArray();



            //TODO:  Find the two TacoBells in Alabama that are the furthurest from one another.

            ITrackable a = null;

            ITrackable b = null;

            double distance = 0;

            foreach (var locA in locations)

            {
                var origin = new Coordinate

                {
                    Latitude = locA.Location.Latitude,

                    Longitude = locA.Location.Longitude
                };

                foreach (var locB in locations)

                {
                    var dest = new Coordinate

                    {
                        Latitude = locB.Location.Latitude,

                        Longitude = locB.Location.Longitude
                    };



                    var nDist = GeoCalculator.GetDistance(origin, dest);



                    if (nDist > distance)

                    {
                        a = locA;

                        b = locB;

                        distance = nDist;
                    }
                }
            }



            if (a == null || b == null)

            {
                Logger.Error("Failed to find furthest locations");

                Console.WriteLine("Couldn't find the distance between furthest locations");

                Console.ReadLine();
            }



            Console.WriteLine($"the two taco bell's that are farthest apart are {a.Name} and : {b.Name}");

            Console.WriteLine($"These two locations are {distance} miles away");

            Console.ReadLine();
        }
Пример #9
0
        static void Main(string[] args)
        {
            Logger.Info("Log initialized");

            var csvPath = Environment.CurrentDirectory + "\\Taco_Bell-US-AL-Alabama.csv";

            Logger.Debug("Created csvPath variable: " + csvPath);

            var rows = File.ReadAllLines(csvPath);

            if (rows.Length == 0)
            {
                Logger.Error("No locations to check. Must have at least one locations.");
            }
            else if (rows.Length == 1)
            {
                Logger.Warn("Only one location provided. Must have two to perform a check.");
            }

            var parser = new TacoParser();


            var locations = rows.Select(row => parser.Parse(row))
                            .OrderBy(loc => loc.Location.Longitude)
                            .ThenBy(loc => loc.Location.Latitude)
                            .ToArray();

            ITrackable a        = null;
            ITrackable b        = null;
            double     distance = 0;

            //TODO:  Find the two TacoBells in Alabama that are the furthurest from one another.

            foreach (var locA in locations)
            {
                var origin = new Coordinate
                {
                    Latitude  = locA.Location.Latitude,
                    Longitude = locA.Location.Longitude
                };

                foreach (var locB in locations)
                {
                    var dest = new Coordinate
                    {
                        Latitude  = locB.Location.Latitude,
                        Longitude = locB.Location.Longitude
                    };

                    var nDist = GeoCalculator.GetDistance(origin, dest);

                    if (nDist > distance)
                    {
                        Logger.Info("Found the next furthest apart");
                        a        = locA;
                        b        = locB;
                        distance = nDist;
                    }
                }
            }

            Console.WriteLine($"The two Taco Bells that are the furthest apart are: {a.Name} and {b.Name}");
            Console.WriteLine($"These two locations are {distance} miles apart.");
            Console.ReadLine();
        }
Пример #10
0
        static void Main(string[] args)
        {
            Logger.LogInfo("Log initialized");

            Logger.LogInfo("Reading lines");
            var lines = File.ReadAllLines(csvPath);

            Logger.LogInfo($"Lines: {lines[0]}");

            switch (lines.Length)
            {
            case 0:
                Logger.LogError("No lines to read from file.");
                break;

            case 1:
                Logger.LogWarning("Only 1 line exists in the file. 2 lines are needed to calculate distance.");
                break;

            default:
                break;
            }

            var parser = new TacoParser();

            // IEnumerable of locations.
            var locations = lines.Select(line => parser.Parse(line));

            // Two Taco Bell locations.
            ITrackable locA     = null;
            ITrackable locB     = null;
            double     distance = 0.00;

            foreach (var loc1 in locations)
            {
                // Store lat and long in coordinate variables for origin and destination Taco Bells.
                var corA = new GeoCoordinate
                {
                    Longitude = loc1.Location.Longitude,
                    Latitude  = loc1.Location.Latitude
                };

                foreach (var loc2 in locations)
                {
                    var corB = new GeoCoordinate
                    {
                        Longitude = loc2.Location.Longitude,
                        Latitude  = loc2.Location.Latitude
                    };

                    // Distance between origin and destination point.
                    var dist = corA.GetDistanceTo(corB);

                    if (dist > distance)
                    {
                        locA     = loc1;
                        locB     = loc2;
                        distance = dist;
                    }
                }
            }
            Console.WriteLine($"The largest distance in the data is between\n\t{locA.Name}\n\t{locB.Name}\nat {Math.Round(distance * 0.000621371)} miles.");
            Console.ReadLine();
        }
Пример #11
0
        static void Main(string[] args)
        {
            var path = Environment.CurrentDirectory + "\\Taco_Bell-US-AL-Alabama.csv";

            if (path.Length == 0)
            {
                Console.WriteLine("You must provide a filename as an argument");
                Logger.Fatal("Cannot import without filename specified in our path variable");
                return;
            }

            Logger.Info("Log initialized");
            Logger.Debug("Created path variable" + path);

            var lines = File.ReadAllLines(path);

            switch (lines.Length)
            {
            case 0:
                Logger.Error("No locations to check. Must have at least one location.");
                break;

            case 1:
                Logger.Warn("Only one location provided. Must have two to perform a check.");
                break;
            }

            Console.ReadLine();

            var parser = new TacoParser();

            Logger.Debug("Initialized our Parser");

            var locations = lines.Select(line => parser.Parse(line))
                            .OrderBy(loc => loc.Location.Longitude)
                            .ThenBy(loc => loc.Location.Latitude)
                            .ToArray();

            ITrackable a = null;
            ITrackable b = null;

            Logger.Info("Comparing all locations");

            double distance = 0;

            foreach (var locA in locations)
            {
                var origin = new Coordinate
                {
                    Latitude  = locA.Location.Latitude,
                    Longitude = locA.Location.Longitude
                };

                foreach (var locB in locations)
                {
                    var destination = new Coordinate
                    {
                        Latitude  = locB.Location.Latitude,
                        Longitude = locB.Location.Longitude
                    };

                    var ndist = GeoCalculator.GetDistance(origin, destination);

                    if (!(ndist > distance))
                    {
                        continue;
                    }
                    a        = locA;
                    b        = locB;
                    distance = ndist;
                }
            }
            Console.WriteLine("Finished foreach loops");

            if (a == null || b == null)
            {
                Logger.Error("Failed to find furthest locations");
                Console.WriteLine("Couldn't find the furthest location apart.");
                Console.ReadLine();
            }

            Console.WriteLine($"The Two Taco Bells that are furthest apart are: {a.Name} and: {b.Name}.");
            Console.WriteLine($"These two locations are {distance} miles away");
            Console.ReadLine();
        }
Пример #12
0
        static void Main(string[] args)
        {
            Console.WriteLine("Started");
            Logger.Info("Log initialized");

            var csvPath = Environment.CurrentDirectory + "\\Taco_Bell-US-AL-Alabama.csv";

            if (csvPath.Length == 0)
            {
                Console.WriteLine("You must provide a filename as an argument");
                Logger.Fatal("Cannot import without filename specified in our path variable");
                Console.ReadLine();
                return;
            }

            Console.WriteLine("Reading Lines");

            var rows = File.ReadAllLines(csvPath);

            switch (rows.Length)
            {
            case 0:
                Logger.Error("Our csv file is missing or empty of content");
                break;

            case 1:
                Logger.Warn("Can't compare. There is only one element");
                break;
            }

            Console.WriteLine("Parsing Tacos");

            var parser = new TacoParser();

            Logger.Info("Initialized our Parser");

            var locations = rows.Select(row => parser.Parse(row))
                            .OrderBy(loc => loc.Location.Longitude)
                            .ThenBy(loc => loc.Location.Latitude)
                            .ToArray();

            Console.WriteLine("Parsed locations");

            ITrackable a        = null;
            ITrackable b        = null;
            double     distance = 0;

            foreach (var locA in locations)
            {
                var origin = new Coordinate
                {
                    Latitude  = locA.Location.Latitude,
                    Longitude = locA.Location.Longitude
                };

                foreach (var locB in locations)
                {
                    var dest = new Coordinate
                    {
                        Latitude  = locB.Location.Latitude,
                        Longitude = locB.Location.Longitude
                    };

                    var nDist = GeoCalculator.GetDistance(origin, dest);

                    if (nDist > distance)
                    {
                        a        = locA;
                        b        = locB;
                        distance = nDist;
                    }
                }
            }

            Console.WriteLine("Foreach loops are finished");

            if (a == null || b == null)
            {
                Logger.Error("Could not find furthest locations");
                Console.WriteLine("Couldn't find the locations furthest apart");
                Console.ReadLine();
            }

            Console.WriteLine($"The 2 TacoBells that are furthest apart are: {a.Name} and: {b.Name}. These 2 locations are {distance} miles apart");
            Console.ReadLine();
        }
Пример #13
0
        static void Main(string[] args)
        {
            // TODO:  Find the two Taco Bells that are the furthest from one another.
            // HINT:  You'll need two nested forloops ---------------------------

            logger.LogInfo("Log initialized");

            // DONE - use File.ReadAllLines(path) to grab all the lines from your csv file
            // Log and error if you get 0 lines and a warning if you get 1 line

            var lines = File.ReadAllLines(csvPath);

            logger.LogInfo($"Lines: {lines[0]}");

            // DONE - Create a new instance of your TacoParser class

            var parser = new TacoParser();

            // DONE - Grab an IEnumerable of locations using the Select command: var locations = lines.Select(parser.Parse);

            var locations = lines.Select(line => parser.Parse(line)).ToArray();

            // DON'T FORGET TO LOG YOUR STEPS

            if (lines.Length == 0)
            {
                logger.LogError("There are 0 lines.", null);
            }
            if (lines.Length == 1)
            {
                logger.LogWarning("There is only 1 line.");
            }

            // Now that your Parse method is completed, START BELOW ----------

            // DONE - TODO: Create two `ITrackable` variables with initial values of `null`. These will be used to store your two taco bells that are the farthest from each other.
            // DONE - Create a `double` variable to store the distance

            ITrackable tb1 = new TacoBell();
            ITrackable tb2 = new TacoBell();

            double distance1 = 0;

            // DONE - Include the Geolocation toolbox, so you can compare locations: `using GeoCoordinatePortable;`


            //HINT NESTED LOOPS SECTION---------------------
            // Do a loop for your locations to grab each location as the origin (perhaps: `locA`)

            // Create a new corA Coordinate with your locA's lat and long

            // Now, do another loop on the locations with the scope of your first loop, so you can grab the "destination" location (perhaps: `locB`)

            // Create a new Coordinate with your locB's lat and long

            // Now, compare the two using `.GetDistanceTo()`, which returns a double
            // If the distance is greater than the currently saved distance, update the distance and the two `ITrackable` variables you set above

            // Once you've looped through everything, you've found the two Taco Bells farthest away from each other.

            for (int i = 0; i < locations.Length; i++)
            {
                var           locA = locations[i];
                var           corA = locA.Location;
                GeoCoordinate loc1 = new GeoCoordinate(corA.Latitude, corA.Longitude);
                for (int j = 0; j < locations.Length; j++)
                {
                    var           locB     = locations[j];
                    var           corB     = locB.Location;
                    GeoCoordinate loc2     = new GeoCoordinate(corB.Latitude, corB.Longitude);
                    double        distance = loc2.GetDistanceTo(loc1);

                    if (distance1 < distance)
                    {
                        distance1 = distance;
                        tb1       = locA;
                        tb2       = locB;
                    }
                }
            }

            logger.LogInfo($"{tb1.Name} and {tb2.Name}");

            Console.WriteLine($"The distance between {tb1.Name} and {tb2.Name} is {distance1}");
        }
Пример #14
0
        static void Main(string[] args)
        {
            var path = Environment.CurrentDirectory + "\\Taco_Bell-US-AL-Alabama.csv";

            if (path.Length == 0)
            {
                Console.WriteLine("You must provide a filename as an argument");
                Logger.Fatal("Cannot import without filename specified as an argument");
                return;
            }

            Logger.Info("Log initialized");
            Logger.Info("Grabbing from your path: " + path);

            var lines = File.ReadAllLines(path);

            switch (lines.Length)
            {
            case 0:
                Logger.Error("No location to check. Must have at least one location.");
                break;

            case 1:
                Logger.Warn("only one location provided. Must have two to perform a check.");
                break;
            }

            var parser = new TacoParser();

            Logger.Debug("Initialized our parser");

            var locations = lines.Select(line => parser.Parse(line))
                            .OrderBy(loc => loc.Location.Longitude)
                            .ThenBy(loc => loc.Location.Latitude)
                            .ToArray();


            ITrackable a        = null;
            ITrackable b        = null;
            double     distance = 0;

            Console.WriteLine("Starting foreach on: " + locations.Length);

            foreach (var locA in locations)
            {
                Logger.Info("Compare all locations");
                var origin = new Coordinate
                {
                    Latitude  = locA.Location.Latitude,
                    Longitude = locA.Location.Longitude
                };
                foreach (var locB in locations)
                {
                    Logger.Debug("Checking origin against destination location");
                    var destination = new Coordinate
                    {
                        Latitude  = locB.Location.Latitude,
                        Longitude = locB.Location.Longitude
                    };

                    Logger.Info("getting distance in miles");
                    var nDistance = GeoCalculator.GetDistance(origin, destination);

                    if (!(nDistance > distance))
                    {
                        continue;
                    }
                    Logger.Info("found the next further apart");
                    a        = locA;
                    b        = locB;
                    distance = nDistance;
                }
            }
            if (a == null || b == null)
            {
                Logger.Error("failed to find the furthest locations");
                Console.WriteLine("Couldnt find the locations furthest apart");
                Console.ReadLine();
                return;
            }
            Console.WriteLine($"The two Taco Bells that are furthest apart are: {a.Name} and {b.Name} {distance} miles apart");
            Console.ReadLine();
        }
Пример #15
0
        static void Main(string[] args)
        {
            var path = Environment.CurrentDirectory + "\\Taco_Bell-US-AL-Alabama.csv";

            if (path.Length == 0)
            {
                Console.WriteLine("You must provide a filename as an argument");
                Logger.Fatal("Cannot import without filename specified as an argument");
                Console.ReadLine();
                return;
            }

            Logger.Info("Log initialized");
            Logger.Info("Grabbing from path:" + path);

            var lines = File.ReadAllLines(path);

            if (lines.Length == 0)
            {
                Logger.Error("No Locations to check. Must have at least one location.");
            }
            else if (lines.Length == 1)
            {
                Logger.Warn("Only one location provided. Must have two to perform a check.");
            }
            var parser = new TacoParser();

            Logger.Debug("Initialized our Parser");

            var locations = lines.Select(line => parser.Parse(line))
                            .OrderBy(loc => loc.Location.Longitude)
                            .ThenBy(loc => loc.Location.Latitude)
                            .ToArray();

            ITrackable a        = null;
            ITrackable b        = null;
            double     distance = 0;

            //TODO:  Find the two TacoBells in Alabama that are the furthurest from one another.

            foreach (var locA in locations)
            {
                var origin = new Coordinate {
                    Latitude = locA.Location.Latitude, Longitude = locA.Location.Longitude
                };

                foreach (var locB in locations)
                {
                    var destination = new Coordinate
                    {
                        Latitude  = locB.Location.Latitude,
                        Longitude = locB.Location.Latitude
                    };

                    var nDestination = GeoCalculator.GetDistance(origin, destination);

                    if (nDestination > distance)
                    {
                        a        = locA;
                        b        = locB;
                        distance = nDestination;
                    }
                }
            }
            Console.WriteLine($"The two TacoBells that are furthest aprt are:{a.Name} and:{b.Name}.");
            Console.WriteLine($"These two locations are:{distance} miles apart.");
        }