- 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>
55 lines
1.8 KiB
C#
55 lines
1.8 KiB
C#
using Schaad.OpenData.Weather.Models;
|
|
|
|
namespace Schaad.OpenData.Weather.Storage;
|
|
|
|
public sealed class WeatherSnapshot
|
|
{
|
|
public static readonly WeatherSnapshot Empty = new([], [], null, null);
|
|
|
|
public WeatherSnapshot(
|
|
IEnumerable<WeatherStation> stations,
|
|
IEnumerable<WeatherReading> readings,
|
|
DateTimeOffset? lastRefresh,
|
|
DateTimeOffset? stationsFetched)
|
|
{
|
|
Stations = stations
|
|
.GroupBy(s => s.Abbr)
|
|
.Select(g => g.Last())
|
|
.OrderBy(s => s.Abbr, StringComparer.Ordinal)
|
|
.ToList();
|
|
Readings = readings
|
|
.GroupBy(r => (r.StationAbbr, r.Time))
|
|
.Select(g => g.Last())
|
|
.OrderBy(r => r.Time)
|
|
.ThenBy(r => r.StationAbbr, StringComparer.Ordinal)
|
|
.ToList();
|
|
LastRefresh = lastRefresh;
|
|
StationsFetched = stationsFetched;
|
|
}
|
|
|
|
public IReadOnlyList<WeatherStation> Stations { get; }
|
|
|
|
public IReadOnlyList<WeatherReading> Readings { get; }
|
|
|
|
public DateTimeOffset? LastRefresh { get; }
|
|
|
|
public DateTimeOffset? StationsFetched { get; }
|
|
|
|
public WeatherSnapshot With(
|
|
IReadOnlyList<WeatherStation> stations,
|
|
IEnumerable<WeatherReading> readings,
|
|
DateTimeOffset lastRefresh,
|
|
DateTimeOffset? stationsFetched,
|
|
DateTimeOffset keepFrom) =>
|
|
new(
|
|
Stations.Concat(stations),
|
|
Readings.Concat(readings).Where(r => r.Time >= keepFrom),
|
|
lastRefresh,
|
|
stationsFetched ?? StationsFetched);
|
|
|
|
public IReadOnlyList<WeatherReading> NewReadings(IEnumerable<WeatherReading> readings)
|
|
{
|
|
var known = Readings.Select(r => (r.StationAbbr, r.Time)).ToHashSet();
|
|
return readings.Where(r => !known.Contains((r.StationAbbr, r.Time))).ToList();
|
|
}
|
|
}
|