- New Schaad.OpenData.Hydrology project: LindasHydroClient fetches the
current level, discharge, water temperature and danger level of nine
BAFU stations around Thurgau from LINDAS every 10 minutes
- LINDAS has no history, so the server keeps readings per day (60 days)
and fills gaps from the 7-day plot JSON of hydrodaten.admin.ch
- API: /api/hydrology/meta, /stations, /stations/{id}/history
- Combined map: "Gewässer (live)" layer with river circles (size by
discharge, colour by danger level or water temperature), lake level
badges, station panel with 7-day chart, overview and municipality
context entries
- Docs: docs/datasets/gewaesser.md, overview in docs/datasets.md,
CLAUDE.md; Docker and appsettings wiring
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Claudio Schaad <c.schaad@pog.ch>
Co-committed-by: Claudio Schaad <c.schaad@pog.ch>
46 lines
1.6 KiB
C#
46 lines
1.6 KiB
C#
using Microsoft.Extensions.Options;
|
|
using Schaad.OpenData.Hydrology;
|
|
using Schaad.OpenData.Hydrology.Analysis;
|
|
using Schaad.OpenData.Hydrology.Storage;
|
|
|
|
namespace Schaad.OpenData.Server.Hydrology;
|
|
|
|
public static class HydrologyEndpoints
|
|
{
|
|
private const int DefaultHistoryDays = 7;
|
|
|
|
public static IEndpointRouteBuilder MapHydrologyEndpoints(this IEndpointRouteBuilder endpoints)
|
|
{
|
|
var group = endpoints.MapGroup("/api/hydrology");
|
|
|
|
group.MapGet("/meta", (HydrologyDataStore store, IOptions<HydrologyOptions> options) =>
|
|
new HydrologyMetaResponse(
|
|
"Hydrologische Daten: aktuelle Messwerte von Flüssen und Seen",
|
|
"Bundesamt für Umwelt BAFU",
|
|
"https://www.hydrodaten.admin.ch/",
|
|
"opendata.swiss BY",
|
|
options.Value.HistoryDays,
|
|
store.Current.LastRefresh));
|
|
|
|
group.MapGet("/stations", (HydrologyDataStore store) => HydrologyAnalysis.BuildStations(store.Current));
|
|
|
|
group.MapGet("/stations/{id}/history", (
|
|
string id,
|
|
int? tage,
|
|
HydrologyDataStore store,
|
|
IOptions<HydrologyOptions> options,
|
|
TimeProvider timeProvider) =>
|
|
{
|
|
var snapshot = store.Current;
|
|
if (snapshot.Stations.All(s => s.Id != id))
|
|
{
|
|
return Results.NotFound();
|
|
}
|
|
|
|
var days = Math.Clamp(tage ?? DefaultHistoryDays, 1, options.Value.HistoryDays);
|
|
return Results.Ok(HydrologyAnalysis.BuildHistory(snapshot, id, timeProvider.GetUtcNow().AddDays(-days)));
|
|
});
|
|
|
|
return endpoints;
|
|
}
|
|
}
|