private static Weather CreateDayWeather(Airport airport, DateTime date, Weather previousWeather)
        {
            WeatherAverage average = WeatherAverages.GetWeatherAverage(date.Month, airport);

            if (average != null)
            {
                return CreateDayWeather(date, previousWeather, average);
            }

            var precipitationValues = (Weather.Precipitation[]) Enum.GetValues(typeof (Weather.Precipitation));
            var coverValues = (Weather.CloudCover[]) Enum.GetValues(typeof (Weather.CloudCover));
            var windDirectionValues = (Weather.WindDirection[]) Enum.GetValues(typeof (Weather.WindDirection));
            var windSpeedValues = (Weather.eWindSpeed[]) Enum.GetValues(typeof (Weather.eWindSpeed));
            Weather.eWindSpeed windSpeed;
            double temperature;

            Weather.WindDirection windDirection = windDirectionValues[Rnd.Next(windDirectionValues.Length)];

            if (previousWeather == null)
            {
                windSpeed = windSpeedValues[Rnd.Next(windSpeedValues.Length)];

                const double maxTemp = 40;
                const double minTemp = -20;

                temperature = MathHelpers.GetRandomDoubleNumber(minTemp, maxTemp);
            }
            else
            {
                int windIndex = windSpeedValues.ToList().IndexOf(previousWeather.WindSpeed);
                windSpeed =
                    windSpeedValues[
                        Rnd.Next(Math.Max(0, windIndex - 2), Math.Min(windIndex + 2, windSpeedValues.Length))];

                double previousTemperature = (previousWeather.TemperatureHigh + previousWeather.TemperatureLow)/2;

                double maxTemp = Math.Min(40, previousTemperature + 5);
                double minTemp = Math.Max(-20, previousTemperature - 5);

                temperature = MathHelpers.GetRandomDoubleNumber(minTemp, maxTemp);
            }

            double temperatureLow = temperature - Rnd.Next(1, 10);
            double temperatureHigh = temperature + Rnd.Next(1, 10);

            double tempDiff = temperatureHigh - temperatureLow;
            double temperatureSunrise = temperatureLow + MathHelpers.GetRandomDoubleNumber(-2, Math.Min(tempDiff, 2));
            double temperatureSunset = temperatureHigh - MathHelpers.GetRandomDoubleNumber(-2, Math.Min(tempDiff, 2));
            double temperatureDayend = temperatureLow + Rnd.Next(-2, 2);

            Weather.CloudCover cover = coverValues[Rnd.Next(coverValues.Length)];
            Weather.Precipitation precip;
            if (cover == Weather.CloudCover.Overcast)
            {
                precip = precipitationValues[Rnd.Next(precipitationValues.Length)];
            }

            var hourlyTemperature = new HourlyWeather[24];

            if (previousWeather == null)
            {
                hourlyTemperature[0] = new HourlyWeather(
                    temperatureLow,
                    cover,
                    cover == Weather.CloudCover.Overcast ? GetPrecipitation(temperatureLow) : Weather.Precipitation.None,
                    windSpeed,
                    windDirection);
            }
            else
            {
                hourlyTemperature[0] = previousWeather.Temperatures[previousWeather.Temperatures.Length - 1];
            }

            double morningSteps = (temperatureSunrise - hourlyTemperature[0].Temperature)/(Weather.Sunrise - 1);

            for (int i = 1; i <= Weather.Sunrise; i++)
            {
                double temp = hourlyTemperature[i - 1].Temperature + morningSteps;
                Weather.CloudCover hourlyCover = Rnd.Next(3) == 0 ? coverValues[Rnd.Next(coverValues.Length)] : cover;

                int windspeedIndex = windSpeedValues.ToList().IndexOf(windSpeed);
                Weather.eWindSpeed[] hourlyWindspeedValues =
                    {
                        windSpeed, windSpeed, windSpeed,
                        hourlyTemperature[i - 1].WindSpeed,
                        windspeedIndex > 0
                            ? (Weather.eWindSpeed) windspeedIndex - 1
                            : (Weather.eWindSpeed) windspeedIndex + 1,
                        windspeedIndex < windSpeedValues.Length - 1
                            ? (Weather.eWindSpeed) windspeedIndex + 1
                            : (Weather.eWindSpeed) windspeedIndex - 1
                    };
                Weather.eWindSpeed hourlyWindspeed = hourlyWindspeedValues[Rnd.Next(hourlyWindspeedValues.Length)];

                hourlyTemperature[i] = new HourlyWeather(
                    temp,
                    hourlyCover,
                    hourlyCover == Weather.CloudCover.Overcast ? GetPrecipitation(temp) : Weather.Precipitation.None,
                    hourlyWindspeed,
                    windDirection);
            }

            double daySteps = (temperatureSunset - temperatureSunrise)/(Weather.Sunset - Weather.Sunrise - 1);

            for (int i = Weather.Sunrise + 1; i < Weather.Sunset; i++)
            {
                Weather.CloudCover hourlyCover = Rnd.Next(3) == 0 ? coverValues[Rnd.Next(coverValues.Length)] : cover;

                double temp = hourlyTemperature[i - 1].Temperature + daySteps;
                if (hourlyCover != hourlyTemperature[i - 1].Cover && hourlyCover == Weather.CloudCover.Overcast)
                {
                    temp -= MathHelpers.GetRandomDoubleNumber(1, 4);
                }
                if (hourlyCover != hourlyTemperature[i - 1].Cover
                    && hourlyTemperature[i - 1].Cover == Weather.CloudCover.Overcast)
                {
                    temp += MathHelpers.GetRandomDoubleNumber(1, 4);
                }

                int windspeedIndex = windSpeedValues.ToList().IndexOf(windSpeed);
                Weather.eWindSpeed[] hourlyWindspeedValues =
                    {
                        windSpeed, windSpeed, windSpeed,
                        hourlyTemperature[i - 1].WindSpeed,
                        windspeedIndex > 0
                            ? (Weather.eWindSpeed) windspeedIndex - 1
                            : (Weather.eWindSpeed) windspeedIndex + 1,
                        windspeedIndex < windSpeedValues.Length - 1
                            ? (Weather.eWindSpeed) windspeedIndex + 1
                            : (Weather.eWindSpeed) windspeedIndex - 1
                    };
                Weather.eWindSpeed hourlyWindspeed = hourlyWindspeedValues[Rnd.Next(hourlyWindspeedValues.Length)];

                hourlyTemperature[i] = new HourlyWeather(
                    temp,
                    hourlyCover,
                    hourlyCover == Weather.CloudCover.Overcast ? GetPrecipitation(temp) : Weather.Precipitation.None,
                    hourlyWindspeed,
                    windDirection);
            }

            double eveningSteps = (temperatureDayend - temperatureSunset)/(hourlyTemperature.Length - Weather.Sunset);

            for (int i = Weather.Sunset; i < hourlyTemperature.Length; i++)
            {
                double temp = hourlyTemperature[i - 1].Temperature + eveningSteps;
                Weather.CloudCover hourlyCover = Rnd.Next(3) == 0 ? coverValues[Rnd.Next(coverValues.Length)] : cover;

                int windspeedIndex = windSpeedValues.ToList().IndexOf(windSpeed);
                Weather.eWindSpeed[] hourlyWindspeedValues =
                    {
                        windSpeed, windSpeed, windSpeed,
                        hourlyTemperature[i - 1].WindSpeed,
                        windspeedIndex > 0
                            ? (Weather.eWindSpeed) windspeedIndex - 1
                            : (Weather.eWindSpeed) windspeedIndex + 1,
                        windspeedIndex < windSpeedValues.Length - 1
                            ? (Weather.eWindSpeed) windspeedIndex + 1
                            : (Weather.eWindSpeed) windspeedIndex - 1
                    };
                Weather.eWindSpeed hourlyWindspeed = hourlyWindspeedValues[Rnd.Next(hourlyWindspeedValues.Length)];

                hourlyTemperature[i] = new HourlyWeather(
                    temp,
                    hourlyCover,
                    hourlyCover == Weather.CloudCover.Overcast ? GetPrecipitation(temp) : Weather.Precipitation.None,
                    hourlyWindspeed,
                    windDirection);
            }

            temperatureLow = hourlyTemperature.Min(t => t.Temperature);
            temperatureHigh = hourlyTemperature.Max(t => t.Temperature);
            cover =
                (from c in hourlyTemperature group c by c.Cover into g select new {Cover = g.Key, Qty = g.Count()})
                    .OrderByDescending(g => g.Qty).First().Cover;
            precip =
                (from c in hourlyTemperature group c by c.Precip into g select new {Precip = g.Key, Qty = g.Count()})
                    .OrderByDescending(g => g.Qty).First().Precip;

            var weather = new Weather(
                date,
                windSpeed,
                windDirection,
                cover,
                precip,
                hourlyTemperature,
                temperatureLow,
                temperatureHigh);

            return weather;
        }
        //creates the weather from an average
        private static Weather CreateDayWeather(DateTime date, Weather previousWeather, WeatherAverage average)
        {
            var windDirectionValues = (Weather.WindDirection[]) Enum.GetValues(typeof (Weather.WindDirection));
            var windSpeedValues = (Weather.eWindSpeed[]) Enum.GetValues(typeof (Weather.eWindSpeed));
            var coverValues = (Weather.CloudCover[]) Enum.GetValues(typeof (Weather.CloudCover));

            Weather.WindDirection windDirection = windDirectionValues[Rnd.Next(windDirectionValues.Length)];
            Weather.CloudCover cover;
            Weather.Precipitation precip;
            Weather.eWindSpeed windSpeed;
            double temperatureLow,
                   temperatureHigh;

            int windIndexMin = windSpeedValues.ToList().IndexOf(average.WindSpeedMin);
            int windIndexMax = windSpeedValues.ToList().IndexOf(average.WindSpeedMax);

            if (previousWeather == null)
            {
                windSpeed = windSpeedValues[Rnd.Next(windIndexMin, windIndexMax)];

                temperatureLow = MathHelpers.GetRandomDoubleNumber(
                    average.TemperatureMin - 5,
                    average.TemperatureMin + 5);
                temperatureHigh =
                    MathHelpers.GetRandomDoubleNumber(
                        Math.Max(average.TemperatureMax - 5, temperatureLow + 1),
                        average.TemperatureMax + 5);
            }
            else
            {
                double previousTemperature = (previousWeather.TemperatureHigh + previousWeather.TemperatureLow)/2;
                int windIndex = windSpeedValues.ToList().IndexOf(previousWeather.WindSpeed);
                windSpeed =
                    windSpeedValues[
                        Rnd.Next(Math.Max(windIndexMin, windIndex - 2), Math.Min(windIndex + 2, windIndexMax))];

                double minTemp = Math.Max(average.TemperatureMin, previousTemperature - 5);
                temperatureLow = MathHelpers.GetRandomDoubleNumber(minTemp - 5, minTemp + 5);

                double maxTemp = Math.Min(average.TemperatureMax, previousTemperature + 5);

                temperatureHigh = MathHelpers.GetRandomDoubleNumber(Math.Max(maxTemp - 5, temperatureLow), maxTemp + 5);
                //rnd.NextDouble() * ((maxTemp + 5) - Math.Max(maxTemp - 5, temperatureLow + 2)) + Math.Max(maxTemp - 5, temperatureLow + 2);
            }

            double tempDiff = temperatureHigh - temperatureLow;
            double temperatureSunrise = temperatureLow + MathHelpers.GetRandomDoubleNumber(-2, Math.Min(tempDiff, 2));
            double temperatureSunset = temperatureHigh - MathHelpers.GetRandomDoubleNumber(-2, Math.Min(tempDiff, 2));
            double temperatureDayend = temperatureLow + Rnd.Next(-2, 2);

            double temperature = (temperatureLow + temperatureHigh)/2;

            bool isOvercast = Rnd.Next(100) < average.Precipitation;
            if (isOvercast)
            {
                cover = Weather.CloudCover.Overcast;
                precip = GetPrecipitation(temperature);
            }
            else
            {
                Weather.CloudCover[] notOvercastCovers =
                    {
                        Weather.CloudCover.Clear, Weather.CloudCover.MostlyCloudy,
                        Weather.CloudCover.PartlyCloudy
                    };
                cover = notOvercastCovers[Rnd.Next(notOvercastCovers.Length)];
            }

            var hourlyTemperature = new HourlyWeather[24];

            if (previousWeather == null)
            {
                hourlyTemperature[0] = new HourlyWeather(
                    temperatureLow,
                    cover,
                    cover == Weather.CloudCover.Overcast ? GetPrecipitation(temperatureLow) : Weather.Precipitation.None,
                    windSpeed,
                    windDirection);
            }
            else
            {
                hourlyTemperature[0] = previousWeather.Temperatures[previousWeather.Temperatures.Length - 1];
            }

            double morningSteps = (temperatureSunrise - hourlyTemperature[0].Temperature)/(Weather.Sunrise - 1);

            for (int i = 1; i <= Weather.Sunrise; i++)
            {
                double temp = hourlyTemperature[i - 1].Temperature + morningSteps;
                Weather.CloudCover hourlyCover = Rnd.Next(3) == 0 ? coverValues[Rnd.Next(coverValues.Length)] : cover;

                int windspeedIndex = windSpeedValues.ToList().IndexOf(windSpeed);
                Weather.eWindSpeed[] hourlyWindspeedValues =
                    {
                        windSpeed, windSpeed, windSpeed,
                        hourlyTemperature[i - 1].WindSpeed,
                        windspeedIndex > 0
                            ? (Weather.eWindSpeed) windspeedIndex - 1
                            : (Weather.eWindSpeed) windspeedIndex + 1,
                        windspeedIndex < windSpeedValues.Length - 1
                            ? (Weather.eWindSpeed) windspeedIndex + 1
                            : (Weather.eWindSpeed) windspeedIndex - 1
                    };
                Weather.eWindSpeed hourlyWindspeed = hourlyWindspeedValues[Rnd.Next(hourlyWindspeedValues.Length)];

                hourlyTemperature[i] = new HourlyWeather(
                    temp,
                    hourlyCover,
                    hourlyCover == Weather.CloudCover.Overcast ? GetPrecipitation(temp) : Weather.Precipitation.None,
                    hourlyWindspeed,
                    windDirection);
            }

            double daySteps = (temperatureSunset - temperatureSunrise)/(Weather.Sunset - Weather.Sunrise - 1);

            for (int i = Weather.Sunrise + 1; i < Weather.Sunset; i++)
            {
                Weather.CloudCover hourlyCover = Rnd.Next(3) == 0 ? coverValues[Rnd.Next(coverValues.Length)] : cover;

                double temp = hourlyTemperature[i - 1].Temperature + daySteps;
                if (hourlyCover != hourlyTemperature[i - 1].Cover && hourlyCover == Weather.CloudCover.Overcast)
                {
                    temp -= MathHelpers.GetRandomDoubleNumber(1, 4);
                }
                if (hourlyCover != hourlyTemperature[i - 1].Cover
                    && hourlyTemperature[i - 1].Cover == Weather.CloudCover.Overcast)
                {
                    temp += MathHelpers.GetRandomDoubleNumber(1, 4);
                }

                int windspeedIndex = windSpeedValues.ToList().IndexOf(windSpeed);
                Weather.eWindSpeed[] hourlyWindspeedValues =
                    {
                        windSpeed, windSpeed, windSpeed,
                        hourlyTemperature[i - 1].WindSpeed,
                        windspeedIndex > 0
                            ? (Weather.eWindSpeed) windspeedIndex - 1
                            : (Weather.eWindSpeed) windspeedIndex + 1,
                        windspeedIndex < windSpeedValues.Length - 1
                            ? (Weather.eWindSpeed) windspeedIndex + 1
                            : (Weather.eWindSpeed) windspeedIndex - 1
                    };
                Weather.eWindSpeed hourlyWindspeed = hourlyWindspeedValues[Rnd.Next(hourlyWindspeedValues.Length)];

                hourlyTemperature[i] = new HourlyWeather(
                    temp,
                    hourlyCover,
                    hourlyCover == Weather.CloudCover.Overcast ? GetPrecipitation(temp) : Weather.Precipitation.None,
                    hourlyWindspeed,
                    windDirection);
            }

            double eveningSteps = (temperatureDayend - temperatureSunset)/(hourlyTemperature.Length - Weather.Sunset);

            for (int i = Weather.Sunset; i < hourlyTemperature.Length; i++)
            {
                double temp = hourlyTemperature[i - 1].Temperature + eveningSteps;
                Weather.CloudCover hourlyCover = Rnd.Next(3) == 0 ? coverValues[Rnd.Next(coverValues.Length)] : cover;

                int windspeedIndex = windSpeedValues.ToList().IndexOf(windSpeed);
                Weather.eWindSpeed[] hourlyWindspeedValues =
                    {
                        windSpeed, windSpeed, windSpeed,
                        hourlyTemperature[i - 1].WindSpeed,
                        windspeedIndex > 0
                            ? (Weather.eWindSpeed) windspeedIndex - 1
                            : (Weather.eWindSpeed) windspeedIndex + 1,
                        windspeedIndex < windSpeedValues.Length - 1
                            ? (Weather.eWindSpeed) windspeedIndex + 1
                            : (Weather.eWindSpeed) windspeedIndex - 1
                    };
                Weather.eWindSpeed hourlyWindspeed = hourlyWindspeedValues[Rnd.Next(hourlyWindspeedValues.Length)];

                hourlyTemperature[i] = new HourlyWeather(
                    temp,
                    hourlyCover,
                    hourlyCover == Weather.CloudCover.Overcast ? GetPrecipitation(temp) : Weather.Precipitation.None,
                    hourlyWindspeed,
                    windDirection);
            }
            temperatureLow = hourlyTemperature.Min(t => t.Temperature);
            temperatureHigh = hourlyTemperature.Max(t => t.Temperature);

            cover =
                (from c in hourlyTemperature group c by c.Cover into g select new {Cover = g.Key, Qty = g.Count()})
                    .OrderByDescending(g => g.Qty).First().Cover;
            precip =
                (from c in hourlyTemperature group c by c.Precip into g select new {Precip = g.Key, Qty = g.Count()})
                    .OrderByDescending(g => g.Qty).First().Precip;

            var weather = new Weather(
                date,
                windSpeed,
                windDirection,
                cover,
                precip,
                hourlyTemperature,
                temperatureLow,
                temperatureHigh);

            return weather;
        }