예제 #1
0
        public static CommuteQuality GetCommuteQualityRating(string startAddress, string destinationAddress, DateTime forecastTime)
        {
            GoogleMapsAPI googleMapsAPI = new GoogleMapsAPI(startAddress, destinationAddress);

            if (googleMapsAPI.GetPathDistance() > 100000) // > 100 km
            {
                Console.WriteLine("Distance between addresses is too long. Results may be inaccurate.");
            }
            double pathDirection = googleMapsAPI.GetPathDirection();
            WindForecastInstance windForecastInstance = WindForecastAPI.GetWindForecast(googleMapsAPI.GetMedianLatitude(), googleMapsAPI.GetMedianLongitude(), forecastTime);

            // Wind direction is the direction wind comes from, therefore before doing vector calculations it needs to be rotated 180 degrees.
            double forecastWindVectorDirection = TrigonometryUtility.RotateAngle180(windForecastInstance.WindDirectionDegrees);

            double windAngleDifference = TrigonometryUtility.GetDegreeBetweenVectors(pathDirection, forecastWindVectorDirection);
            double windHelpMagnitude   = TrigonometryUtility.DotProductWithUnitVector(windForecastInstance.windStrengthMps, windAngleDifference);

            CommuteQuality commuteQuality = new CommuteQuality();

            commuteQuality.Rating = new CommuteRating(CalculateHelpIndex(windHelpMagnitude));
            commuteQuality.windPositiveWorkPercentage = GetPositiveWindWorkPercentage(googleMapsAPI, forecastWindVectorDirection);

            return(commuteQuality);
        }
예제 #2
0
 static void Main(string[] args)
 {
     CommuteQuality commuteQuality = CommuteQualityCalculator.GetCommuteQualityRating("Richard Mortensens vej 54", "Frederiksberg", DateTime.Now.AddHours(6));
 }