diff --git a/FluentWeather.Abstraction/Models/HistoricalDailyWeatherBase.cs b/FluentWeather.Abstraction/Models/HistoricalDailyWeatherBase.cs index 4ccb347..98159f2 100644 --- a/FluentWeather.Abstraction/Models/HistoricalDailyWeatherBase.cs +++ b/FluentWeather.Abstraction/Models/HistoricalDailyWeatherBase.cs @@ -26,4 +26,7 @@ public class HistoricalDailyWeatherBase public DateTime? MaxPrecipitationDate { get; set; } public double? AveragePrecipitationHours { get; set; } + + public WindDirection WindDirection { get; set; } + public int AverageWindSpeed { get; set; } } \ No newline at end of file diff --git a/FluentWeather.OpenMeteoProvider/OpenMeteoProvider.cs b/FluentWeather.OpenMeteoProvider/OpenMeteoProvider.cs index f31e985..cfa1d0f 100644 --- a/FluentWeather.OpenMeteoProvider/OpenMeteoProvider.cs +++ b/FluentWeather.OpenMeteoProvider/OpenMeteoProvider.cs @@ -12,6 +12,7 @@ using OpenMeteoApi.Variables; using System; using System.Linq; +using FluentWeather.Abstraction.Helpers; namespace FluentWeather.OpenMeteoProvider; @@ -64,10 +65,10 @@ public async Task<PrecipitationBase> GetPrecipitations(double lon, double lat) public async Task<List<WeatherDailyBase>> GetHistoricalDailyWeather(double lon, double lat, DateTime startTime, DateTime endTime) { - var list = new List<WeatherDailyBase>(); var data = await Client.GetHistoricalWeatherData(lat, lon, startTime, endTime, - dailyVariables: [DailyVariables.WeatherCode,DailyVariables.Temperature2mMax,DailyVariables.Temperature2mMin,DailyVariables.PrecipitationSum,DailyVariables.PrecipitationHours] + dailyVariables: [DailyVariables.WeatherCode,DailyVariables.Temperature2mMax,DailyVariables.Temperature2mMin,DailyVariables.PrecipitationSum,DailyVariables.PrecipitationHours,DailyVariables.WindDirection10mDominant,DailyVariables.WindSpeed10mMax] ); + var list = new List<WeatherDailyBase>(data.DailyForecast!.Time!.Count()); for (var i = 0; i < data.DailyForecast!.Time!.Count(); i++) { var item = new WeatherDailyBase @@ -77,6 +78,8 @@ public async Task<List<WeatherDailyBase>> GetHistoricalDailyWeather(double lon, PrecipitationHours = data.DailyForecast.PrecipitationHours![i], MaxTemperature = (int)Math.Round(data.DailyForecast.Temperature2mMax![i]!.Value), MinTemperature = (int)Math.Round(data.DailyForecast.Temperature2mMin![i]!.Value), + WindDirection = UnitConverter.GetWindDirectionFromAngle(data.DailyForecast.WindDirection10mDominant![i]!.Value), + WindSpeed = (int)Math.Round(data.DailyForecast.WindSpeed10mMax![i]!.Value), }; list.Add(item); } diff --git a/FluentWeather.Uwp/Controls/Dialogs/HistoricalWeatherSetupDialog.xaml b/FluentWeather.Uwp/Controls/Dialogs/HistoricalWeatherSetupDialog.xaml index 4d54e52..d7dbd1e 100644 --- a/FluentWeather.Uwp/Controls/Dialogs/HistoricalWeatherSetupDialog.xaml +++ b/FluentWeather.Uwp/Controls/Dialogs/HistoricalWeatherSetupDialog.xaml @@ -10,7 +10,11 @@ RequestedTheme="{x:Bind app:Common.Settings.ApplicationTheme}" Style="{ThemeResource DefaultContentDialogStyle}" mc:Ignorable="d"> - <Grid Margin="-28"> + <ContentDialog.Resources> + <Thickness x:Key="ContentDialogPadding">0</Thickness> + <Thickness x:Key="ContentDialogSeparatorThickness">0</Thickness> + </ContentDialog.Resources> + <Grid> <Grid ColumnSpacing="8"> <Grid.ColumnDefinitions> <ColumnDefinition Width="160" /> @@ -31,12 +35,12 @@ Grid.Column="1" Padding="28,28,28,24" Spacing="12"> - <TextBlock Style="{ThemeResource TitleTextBlockStyle}" x:Uid="HistoricalWeatherTitle" /> + <TextBlock x:Uid="HistoricalWeatherTitle" Style="{ThemeResource TitleTextBlockStyle}" /> <TextBlock TextWrapping="Wrap"> - <Run x:Uid="HistoricalWeatherDescription"/> - <LineBreak /><Run Foreground="{ThemeResource SystemControlForegroundBaseMediumBrush}" x:Uid="HistoricalWeatherSource" /><LineBreak /> - Open-Meteo(ERA5 / ECMWF IFS)<LineBreak /><Run Foreground="{ThemeResource SystemControlForegroundBaseMediumBrush}" x:Uid="HistoricalWeatherFeature" /> - <LineBreak /><Run x:Uid="HistoricalWeatherFeatureDescription"/> + <Run x:Uid="HistoricalWeatherDescription" /> + <LineBreak /><Run x:Uid="HistoricalWeatherSource" Foreground="{ThemeResource SystemControlForegroundBaseMediumBrush}" /><LineBreak /> + Open-Meteo(ERA5 / ECMWF IFS)<LineBreak /><Run x:Uid="HistoricalWeatherFeature" Foreground="{ThemeResource SystemControlForegroundBaseMediumBrush}" /> + <LineBreak /><Run x:Uid="HistoricalWeatherFeatureDescription" /> </TextBlock> <muxc:InfoBar x:Name="WarningInfoBar" @@ -70,10 +74,10 @@ Style="{ThemeResource AccentButtonStyle}" /> <Button x:Name="RestartButton" - Click="RestartButton_Click" + x:Uid="RestartButton" Margin="12,0,0,0" Padding="36,6" - x:Uid="RestartButton" + Click="RestartButton_Click" Style="{ThemeResource AccentButtonStyle}" Visibility="Collapsed" /> </StackPanel> diff --git a/FluentWeather.Uwp/Helpers/HistoricalWeatherHelper.cs b/FluentWeather.Uwp/Helpers/HistoricalWeatherHelper.cs index b8d5f65..c192e14 100644 --- a/FluentWeather.Uwp/Helpers/HistoricalWeatherHelper.cs +++ b/FluentWeather.Uwp/Helpers/HistoricalWeatherHelper.cs @@ -65,12 +65,13 @@ public static async Task<Dictionary<string, HistoricalDailyWeatherBase>> Analyse double? totalPrecip = 0.0; double? maxPrecip = 0.0; DateTime? maxPrecipDate = DateTime.MinValue; - - + + var totalWindSpeed = 0; var totalMaxTemp = 0; var totalMinTemp = 0; double? totalPrecipHours = 0.0; var weatherCodeDic = new Dictionary<WeatherCode, int>(); + var windDirectionDic = new Dictionary<WindDirection, int>(); var count = 0; foreach (var item in pair.Value) { @@ -89,6 +90,9 @@ public static async Task<Dictionary<string, HistoricalDailyWeatherBase>> Analyse maxPrecip = item.Precipitation; maxPrecipDate = item.Time; } + totalWindSpeed += item.WindSpeed; + windDirectionDic[item.WindDirection] = windDirectionDic.GetOrCreate(item.WindDirection) + 1; + totalMaxTemp += item.MaxTemperature; totalMinTemp += item.MinTemperature; totalPrecipHours += item.PrecipitationHours; @@ -99,6 +103,8 @@ public static async Task<Dictionary<string, HistoricalDailyWeatherBase>> Analyse var historicalWeather = new HistoricalDailyWeatherBase { Date = pair.Value.First.Value.Time.Date, + WindDirection = windDirectionDic.OrderBy(p => p.Value).First().Key, + AverageWindSpeed = totalWindSpeed / count, AverageMaxTemperature = totalMaxTemp / count, AverageMinTemperature = totalMinTemp / count, MaxPrecipitation = maxPrecip, @@ -109,7 +115,7 @@ public static async Task<Dictionary<string, HistoricalDailyWeatherBase>> Analyse HistoricalMaxTemperatureDate = maxTempDate, HistoricalMinTemperature = minTemp, HistoricalMinTemperatureDate = minTempDate, - Weather = weatherCodeDic.Max(p => p).Key + Weather = weatherCodeDic.OrderBy(p => p.Value).First().Key, }; result[pair.Key] = historicalWeather; }