- New Schaad.OpenData.Weather project: MeteoSwissClient reads the
10-minute CSV of the five SwissMetNet stations in Thurgau every 10
minutes (station list once a day) and backfills the last 7 days from
the yearly file when the cache has less than 6 days
- History kept as JSON per day (60 days); a failing station does not
stop the others
- API: /api/weather/meta, /stations (current values, 1 h/24 h rain,
24 h min/max, strongest gust), /stations/{abbr}/history
- Combined map: "Wetter (live)" layer with station badges (temperature,
24 h rain or wind), wind arrows, rain marker, station panel with
hourly 7-day chart, overview and municipality context entries
- Docs: docs/datasets/wetter.md, overview in docs/datasets.md,
CLAUDE.md; Docker and appsettings wiring
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
47 lines
1.7 KiB
C#
47 lines
1.7 KiB
C#
using Microsoft.Extensions.Options;
|
||
using Schaad.OpenData.Weather;
|
||
using Schaad.OpenData.Weather.Analysis;
|
||
using Schaad.OpenData.Weather.Storage;
|
||
|
||
namespace Schaad.OpenData.Server.Weather;
|
||
|
||
public static class WeatherEndpoints
|
||
{
|
||
private const int DefaultHistoryDays = 7;
|
||
|
||
public static IEndpointRouteBuilder MapWeatherEndpoints(this IEndpointRouteBuilder endpoints)
|
||
{
|
||
var group = endpoints.MapGroup("/api/weather");
|
||
|
||
group.MapGet("/meta", (WeatherDataStore store, IOptions<WeatherOptions> options) =>
|
||
new WeatherMetaResponse(
|
||
"Automatische Wetterstationen – Messwerte (SwissMetNet)",
|
||
"MeteoSchweiz",
|
||
"https://opendata.swiss/de/dataset/automatische-wetterstationen-messwerte",
|
||
"CC BY 4.0",
|
||
options.Value.HistoryDays,
|
||
store.Current.LastRefresh));
|
||
|
||
group.MapGet("/stations", (WeatherDataStore store) => WeatherAnalysis.BuildStations(store.Current));
|
||
|
||
group.MapGet("/stations/{abbr}/history", (
|
||
string abbr,
|
||
int? tage,
|
||
WeatherDataStore store,
|
||
IOptions<WeatherOptions> options,
|
||
TimeProvider timeProvider) =>
|
||
{
|
||
var snapshot = store.Current;
|
||
var key = abbr.ToUpperInvariant();
|
||
if (snapshot.Stations.All(s => s.Abbr != key))
|
||
{
|
||
return Results.NotFound();
|
||
}
|
||
|
||
var days = Math.Clamp(tage ?? DefaultHistoryDays, 1, options.Value.HistoryDays);
|
||
return Results.Ok(WeatherAnalysis.BuildHistory(snapshot, key, timeProvider.GetUtcNow().AddDays(-days)));
|
||
});
|
||
|
||
return endpoints;
|
||
}
|
||
}
|