Wetterdienst: Erweitert

This commit is contained in:
2026-08-23 21:45:25 +02:00
parent e76884a58e
commit 83a430f8ee
6 changed files with 60 additions and 7 deletions
@@ -13,6 +13,8 @@ public sealed class SchoolDayWeatherSummary
public double? MinTemperatureC { get; init; }
public double? MaxTemperatureC { get; init; }
public double PrecipitationMm { get; init; }
public double? MaxHourlyPrecipitationProbabilityPercent { get; init; }
public double? SunshineDurationHours { get; init; }
public double? MaxWindGustKmh { get; init; }
public IReadOnlyList<WeatherWarning> Warnings { get; init; } = [];
@@ -38,10 +40,15 @@ public sealed class SchoolDayWeatherSummary
{
get
{
var lines = new List<string> { Label };
var lines = new List<string> { $"{Label} · 0816 Uhr" };
if (MinTemperatureC is { } min && MaxTemperatureC is { } max)
lines.Add(Math.Abs(max - min) < 0.05 ? $"{min:0.#} °C" : $"{min:0.#}{max:0.#} °C");
lines.Add("Temperatur: " + (Math.Abs(max - min) < 0.05
? $"{min:0.#} °C" : $"{min:0.#}{max:0.#} °C"));
if (MaxHourlyPrecipitationProbabilityPercent is { } probability)
lines.Add($"Regenwahrscheinlichkeit: bis {probability:0} % (stündlich)");
if (PrecipitationMm >= 0.05) lines.Add($"Niederschlag: {PrecipitationMm:0.#} mm");
if (SunshineDurationHours is { } sunshine)
lines.Add($"Sonnenschein: {sunshine:0.#} h");
if (MaxWindGustKmh is { } gust) lines.Add($"Max. Böen: {gust:0.#} km/h");
foreach (var warning in Warnings)
{
@@ -63,7 +70,7 @@ public sealed class SchoolDayWeatherSummary
var schoolHours = allHours.Where(x =>
{
var hour = Local(x.ValidAt).Hour;
return hour >= 6 && hour <= 18;
return hour >= 8 && hour <= 16;
}).ToList();
var hours = schoolHours.Count > 0 ? schoolHours : allHours;
if (hours.Count == 0) return null;
@@ -71,6 +78,10 @@ public sealed class SchoolDayWeatherSummary
var warnings = snapshot.Warnings.Where(x => WarningTouchesDate(x, date)).ToList();
var codes = hours.Where(x => x.WeatherCode.HasValue).Select(x => x.WeatherCode!.Value).ToList();
var precipitation = hours.Sum(x => x.PrecipitationMm ?? 0);
var probabilities = hours.Where(x => x.PrecipitationProbabilityPercent.HasValue)
.Select(x => x.PrecipitationProbabilityPercent!.Value).ToList();
var sunshineMinutes = hours.Where(x => x.SunshineDurationMinutes.HasValue)
.Select(x => x.SunshineDurationMinutes!.Value).ToList();
var gust = hours.Where(x => x.WindGustKmh.HasValue).Select(x => x.WindGustKmh!.Value).DefaultIfEmpty().Max();
var hasGust = hours.Any(x => x.WindGustKmh.HasValue);
var warningText = string.Join(" ", warnings.SelectMany(x => new[] { x.Event, x.Headline }));
@@ -95,6 +106,10 @@ public sealed class SchoolDayWeatherSummary
MinTemperatureC = temperatures.Count > 0 ? temperatures.Min() : null,
MaxTemperatureC = temperatures.Count > 0 ? temperatures.Max() : null,
PrecipitationMm = Math.Round(precipitation, 1, MidpointRounding.AwayFromZero),
MaxHourlyPrecipitationProbabilityPercent = probabilities.Count > 0
? Math.Round(probabilities.Max(), 0, MidpointRounding.AwayFromZero) : null,
SunshineDurationHours = sunshineMinutes.Count > 0
? Math.Round(sunshineMinutes.Sum() / 60, 1, MidpointRounding.AwayFromZero) : null,
MaxWindGustKmh = hasGust ? Math.Round(gust, 1, MidpointRounding.AwayFromZero) : null,
Warnings = warnings,
};