Skip to content

Commit

Permalink
[feat] 历史风速/风向
Browse files Browse the repository at this point in the history
  • Loading branch information
zxbmmmmmmmmm committed Jun 15, 2024
1 parent fe0822f commit f7d016b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
7 changes: 5 additions & 2 deletions FluentWeather.OpenMeteoProvider/OpenMeteoProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using OpenMeteoApi.Variables;
using System;
using System.Linq;
using FluentWeather.Abstraction.Helpers;

namespace FluentWeather.OpenMeteoProvider;

Expand Down Expand Up @@ -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
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand All @@ -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"
Expand Down Expand Up @@ -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>
Expand Down
12 changes: 9 additions & 3 deletions FluentWeather.Uwp/Helpers/HistoricalWeatherHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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;
Expand All @@ -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,
Expand All @@ -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;
}
Expand Down

0 comments on commit f7d016b

Please sign in to comment.