Skip to content

Commit

Permalink
Update met.no sunrise api to version 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ahaggqvist committed Oct 21, 2023
1 parent 3c753b9 commit c57f99c
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 131 deletions.
12 changes: 6 additions & 6 deletions Uroskur.sln
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ Global
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A0AADFB5-E349-4FF6-9D17-7F8E41FD34C0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A0AADFB5-E349-4FF6-9D17-7F8E41FD34C0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A0AADFB5-E349-4FF6-9D17-7F8E41FD34C0}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
{A0AADFB5-E349-4FF6-9D17-7F8E41FD34C0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A0AADFB5-E349-4FF6-9D17-7F8E41FD34C0}.Release|Any CPU.Build.0 = Release|Any CPU
{A0AADFB5-E349-4FF6-9D17-7F8E41FD34C0}.Release|Any CPU.Deploy.0 = Release|Any CPU
{A0AADFB5-E349-4FF6-9D17-7F8E41FD34C0}.Debug|Any CPU.ActiveCfg = Release|Any CPU
{A0AADFB5-E349-4FF6-9D17-7F8E41FD34C0}.Debug|Any CPU.Build.0 = Release|Any CPU
{A0AADFB5-E349-4FF6-9D17-7F8E41FD34C0}.Debug|Any CPU.Deploy.0 = Release|Any CPU
{A0AADFB5-E349-4FF6-9D17-7F8E41FD34C0}.Release|Any CPU.ActiveCfg = Debug|Any CPU
{A0AADFB5-E349-4FF6-9D17-7F8E41FD34C0}.Release|Any CPU.Build.0 = Debug|Any CPU
{A0AADFB5-E349-4FF6-9D17-7F8E41FD34C0}.Release|Any CPU.Deploy.0 = Debug|Any CPU
{4AA32FCF-83A5-4EF8-9D04-234FB0A48FF7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4AA32FCF-83A5-4EF8-9D04-234FB0A48FF7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4AA32FCF-83A5-4EF8-9D04-234FB0A48FF7}.Release|Any CPU.ActiveCfg = Debug|Any CPU
Expand Down
142 changes: 42 additions & 100 deletions src/Models/Yr/YrSunriseData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,135 +4,77 @@
//
// using Uroskur.Models.Yr;
//
// var yrSunrise = YrSunrise.FromJson(jsonString);
// var yrSunriseData = YrSunriseData.FromJson(jsonString);

namespace Uroskur.Models.Yr
{
public partial class YrSunriseData
{
[JsonProperty("location", NullValueHandling = NullValueHandling.Ignore)]
public Location Location { get; set; }

[JsonProperty("meta", NullValueHandling = NullValueHandling.Ignore)]
public Meta Meta { get; set; }
}

public partial class Location
{
[JsonProperty("height", NullValueHandling = NullValueHandling.Ignore)]
[JsonConverter(typeof(ParseStringConverter))]
public long? Height { get; set; }
using System;
using Newtonsoft.Json;

[JsonProperty("latitude", NullValueHandling = NullValueHandling.Ignore)]
public string Latitude { get; set; }

[JsonProperty("longitude", NullValueHandling = NullValueHandling.Ignore)]
public string Longitude { get; set; }

[JsonProperty("time", NullValueHandling = NullValueHandling.Ignore)]
public List<Time> Time { get; set; }
}

public partial class Time
public partial class YrSunriseData
{
[JsonProperty("date", NullValueHandling = NullValueHandling.Ignore)]
public DateTimeOffset? Date { get; set; }

[JsonProperty("high_moon", NullValueHandling = NullValueHandling.Ignore)]
public HighMoon HighMoon { get; set; }
[JsonProperty("copyright")]
public string Copyright { get; set; }

[JsonProperty("low_moon", NullValueHandling = NullValueHandling.Ignore)]
public HighMoon LowMoon { get; set; }
[JsonProperty("licenseURL")]
public Uri LicenseUrl { get; set; }

[JsonProperty("moonphase", NullValueHandling = NullValueHandling.Ignore)]
public Moonphase Moonphase { get; set; }
[JsonProperty("type")]
public string Type { get; set; }

[JsonProperty("moonposition", NullValueHandling = NullValueHandling.Ignore)]
public Moonposition Moonposition { get; set; }
[JsonProperty("geometry")]
public Geometry Geometry { get; set; }

[JsonProperty("moonrise", NullValueHandling = NullValueHandling.Ignore)]
public Moonrise Moonrise { get; set; }
[JsonProperty("when")]
public When When { get; set; }

[JsonProperty("moonset", NullValueHandling = NullValueHandling.Ignore)]
public Moonrise Moonset { get; set; }

[JsonProperty("moonshadow", NullValueHandling = NullValueHandling.Ignore)]
public HighMoon Moonshadow { get; set; }

[JsonProperty("solarmidnight", NullValueHandling = NullValueHandling.Ignore)]
public HighMoon Solarmidnight { get; set; }

[JsonProperty("solarnoon", NullValueHandling = NullValueHandling.Ignore)]
public HighMoon Solarnoon { get; set; }

[JsonProperty("sunrise", NullValueHandling = NullValueHandling.Ignore)]
public Moonrise Sunrise { get; set; }

[JsonProperty("sunset", NullValueHandling = NullValueHandling.Ignore)]
public Moonrise Sunset { get; set; }
[JsonProperty("properties")]
public Properties Properties { get; set; }
}

public partial class HighMoon
public partial class Properties
{
[JsonProperty("desc", NullValueHandling = NullValueHandling.Ignore)]
public string Desc { get; set; }

[JsonProperty("elevation", NullValueHandling = NullValueHandling.Ignore)]
public string Elevation { get; set; }
[JsonProperty("body")]
public string Body { get; set; }

[JsonProperty("time", NullValueHandling = NullValueHandling.Ignore)]
public DateTimeOffset? Time { get; set; }
[JsonProperty("sunrise")]
public Sun Sunrise { get; set; }

[JsonProperty("azimuth", NullValueHandling = NullValueHandling.Ignore)]
public string Azimuth { get; set; }
}

public partial class Moonphase
{
[JsonProperty("desc", NullValueHandling = NullValueHandling.Ignore)]
public string Desc { get; set; }
[JsonProperty("sunset")]
public Sun Sunset { get; set; }

[JsonProperty("time", NullValueHandling = NullValueHandling.Ignore)]
public DateTimeOffset? Time { get; set; }
[JsonProperty("solarnoon")]
public Solar Solarnoon { get; set; }

[JsonProperty("value", NullValueHandling = NullValueHandling.Ignore)]
public string Value { get; set; }
[JsonProperty("solarmidnight")]
public Solar Solarmidnight { get; set; }
}

public partial class Moonposition
public partial class Solar
{
[JsonProperty("azimuth", NullValueHandling = NullValueHandling.Ignore)]
public string Azimuth { get; set; }

[JsonProperty("desc", NullValueHandling = NullValueHandling.Ignore)]
public string Desc { get; set; }

[JsonProperty("elevation", NullValueHandling = NullValueHandling.Ignore)]
public string Elevation { get; set; }

[JsonProperty("phase", NullValueHandling = NullValueHandling.Ignore)]
public string Phase { get; set; }
[JsonProperty("time")]
public string Time { get; set; }

[JsonProperty("range", NullValueHandling = NullValueHandling.Ignore)]
public string Range { get; set; }
[JsonProperty("disc_centre_elevation")]
public double DiscCentreElevation { get; set; }

[JsonProperty("time", NullValueHandling = NullValueHandling.Ignore)]
public DateTimeOffset? Time { get; set; }
[JsonProperty("visible")]
public bool Visible { get; set; }
}

public partial class Moonrise
public partial class Sun
{
[JsonProperty("desc", NullValueHandling = NullValueHandling.Ignore)]
public string Desc { get; set; }
[JsonProperty("time")]
public string Time { get; set; }

[JsonProperty("time", NullValueHandling = NullValueHandling.Ignore)]
public DateTimeOffset? Time { get; set; }
[JsonProperty("azimuth")]
public double Azimuth { get; set; }
}

public partial class Meta
public partial class When
{
[JsonProperty("licenseurl", NullValueHandling = NullValueHandling.Ignore)]
public Uri Licenseurl { get; set; }
[JsonProperty("interval")]
public DateTimeOffset[] Interval { get; set; }
}

public partial class YrSunriseData
Expand Down
21 changes: 8 additions & 13 deletions src/Services/WeatherForecastService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,14 @@ private async Task<IEnumerable<WeatherForecast>> GetWeatherForecastsAsync(
foreach (var weatherForecast in weatherForecasts)
{
if (weatherForecastProviderDataToday?.YrSunriseData == null || weatherForecastProviderDataTomorrow?.YrSunriseData == null) continue;
var sunriseToday = weatherForecastProviderDataToday.YrSunriseData.Location.Time[0].Sunrise.Time;
var sunsetToday = weatherForecastProviderDataToday.YrSunriseData.Location.Time[0].Sunset.Time;
var sunriseTomorrow = weatherForecastProviderDataTomorrow.YrSunriseData.Location.Time[0].Sunrise.Time;
var sunsetTomorrow = weatherForecastProviderDataTomorrow.YrSunriseData.Location.Time[0].Sunset.Time;
if (sunriseToday != null) weatherForecast.SunriseToday = RoundUpSeconds(sunriseToday.Value.LocalDateTime);
if (sunsetToday != null) weatherForecast.SunsetToday = RoundUpSeconds(sunsetToday.Value.LocalDateTime);
if (sunriseTomorrow != null) weatherForecast.SunriseTomorrow = RoundUpSeconds(sunriseTomorrow.Value.LocalDateTime);
if (sunsetTomorrow != null) weatherForecast.SunsetTomorrow = RoundUpSeconds(sunsetTomorrow.Value.LocalDateTime);
var sunriseToday = DateTime.Parse(weatherForecastProviderDataToday.YrSunriseData.Properties.Sunrise.Time, new CultureInfo("sv-SE"));
var sunsetToday = DateTime.Parse(weatherForecastProviderDataToday.YrSunriseData.Properties.Sunset.Time, new CultureInfo("sv-SE"));
var sunriseTomorrow = DateTime.Parse(weatherForecastProviderDataTomorrow.YrSunriseData.Properties.Sunrise.Time, new CultureInfo("sv-SE"));
var sunsetTomorrow = DateTime.Parse(weatherForecastProviderDataTomorrow.YrSunriseData.Properties.Sunset.Time, new CultureInfo("sv-SE"));
weatherForecast.SunriseToday = RoundUpSeconds(sunriseToday);
weatherForecast.SunsetToday = RoundUpSeconds(sunsetToday);
weatherForecast.SunriseTomorrow = RoundUpSeconds(sunriseTomorrow);
weatherForecast.SunsetTomorrow = RoundUpSeconds(sunsetTomorrow);
}

return weatherForecasts;
Expand All @@ -113,11 +113,6 @@ private async Task<ImmutableArray<Location>> GetLocations(string athleteId, stri
var locations = (await _stravaService.FindLocationsByAthleteIdRouteIdAsync(athleteId, routeId))
.ToImmutableArray();

if (locations == null)
{
throw new ArgumentException("Locations are null.");
}

if (locations.Length > MaxLocations)
{
throw new ArgumentException("Number of locations exceed maximum allowed.");
Expand Down
12 changes: 6 additions & 6 deletions src/Uroskur.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net7.0-android;net7.0-ios;net7.0-maccatalyst</TargetFrameworks>
<TargetFrameworks>net7.0-maccatalyst;net7.0-ios;net7.0-android</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net7.0-windows10.0.19041.0</TargetFrameworks>
<!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET -->
<!-- <TargetFrameworks>$(TargetFrameworks);net7.0-tizen</TargetFrameworks> -->
Expand Down Expand Up @@ -67,13 +67,13 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="CommunityToolkit.Maui" Version="5.0.0" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.0-preview2" />
<PackageReference Include="CommunityToolkit.Maui" Version="6.0.0" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.1" />
<PackageReference Include="MonkeyCache.FileStore" Version="2.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Polly" Version="7.2.3" />
<PackageReference Include="SkiaSharp" Version="2.88.3" />
<PackageReference Include="SkiaSharp.Views.Maui.Controls" Version="2.88.3" />
<PackageReference Include="Polly" Version="8.0.0" />
<PackageReference Include="SkiaSharp" Version="2.88.6" />
<PackageReference Include="SkiaSharp.Views.Maui.Controls" Version="2.88.6" />
</ItemGroup>

<ItemGroup Condition="$(TargetFramework.StartsWith('net7.0-android')) != true">
Expand Down
2 changes: 1 addition & 1 deletion src/appsettings.Development.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
"OpenWeatherApiUrl": "https://api.openweathermap.org/data/2.5/onecall?lat=@Lat&lon=@Lon&exclude=@Exclude&units=metric&appid=@AppId&lang=en",
"YrApiUrl": "https://api.met.no/weatherapi/locationforecast/2.0/complete?lat=@Lat&lon=@Lon",
"SmhiApiUrl": "https://opendata-download-metfcst.smhi.se/api/category/pmp3g/version/2/geotype/point/lon/@Lon/lat/@Lat/data.json",
"YrSunriseApiUrl": "https://api.met.no/weatherapi/sunrise/2.0/.json?lat=@Lat&lon=@Lon&date=@Date&offset=@Offset",
"YrSunriseApiUrl": "https://api.met.no/weatherapi/sunrise/3.0/sun?lat=@Lat&lon=@Lon&date=@Date&offset=@Offset",
"IsDevelopment": true
}
2 changes: 1 addition & 1 deletion src/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
"OpenWeatherApiUrl": "https://api.openweathermap.org/data/2.5/onecall?lat=@Lat&lon=@Lon&exclude=@Exclude&units=metric&appid=@AppId&lang=en",
"YrApiUrl": "https://api.met.no/weatherapi/locationforecast/2.0/complete?lat=@Lat&lon=@Lon",
"SmhiApiUrl": "https://opendata-download-metfcst.smhi.se/api/category/pmp3g/version/2/geotype/point/lon/@Lon/lat/@Lat/data.json",
"YrSunriseApiUrl": "https://api.met.no/weatherapi/sunrise/2.0/.json?lat=@Lat&lon=@Lon&date=@Date&offset=@Offset",
"YrSunriseApiUrl": "https://api.met.no/weatherapi/sunrise/3.0/sun?lat=@Lat&lon=@Lon&date=@Date&offset=@Offset",
"IsDevelopment": false
}
8 changes: 4 additions & 4 deletions tests/Uroskur.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0-preview-20230223-05" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="xunit" Version="2.5.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.2.0">
<PackageReference Include="coverlet.collector" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down

0 comments on commit c57f99c

Please sign in to comment.