- 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>
42 lines
1.5 KiB
C#
42 lines
1.5 KiB
C#
using Schaad.OpenData.Hydrology.Models;
|
|
|
|
namespace Schaad.OpenData.Hydrology.Storage;
|
|
|
|
public sealed class HydrologySnapshot
|
|
{
|
|
public static readonly HydrologySnapshot Empty = new([], [], null);
|
|
|
|
public HydrologySnapshot(IEnumerable<HydroStation> stations, IEnumerable<HydroReading> readings, DateTimeOffset? lastRefresh)
|
|
{
|
|
Stations = stations
|
|
.GroupBy(s => s.Id)
|
|
.Select(g => g.Last())
|
|
.OrderBy(s => s.Id, StringComparer.Ordinal)
|
|
.ToList();
|
|
Readings = readings
|
|
.GroupBy(r => (r.StationId, r.Time))
|
|
.Select(g => g.Last())
|
|
.OrderBy(r => r.Time)
|
|
.ThenBy(r => r.StationId, StringComparer.Ordinal)
|
|
.ToList();
|
|
LastRefresh = lastRefresh;
|
|
}
|
|
|
|
public IReadOnlyList<HydroStation> Stations { get; }
|
|
|
|
public IReadOnlyList<HydroReading> Readings { get; }
|
|
|
|
public DateTimeOffset? LastRefresh { get; }
|
|
|
|
public HydrologySnapshot With(HydroMeasurements measurements, DateTimeOffset lastRefresh, DateTimeOffset keepFrom) =>
|
|
new(
|
|
Stations.Concat(measurements.Stations),
|
|
Readings.Concat(measurements.Readings).Where(r => r.Time >= keepFrom),
|
|
lastRefresh);
|
|
|
|
public IReadOnlyList<HydroReading> NewReadings(IEnumerable<HydroReading> readings)
|
|
{
|
|
var known = Readings.Select(r => (r.StationId, r.Time)).ToHashSet();
|
|
return readings.Where(r => !known.Contains((r.StationId, r.Time))).ToList();
|
|
}
|
|
}
|