コード例 #1
0
ファイル: Support.cs プロジェクト: papyr/taxify-challenge
 public static double clientDistance(Client client, DistCalc distCalc)
 {
     return(DistanceBetweenCoordinates(
                client.StartLatitude,
                client.StartLongitude,
                client.EndLatitude,
                client.EndLongitude,
                distCalc));
 }
コード例 #2
0
        public void Post([FromBody] FlightPlan value)
        {
            if (value == null)
            {
                return;
            }
            if (value.Company_name == null || value.Initial_location == null || value.Segments == null)
            {
                return;
            }
            Plane p  = new Plane(value, true, DistCalc.IdGenerator());
            var   ts = new List <Plane>();

            ts.Add(p);
            FlightsSQL.Instance.SaveInternalFlights(ts);
        }
コード例 #3
0
        public void Post([FromBody] FlightPlan value)
        {
            //convert flightPlans to Plane and put in list.
            if (value == null)
            {
                return;
            }
            if (value.Company_name == null || value.Initial_location == null || value.Segments == null)
            {
                return;
            }
            List <Plane> planes = new List <Plane>();
            var          id     = DistCalc.IdGenerator();
            var          p      = new Plane(value, false, id);

            planes.Add(p);
            FlightsSQL.Instance.SaveInternalFlights(planes);

            return;
        }
コード例 #4
0
ファイル: Support.cs プロジェクト: papyr/taxify-challenge
        public static double DistanceBetweenCoordinates(double lat1, double long1, double lat2, double long2, DistCalc distCalc)
        {
            if (distCalc == DistCalc.FAST)
            {
                int    earthRadius = 6371000;
                double lat1rad     = lat1.ToRadians();
                double lat2rad     = lat2.ToRadians();

                double x = (long2 - long1).ToRadians() * Math.Cos((lat1rad + lat2rad) / 2);
                double y = (lat2rad - lat1rad);

                return(Math.Sqrt(x * x + y * y) * earthRadius);
            }

            if (distCalc == DistCalc.ACCURATE)
            {
                GeoCoordinate start = new GeoCoordinate(lat1, long1);
                GeoCoordinate end   = new GeoCoordinate(lat2, long2);

                return(start.GetDistanceTo(end));
            }

            return(0);
        }
コード例 #5
0
ファイル: Support.cs プロジェクト: papyr/taxify-challenge
        public static void Test()
        {
            Stopwatch stopWatch = new Stopwatch();

            //Loading all clients to memory, downside - limited to RAM capacity

            stopWatch.Start();
            List <Client> clients = LoadClients();

            stopWatch.Stop();
            Console.WriteLine("It took {0} ms to read the file", stopWatch.ElapsedMilliseconds);

            stopWatch.Reset();

            //Measuring distances test
            Console.WriteLine("Starting distance measuring");

            stopWatch.Start();

            DistCalc method = DistCalc.FAST;

            List <double> distances = new List <double>();

            for (int i = 0; i < clients.Count; i++)
            {
                double distance = DistanceBetweenCoordinates(clients[i].StartLatitude, clients[i].StartLongitude, clients[i].EndLatitude, clients[i].EndLongitude, method);
                distances.Add(distance);
            }

            stopWatch.Stop();

            Console.WriteLine("It took {0} ms to calculate {1} distances using {2}", stopWatch.ElapsedMilliseconds, distances.Count, method);



            Console.WriteLine("Starting distance measuring");

            stopWatch.Start();

            int earthRadius = 6371000;

            for (int i = 0; i < 100; i++)
            {
                double startLatitudeRad = clients[i].StartLatitude.ToRadians();
                double startLongitude   = clients[i].StartLongitude;
                double endLatitudeRad   = clients[i].EndLatitude.ToRadians();
                double endLongitude     = clients[i].EndLongitude;

                double x = (endLongitude - startLongitude).ToRadians() * Math.Cos((startLatitudeRad + endLatitudeRad) / 2);
                double y = (endLatitudeRad - startLatitudeRad);

                double distance1 = Math.Sqrt(x * x + y * y) * earthRadius;

                GeoCoordinate start = new GeoCoordinate(clients[i].StartLatitude, clients[i].StartLongitude);
                GeoCoordinate end   = new GeoCoordinate(clients[i].EndLatitude, clients[i].EndLongitude);

                double distance2 = start.GetDistanceTo(end);

                Console.WriteLine("For client number {0} GeoCoordinate calculated {1} meters and mine calculated {2} meters", i, distance2, distance1);
            }

            stopWatch.Stop();



            Console.ReadLine();


            //Some testing calculations
            //1 - how many clients in each hour

            DateTime firstOrderTime = RoundToHour(clients[0].StartTime);

            //Hardcoded for 2 days (48 hours
            for (int i = 0; i < 48; i++)
            {
                DateTime counterStart = firstOrderTime.AddHours(i);
                DateTime counterEnd   = firstOrderTime.AddHours(i + 1);
                Console.WriteLine("Counting clients from {0} to {1}", counterStart.ToString(), counterEnd.ToString());

                int count = clients.FindAll(x => x.IsBetweenDates(counterStart, counterEnd)).Count;
                Console.WriteLine("The count is " + count);
            }



            Console.WriteLine("Hello world!");
            Console.ReadLine();
        }