/// <summary> /// Calculate Estimate Measures from WeatherData List /// Prediction Weight: day -1 45%, day -2 30%, day -3 15%, day -4 7%, day -5 3%, /// We assume the same data for: /// - Solar Radiation /// - Wind Speed /// </summary> /// <param name="pLastDay"></param> /// <returns></returns> private WeatherData CalculateEstimateWeatherData(DateTime pLastDay) { #region local variables WeatherData lReturn = null; Double lTemperature; Double lSolarRadiation; Double lTemperatureMax; Double lTemperatureMaxLast5; Double lTemperatureMaxLast5Weight; Double lTemperatureMaxLast4; Double lTemperatureMaxLast4Weight; Double lTemperatureMaxLast3; Double lTemperatureMaxLast3Weight; Double lTemperatureMaxLast2; Double lTemperatureMaxLast2Weight; Double lTemperatureMaxLast1; Double lTemperatureMaxLast1Weight; Double lTemperatureMin; Double lTemperatureMinLast5; Double lTemperatureMinLast5Weight; Double lTemperatureMinLast4; Double lTemperatureMinLast4Weight; Double lTemperatureMinLast3; Double lTemperatureMinLast3Weight; Double lTemperatureMinLast2; Double lTemperatureMinLast2Weight; Double lTemperatureMinLast1; Double lTemperatureMinLast1Weight; Double lEvapotranspiration; Double lEvapotranspirationLast5; Double lEvapotranspirationLast5Weight; Double lEvapotranspirationLast4; Double lEvapotranspirationLast4Weight; Double lEvapotranspirationLast3; Double lEvapotranspirationLast3Weight; Double lEvapotranspirationLast2; Double lEvapotranspirationLast2Weight; Double lEvapotranspirationLast1; Double lEvapotranspirationLast1Weight; Double lWindSpeed; WeatherData lWeatherData = null; DateTime lLastDay = pLastDay; #endregion #region Prediction Weight lTemperatureMaxLast1Weight = 0.45; lTemperatureMaxLast2Weight = 0.30; lTemperatureMaxLast3Weight = 0.15; lTemperatureMaxLast4Weight = 0.07; lTemperatureMaxLast5Weight = 0.03; lTemperatureMinLast1Weight = 0.45; lTemperatureMinLast2Weight = 0.30; lTemperatureMinLast3Weight = 0.15; lTemperatureMinLast4Weight = 0.07; lTemperatureMinLast5Weight = 0.03; lEvapotranspirationLast1Weight = 0.45; lEvapotranspirationLast2Weight = 0.30; lEvapotranspirationLast3Weight = 0.15; lEvapotranspirationLast4Weight = 0.07; lEvapotranspirationLast5Weight = 0.03; #endregion //Find last WeatherData lWeatherData = this.FindWeatherData(lLastDay); if (lWeatherData != null) { lSolarRadiation = lWeatherData.SolarRadiation; lWindSpeed = lWeatherData.WindSpeed; #region Calculate Estimate Measures //Last Day information lTemperatureMaxLast1 = lWeatherData.TemperatureMax; lTemperatureMinLast1 = lWeatherData.TemperatureMin; lEvapotranspirationLast1 = lWeatherData.Evapotranspiration; #region 1 Day Before LastDay lWeatherData = this.FindWeatherData(pLastDay.AddDays(-1)); if (lWeatherData == null) { lTemperatureMaxLast2 = lTemperatureMaxLast1; lTemperatureMinLast2 = lTemperatureMinLast1; lEvapotranspirationLast2 = lEvapotranspirationLast1; } else { lTemperatureMaxLast2 = lWeatherData.TemperatureMax; lTemperatureMinLast2 = lWeatherData.TemperatureMin; lEvapotranspirationLast2 = lWeatherData.Evapotranspiration; } #endregion #region 2 Day Before LastDay lWeatherData = this.FindWeatherData(pLastDay.AddDays(-2)); if (lWeatherData == null) { lTemperatureMaxLast3 = lTemperatureMaxLast2; lTemperatureMinLast3 = lTemperatureMinLast2; lEvapotranspirationLast3 = lEvapotranspirationLast2; } else { lTemperatureMaxLast3 = lWeatherData.TemperatureMax; lTemperatureMinLast3 = lWeatherData.TemperatureMin; lEvapotranspirationLast3 = lWeatherData.Evapotranspiration; } #endregion #region 3 Day Before LastDay lWeatherData = this.FindWeatherData(pLastDay.AddDays(-3)); if (lWeatherData == null) { lTemperatureMaxLast4 = lTemperatureMaxLast3; lTemperatureMinLast4 = lTemperatureMinLast3; lEvapotranspirationLast4 = lEvapotranspirationLast3; } else { lTemperatureMaxLast4 = lWeatherData.TemperatureMax; lTemperatureMinLast4 = lWeatherData.TemperatureMin; lEvapotranspirationLast4 = lWeatherData.Evapotranspiration; } #endregion #region 4 Day Before LastDay lWeatherData = this.FindWeatherData(pLastDay.AddDays(-4)); if (lWeatherData == null) { lTemperatureMaxLast5 = lTemperatureMaxLast4; lTemperatureMinLast5 = lTemperatureMinLast4; lEvapotranspirationLast5 = lEvapotranspirationLast4; } else { lTemperatureMaxLast5 = lWeatherData.TemperatureMax; lTemperatureMinLast5 = lWeatherData.TemperatureMin; lEvapotranspirationLast5 = lWeatherData.Evapotranspiration; } #endregion lTemperatureMax = Math.Round( lTemperatureMaxLast5 * lTemperatureMaxLast5Weight + lTemperatureMaxLast4 * lTemperatureMaxLast4Weight + lTemperatureMaxLast3 * lTemperatureMaxLast3Weight + lTemperatureMaxLast2 * lTemperatureMaxLast2Weight + lTemperatureMaxLast1 * lTemperatureMaxLast1Weight, 2); lTemperatureMin = Math.Round( lTemperatureMinLast5 * lTemperatureMinLast5Weight + lTemperatureMinLast4 * lTemperatureMinLast4Weight + lTemperatureMinLast3 * lTemperatureMinLast3Weight + lTemperatureMinLast2 * lTemperatureMinLast2Weight + lTemperatureMinLast1 * lTemperatureMinLast1Weight, 2); lEvapotranspiration = Math.Round( lEvapotranspirationLast5 * lEvapotranspirationLast5Weight + lEvapotranspirationLast4 * lEvapotranspirationLast4Weight + lEvapotranspirationLast3 * lEvapotranspirationLast3Weight + lEvapotranspirationLast2 * lEvapotranspirationLast2Weight + lEvapotranspirationLast1 * lEvapotranspirationLast1Weight, 2); #endregion lTemperature = Utils.GetAverage(lTemperatureMax, lTemperatureMin); lWeatherData.Temperature = lTemperature; lWeatherData.TemperatureMax = lTemperatureMax; lWeatherData.TemperatureMin = lTemperatureMin; lWeatherData.Evapotranspiration = lEvapotranspiration; lWeatherData.SolarRadiation = lSolarRadiation; lWeatherData.WindSpeed = lWindSpeed; } lReturn = lWeatherData; return(lReturn); }