Skip to content

Commit

Permalink
Merge pull request #45 from zxbmmmmmmmmm/feat/open-meteo/minutely-for…
Browse files Browse the repository at this point in the history
…ecast

Feat/open meteo/minutely forecast
  • Loading branch information
zxbmmmmmmmmm authored Apr 13, 2024
2 parents 3d82d29 + 01d3d44 commit 9df07eb
Show file tree
Hide file tree
Showing 24 changed files with 456 additions and 166 deletions.
6 changes: 6 additions & 0 deletions FluentWeather.Abstraction/Models/PrecipitationBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,11 @@ public class PrecipitationItemBase
public double Precipitation { get; set; }
public DateTime Time { get; set; }
public bool IsSnow { get; set; }
public PrecipitationItemBase(DateTime time,double precipitation,bool isSnow=false)
{
Precipitation = precipitation;
Time = time;
IsSnow = isSnow;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="OpenMeteoApi" Version="1.0.0" />
<PackageReference Include="OpenMeteoApi" Version="1.1.0" />
<PackageReference Include="PolySharp" Version="1.14.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
19 changes: 17 additions & 2 deletions FluentWeather.OpenMeteoProvider/OpenMeteoProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,21 @@
using System.Collections.Generic;
using FluentWeather.OpenMeteoProvider.Models;
using OpenMeteoApi.Variables;
using System;

namespace FluentWeather.OpenMeteoProvider;

public sealed class OpenMeteoProvider : ProviderBase, ICurrentWeatherProvider, IAirConditionProvider, IDailyForecastProvider, IHourlyForecastProvider
public sealed class OpenMeteoProvider : ProviderBase, ICurrentWeatherProvider, IAirConditionProvider, IDailyForecastProvider, IHourlyForecastProvider , IPrecipitationProvider
{
public override string Name => "OpenMeteo";
public override string Id => "open-meteo";

public static readonly OpenMeteoClient Client = new();
public static OpenMeteoClient Client { get; }
static OpenMeteoProvider()
{
Client = new();
Client.ForecastParameters.Add("forecast_minutely_15", "8");
}
public async Task<WeatherNowBase> GetCurrentWeather(double lon, double lat)
{
var result = await Client.GetWeatherForecastData(lat, lon, currentVariables: CurrentVariables.All, hourlyVariables:new[]{ HourlyVariables.Visibility, "dew_point_2m" });
Expand All @@ -45,4 +51,13 @@ public async Task<List<WeatherHourlyBase>> GetHourlyForecasts(double lon, double
return result.ConvertAll<WeatherHourlyBase>(p => p.MapToOpenMeteoHourlyForecast());
}

public async Task<PrecipitationBase> GetPrecipitations(double lon, double lat)
{
var result = await Client.GetMinutelyForecasts(lat, lon);
var precip = new PrecipitationBase
{
Precipitations = result.ConvertAll(p => new PrecipitationItemBase(DateTime.Parse(p.Time),p.Precipitation!.Value)),
};
return precip;
}
}
4 changes: 4 additions & 0 deletions FluentWeather.Tasks/FluentWeather.Tasks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@
<Project>{15e289d2-4104-4889-b968-60d2c2efd806}</Project>
<Name>FluentWeather.DIContainer</Name>
</ProjectReference>
<ProjectReference Include="..\FluentWeather.OpenMeteoProvider\FluentWeather.OpenMeteoProvider.csproj">
<Project>{839ccc2a-1f6d-4965-bcd3-8efc98dd84aa}</Project>
<Name>FluentWeather.OpenMeteoProvider</Name>
</ProjectReference>
<ProjectReference Include="..\FluentWeather.Uwp.QWeatherProvider\FluentWeather.Uwp.QWeatherProvider.csproj">
<Project>{47F2B7FC-1B81-4D69-B5BA-D1160532ED63}</Project>
<Name>FluentWeather.Uwp.QWeatherProvider</Name>
Expand Down
26 changes: 21 additions & 5 deletions FluentWeather.Tasks/NotifyTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,34 @@
using static FluentWeather.Uwp.Shared.Common;
using System.Text.RegularExpressions;
using FluentWeather.Uwp.QWeatherProvider;
using FluentWeather.Abstraction;
using FluentWeather.OpenMeteoProvider;
using FluentWeather.Abstraction.Interfaces.WeatherProvider;

namespace FluentWeather.Tasks
{
public sealed class NotifyTask :IBackgroundTask
{
private IWeatherWarningProvider _warningProvider;
private IDailyForecastProvider _dailyForecastProvider;

public async void Run(IBackgroundTaskInstance taskInstance)
{
BackgroundTaskDeferral deferral = taskInstance.GetDeferral();

LogManager.GetLogger(nameof(NotifyTask)).Info("NotifyTask Started");

var provider = new QWeatherProvider(Settings.QWeatherToken,Settings.QWeatherDomain,null,Settings.QWeatherPublicId);
if(Settings.ProviderConfig is Uwp.Shared.ProviderConfig.QWeather)
{
var provider = new QWeatherProvider(Settings.QWeatherToken, Settings.QWeatherDomain, null, Settings.QWeatherPublicId);
_warningProvider = provider;
_dailyForecastProvider = provider;
}
else
{
var provider = new OpenMeteoProvider.OpenMeteoProvider();
_dailyForecastProvider = provider;
}
var lat = Settings.Latitude;
var lon = Settings.Longitude;
if(lat is -1 || lon is -1)
Expand All @@ -40,11 +56,11 @@ public async void Run(IBackgroundTaskInstance taskInstance)
}
private async Task PushWarnings(double lon, double lat)
{
if (_warningProvider is null) return;
var settingContainer = ApplicationData.Current.LocalSettings;
var isWarningNotificationEnabled = Settings.IsWarningNotificationEnabled;
if (!isWarningNotificationEnabled) return;

var warnings = await QWeatherProvider.Instance.GetWeatherWarnings(lon, lat);
var warnings = await _warningProvider.GetWeatherWarnings(lon, lat);
settingContainer.Values["PushedWarnings"] ??= JsonSerializer.Serialize(new Dictionary<string,DateTime>());
var pushed = JsonSerializer.Deserialize<Dictionary<string, DateTime>>((string)settingContainer.Values["PushedWarnings"]);
foreach (var warning in warnings)
Expand All @@ -62,12 +78,12 @@ private async Task PushWarnings(double lon, double lat)
}
private async Task PushDaily(double lon, double lat)
{
if (_dailyForecastProvider is null) return;
var isPushTodayAvailable = Settings.IsDailyNotificationEnabled && Settings.LastPushedTime != DateTime.Now.Date.DayOfYear;
var isPushTomorrowAvailable = Settings.IsTomorrowNotificationEnabled && Settings.LastPushedTimeTomorrow != DateTime.Now.Date.DayOfYear;
var isTileAvailable = Settings.IsDailyNotificationTileEnabled && Settings.LastPushedTime != DateTime.Now.Date.DayOfYear;
if (!isPushTodayAvailable && !isPushTomorrowAvailable && !isTileAvailable) return;

var data = await QWeatherProvider.Instance.GetDailyForecasts(lon, lat);
var data = await _dailyForecastProvider.GetDailyForecasts(lon, lat);
if (isTileAvailable)
{
UpdateTiles(data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@
<SubType>Designer</SubType>
</Page>
</ItemGroup>
<ItemGroup>
<PRIResource Include="Strings\zh-CN\Resources.resw" />
</ItemGroup>
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '14.0' ">
<VisualStudioVersion>14.0</VisualStudioVersion>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,14 @@ public static class PrecipitationMapper
{
public static PrecipitationItemBase MapToPrecipitationItemBase(this PrecipitationResponse.PrecipitationItem item)
{
return new PrecipitationItemBase
{
Precipitation = item.Precip,
Time = item.FxTime,
IsSnow = item.Type is "snow"
};
return new PrecipitationItemBase(item.FxTime, item.Precip, item.Type is "snow");
}
public static PrecipitationBase MapToPrecipitationBase(this PrecipitationResponse item)
{
return new PrecipitationBase
{
Summary = item.Summary,
Precipitations = item.MinutelyPrecipitations?.ConvertAll(p => (PrecipitationItemBase)p.MapToPrecipitationItemBase()),
Precipitations = item.MinutelyPrecipitations?.ConvertAll(p => p.MapToPrecipitationItemBase()),
};
}
}
Expand Down
135 changes: 135 additions & 0 deletions FluentWeather.Uwp.QWeatherProvider/Strings/zh-CN/Resources.resw
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="CancelButton.Content" xml:space="preserve">
<value>取消</value>
</data>
<data name="ConfirmAndRestartButton.Content" xml:space="preserve">
<value>确定并重启应用</value>
</data>
<data name="GetFreeKeyHyperlink.Content" xml:space="preserve">
<value>获取免费KEY</value>
</data>
<data name="PublicIdBox.PlaceholderText" xml:space="preserve">
<value>Public ID (可选)</value>
</data>
<data name="SetTokenDialog.Title" xml:space="preserve">
<value>设置KEY</value>
</data>
</root>
54 changes: 41 additions & 13 deletions FluentWeather.Uwp.QWeatherProvider/Views/SetTokenDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,53 @@
x:Class="FluentWeather.Uwp.QWeatherProvider.Views.SetTokenDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:FluentWeather.Uwp.QWeatherProvider"
xmlns:app="using:FluentWeather.Uwp.Shared"
xmlns:core="using:Microsoft.Xaml.Interactions.Core"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:i="using:Microsoft.Xaml.Interactivity"
xmlns:core="using:Microsoft.Xaml.Interactions.Core"
xmlns:local="using:FluentWeather.Uwp.QWeatherProvider"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
xmlns:app="using:FluentWeather.Uwp.Shared"
Style="{ThemeResource DefaultContentDialogStyle}"
x:Uid="SetTokenDialog"
RequestedTheme="{x:Bind app:Common.Settings.ApplicationTheme}"
mc:Ignorable="d"
Title="设置KEY">
Style="{ThemeResource DefaultContentDialogStyle}"
mc:Ignorable="d">
<Grid>
<StackPanel>
<TextBlock Visibility="Collapsed" x:Name="ErrorTextblock" Margin="0,0,0,12"/>
<AutoSuggestBox x:Name="KeyBox" Text="{x:Bind Key,Mode=TwoWay}" PlaceholderText="KEY" QueryIcon="Paste" QuerySubmitted="KeyBox_QuerySubmitted"/>
<AutoSuggestBox Margin="0,12,0,0" x:Name="PublicIdBox" Text="{x:Bind PublicId,Mode=TwoWay}" PlaceholderText="Public ID (可选)" QueryIcon="Paste" QuerySubmitted="PublicIdBox_QuerySubmitted"/>
<StackPanel Margin="0,12,0,0" Orientation="Horizontal" Spacing="12">
<Button Command="{x:Bind ConfirmCommand}" HorizontalAlignment="Right" Style="{ThemeResource AccentButtonStyle}" Content="确定并重启应用"/>
<Button x:Name="CancelButton" Content="取消" Click="CancelButton_Click"/>
<HyperlinkButton
x:Uid="GetFreeKeyHyperlink"
Margin="0,0,0,4"
NavigateUri="https://github.com/zxbmmmmmmmmm/FluentWeather/wiki/%E8%8E%B7%E5%8F%96API-KEY" />
<TextBlock
x:Name="ErrorTextblock"
Margin="0,0,0,12"
Visibility="Collapsed" />
<AutoSuggestBox
x:Name="KeyBox"
PlaceholderText="KEY"
QueryIcon="Paste"
QuerySubmitted="KeyBox_QuerySubmitted"
Text="{x:Bind Key, Mode=TwoWay}" />
<AutoSuggestBox
x:Name="PublicIdBox"
x:Uid="PublicIdBox"
Margin="0,12,0,0"
QueryIcon="Paste"
QuerySubmitted="PublicIdBox_QuerySubmitted"
Text="{x:Bind PublicId, Mode=TwoWay}" />
<StackPanel
Margin="0,12,0,0"
Orientation="Horizontal"
Spacing="12">
<Button
x:Uid="ConfirmAndRestartButton"
HorizontalAlignment="Right"
Command="{x:Bind ConfirmCommand}"
Style="{ThemeResource AccentButtonStyle}" />
<Button
x:Name="CancelButton"
x:Uid="CancelButton"
Click="CancelButton_Click" />
</StackPanel>
</StackPanel>
</Grid>
Expand Down
1 change: 1 addition & 0 deletions FluentWeather.Uwp.Shared/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ public partial class Constants
public static readonly string QWeatherToken;
public static readonly string QWeatherPublicId;
public static readonly string AppCenterSecret;
public static readonly string QWeatherDomain;
}
4 changes: 1 addition & 3 deletions FluentWeather.Uwp.Shared/FluentWeather.Uwp.Shared.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,7 @@
<Name>FluentWeather.OpenMeteoProvider</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Folder Include="NewFolder1\" />
</ItemGroup>
<ItemGroup />
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '14.0' ">
<VisualStudioVersion>14.0</VisualStudioVersion>
</PropertyGroup>
Expand Down
Loading

0 comments on commit 9df07eb

Please sign in to comment.