Skip to content

Commit

Permalink
Merge pull request #42 from zxbmmmmmmmmm/refactor/provider/qweather-uwp
Browse files Browse the repository at this point in the history
Refactor/provider/qweather uwp
  • Loading branch information
zxbmmmmmmmmm authored Apr 4, 2024
2 parents 45c8219 + 0008321 commit 833090c
Show file tree
Hide file tree
Showing 45 changed files with 1,047 additions and 130 deletions.
6 changes: 3 additions & 3 deletions FluentWeather.Tasks/FluentWeather.Tasks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,9 @@
<Project>{15e289d2-4104-4889-b968-60d2c2efd806}</Project>
<Name>FluentWeather.DIContainer</Name>
</ProjectReference>
<ProjectReference Include="..\FluentWeather.QWeatherProvider\FluentWeather.QWeatherProvider.csproj">
<Project>{89720ebb-0489-4147-a200-753747f4bcb8}</Project>
<Name>FluentWeather.QWeatherProvider</Name>
<ProjectReference Include="..\FluentWeather.Uwp.QWeatherProvider\FluentWeather.Uwp.QWeatherProvider.csproj">
<Project>{47F2B7FC-1B81-4D69-B5BA-D1160532ED63}</Project>
<Name>FluentWeather.Uwp.QWeatherProvider</Name>
</ProjectReference>
<ProjectReference Include="..\FluentWeather.Uwp.Shared\FluentWeather.Uwp.Shared.csproj">
<Project>{23269c7b-0343-48b6-9909-505d667b0dbf}</Project>
Expand Down
7 changes: 4 additions & 3 deletions FluentWeather.Tasks/NotifyTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using static FluentWeather.Uwp.Shared.TileHelper;
using static FluentWeather.Uwp.Shared.Common;
using System.Text.RegularExpressions;
using FluentWeather.Uwp.QWeatherProvider;

namespace FluentWeather.Tasks
{
Expand All @@ -22,7 +23,7 @@ public async void Run(IBackgroundTaskInstance taskInstance)

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

var provider = new QWeatherProvider.QWeatherProvider(Settings.QWeatherToken,Settings.QWeatherDomain,null,Settings.QWeatherPublicId);
var provider = new QWeatherProvider(Settings.QWeatherToken,Settings.QWeatherDomain,null,Settings.QWeatherPublicId);
var lat = Settings.Latitude;
var lon = Settings.Longitude;
if(lat is -1 || lon is -1)
Expand All @@ -43,7 +44,7 @@ private async Task PushWarnings(double lon, double lat)
var isWarningNotificationEnabled = Settings.IsWarningNotificationEnabled;
if (!isWarningNotificationEnabled) return;

var warnings = await QWeatherProvider.QWeatherProvider.Instance.GetWeatherWarnings(lon, lat);
var warnings = await QWeatherProvider.Instance.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 @@ -66,7 +67,7 @@ private async Task PushDaily(double lon, double lat)
var isTileAvailable = Settings.IsDailyNotificationTileEnabled && Settings.LastPushedTime != DateTime.Now.Date.DayOfYear;
if (!isPushTodayAvailable && !isPushTomorrowAvailable && !isTileAvailable) return;

var data = await QWeatherProvider.QWeatherProvider.Instance.GetDailyForecasts(lon, lat);
var data = await QWeatherProvider.Instance.GetDailyForecasts(lon, lat);
if (isTileAvailable)
{
UpdateTiles(data);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{47F2B7FC-1B81-4D69-B5BA-D1160532ED63}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>FluentWeather.Uwp.QWeatherProvider</RootNamespace>
<AssemblyName>FluentWeather.Uwp.QWeatherProvider</AssemblyName>
<DefaultLanguage>zh-CN</DefaultLanguage>
<TargetPlatformIdentifier>UAP</TargetPlatformIdentifier>
<TargetPlatformVersion Condition=" '$(TargetPlatformVersion)' == '' ">10.0.22621.0</TargetPlatformVersion>
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
<MinimumVisualStudioVersion>14</MinimumVisualStudioVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<PlatformTarget>x86</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<NoWarn>;2008</NoWarn>
<DebugType>full</DebugType>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<PlatformTarget>x86</PlatformTarget>
<OutputPath>bin\x86\Release\</OutputPath>
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<Optimize>true</Optimize>
<NoWarn>;2008</NoWarn>
<DebugType>pdbonly</DebugType>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|ARM'">
<PlatformTarget>ARM</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\ARM\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<NoWarn>;2008</NoWarn>
<DebugType>full</DebugType>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|ARM'">
<PlatformTarget>ARM</PlatformTarget>
<OutputPath>bin\ARM\Release\</OutputPath>
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<Optimize>true</Optimize>
<NoWarn>;2008</NoWarn>
<DebugType>pdbonly</DebugType>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|ARM64'">
<PlatformTarget>ARM64</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\ARM64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<NoWarn>;2008</NoWarn>
<DebugType>full</DebugType>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|ARM64'">
<PlatformTarget>ARM64</PlatformTarget>
<OutputPath>bin\ARM64\Release\</OutputPath>
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<Optimize>true</Optimize>
<NoWarn>;2008</NoWarn>
<DebugType>pdbonly</DebugType>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<PlatformTarget>x64</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<NoWarn>;2008</NoWarn>
<DebugType>full</DebugType>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<PlatformTarget>x64</PlatformTarget>
<OutputPath>bin\x64\Release\</OutputPath>
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<Optimize>true</Optimize>
<NoWarn>;2008</NoWarn>
<DebugType>pdbonly</DebugType>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<PropertyGroup>
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
</PropertyGroup>
<ItemGroup>
<Compile Include="Views\SetTokenDialog.xaml.cs">
<DependentUpon>SetTokenDialog.xaml</DependentUpon>
</Compile>
<Compile Include="Helpers\WeatherTypeConverter.cs" />
<Compile Include="Mappers\AirConditionMapper.cs" />
<Compile Include="Mappers\DailyForecastItemMapper.cs" />
<Compile Include="Mappers\GeolocationMapper.cs" />
<Compile Include="Mappers\HourlyForecastItemMapper.cs" />
<Compile Include="Mappers\PrecipitationMapper.cs" />
<Compile Include="Mappers\TyphoonMapper.cs" />
<Compile Include="Mappers\WeatherIndicesMapper.cs" />
<Compile Include="Mappers\WeatherNowMapper.cs" />
<Compile Include="Mappers\WeatherWarningMapper.cs" />
<Compile Include="Models\QAirCondition.cs" />
<Compile Include="Models\QTyphoon.cs" />
<Compile Include="Models\QWeatherDailyForecast.cs" />
<Compile Include="Models\QWeatherHourlyForecast.cs" />
<Compile Include="Models\QWeatherIndices.cs" />
<Compile Include="Models\QWeatherNight.cs" />
<Compile Include="Models\QWeatherNow.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="QWeatherProvider.cs" />
<EmbeddedResource Include="Properties\FluentWeather.Uwp.QWeatherProvider.rd.xml" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm">
<Version>8.2.2</Version>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.DependencyInjection">
<Version>8.0.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
<Version>6.2.14</Version>
</PackageReference>
<PackageReference Include="Microsoft.UI.Xaml">
<Version>2.7.3</Version>
</PackageReference>
<PackageReference Include="Microsoft.Xaml.Behaviors.Uwp.Managed">
<Version>2.0.1</Version>
</PackageReference>
<PackageReference Include="QWeather">
<Version>1.0.1</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\FluentWeather.Abstraction\FluentWeather.Abstraction.csproj">
<Project>{0627214c-2da0-4b49-bb12-dc8c44014eee}</Project>
<Name>FluentWeather.Abstraction</Name>
</ProjectReference>
<ProjectReference Include="..\FluentWeather.DIContainer\FluentWeather.DIContainer.csproj">
<Project>{15e289d2-4104-4889-b968-60d2c2efd806}</Project>
<Name>FluentWeather.DIContainer</Name>
</ProjectReference>
<ProjectReference Include="..\FluentWeather.Uwp.Shared\FluentWeather.Uwp.Shared.csproj">
<Project>{23269c7b-0343-48b6-9909-505d667b0dbf}</Project>
<Name>FluentWeather.Uwp.Shared</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup />
<ItemGroup>
<Page Include="Views\SetTokenDialog.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
</ItemGroup>
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '14.0' ">
<VisualStudioVersion>14.0</VisualStudioVersion>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
56 changes: 56 additions & 0 deletions FluentWeather.Uwp.QWeatherProvider/Helpers/WeatherTypeConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using FluentWeather.Abstraction.Models;
using static FluentWeather.Abstraction.Models.WeatherCode;
namespace FluentWeather.Uwp.QWeatherProvider.Helpers;


public static class WeatherTypeConverter
{
public static WeatherCode GetWeatherTypeByDescription(string description)
{
description = description.ToLower();
if (description.Contains("晴") || description.Contains("Clear"))
return Clear;
if (description.Contains("阴") || description.Contains("Overcast"))
return Overcast;
if (description.Contains("小雨") || description.Contains("Light Rain"))
return SlightRain;
if (description.Contains("中雨") || description.Contains("Moderate Rain"))
return ModerateRain;
if (description.Contains("大雨") || description.Contains("Heavy Rain"))
return HeavyRain;
if (description.Contains("局部多云") || description.Contains("Partly Cloudy"))
return PartlyCloudy;
if (description.Contains("大部多云") || description.Contains("Cloudy"))
return PartlyCloudy;
if (description.Contains("少云") || description.Contains("Mainly Clear"))
return MainlyClear;

if (description.Contains("冰雹") || description.Contains("Hail"))
return SlightHail;
if (description.Contains("雷阵雨") || description.Contains("Thunder"))
return HeavyThunderStorm;
if(description.Contains("小雪") || description.Contains("Light Snow"))
return SlightSnowFall;
if (description.Contains("大雪") || description.Contains("Heavy Snow"))
return HeavySnowFall;
if (description.Contains("冻雨") || description.Contains("Freezing Rain"))
return LightFreezingRain;

if (description.Contains("雪") || description.Contains("Snow"))
return ModerateSnowFall;
if (description.Contains("雷") || description.Contains("Thunder"))
return SlightOrModerateThunderstorm;
if (description.Contains("雨") || description.Contains("Rain"))
return ModerateRain;
if (description.Contains("雾") || description.Contains("Fog"))
return Fog;
if (description.Contains("霾") || description.Contains("Haze"))
return Haze;
if (description.Contains("多云") || description.Contains("Cloud"))
return PartlyCloudy;



return Unknown;
}
}
24 changes: 24 additions & 0 deletions FluentWeather.Uwp.QWeatherProvider/Mappers/AirConditionMapper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using FluentWeather.Uwp.QWeatherProvider.Models;
using QWeatherApi.ApiContracts;

namespace FluentWeather.Uwp.QWeatherProvider.Mappers
{
internal static class AirConditionMapper
{
public static QAirCondition MapToQAirCondition(this AirConditionResponse.AirConditionItem item)
{
return new QAirCondition
{
Aqi = item.Aqi,
AqiCategory = item.Category,
AqiLevel = item.Level,
CO= item.Co,
SO2 = item.So2,
NO2 = item.No2,
O3 = item.O3,
PM10 = item.Pm10,
PM25 = item.Pm2p5,
};
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using FluentWeather.Abstraction.Helpers;
using FluentWeather.Uwp.QWeatherProvider.Models;
using QWeatherApi.ApiContracts;

namespace FluentWeather.Uwp.QWeatherProvider.Mappers;

public static class DailyForecastItemMapper
{
public static QWeatherDailyForecast MapToQWeatherDailyForecast(this WeatherDailyResponse.DailyForecastItem item)
{
return new QWeatherDailyForecast
{
WindDirection = UnitConverter.GetWindDirectionFromAngle(int.Parse(item.Wind360Day)),
Description = item.TextDay,
WindDirectionDescription = item.WindDirDay,
WindScale = item.WindScaleDay,
WindSpeed = item.WindSpeedDay,
Humidity = item.Humidity,
MaxTemperature = item.TempMax,
MinTemperature = item.TempMin,
Pressure = item.Pressure,
Time = item.FxDate,
Visibility = item.Vis,
SunRise = item.Sunrise,
SunSet = item.Sunset,
CloudAmount = item.Cloud,

WeatherNight = new QWeatherNight
{
Description = item.TextNight,
WindDirection = UnitConverter.GetWindDirectionFromAngle(item.Wind360Night),
WindDirectionDescription = item.WindDirNight,
WindScale = item.WindScaleNight,
WindSpeed = item.WindSpeedNight,
}
};
}
}
Loading

0 comments on commit 833090c

Please sign in to comment.