New Schaad.OpenData.Watercraft library that discovers the yearly "immatrikulierte Wasserfahrzeuge" datasets (2021–2025) on data.tg.ch, caches them and aggregates boats per harbour location by type, propulsion, fuel, emission group and use, with length/power bins. API under /api/watercraft, new page /schifffahrt/thurgau with donut markers per location, year playback, toggleable categories and a location/canton panel. Swisstopo base layers moved to map/baseLayers.ts for both maps. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
42 lines
1.4 KiB
C#
42 lines
1.4 KiB
C#
using System.Globalization;
|
|
using Schaad.OpenData.Watercraft.Models;
|
|
|
|
namespace Schaad.OpenData.Watercraft.Source;
|
|
|
|
public static class ThurgauVesselMapper
|
|
{
|
|
private const string UnknownLocation = "Unbekannt";
|
|
|
|
public static VesselYear Map(VesselDataset dataset, IEnumerable<ThurgauVesselRecord> records)
|
|
{
|
|
var list = records.ToList();
|
|
var referenceDate = list
|
|
.Select(r => ParseDate(r.ReferenceDate))
|
|
.Where(d => d is not null)
|
|
.Max();
|
|
|
|
var vessels = list.Select(r => new Vessel(
|
|
Clean(r.Location) ?? UnknownLocation,
|
|
Clean(r.Type),
|
|
Clean(r.SpecialUse),
|
|
r.LengthCm,
|
|
r.WidthCm,
|
|
r.SailAreaM2,
|
|
Clean(r.Propulsion),
|
|
r.EngineCount is { } count ? (int)Math.Round(count) : null,
|
|
r.PowerKw,
|
|
Clean(r.Fuel),
|
|
Clean(r.EmissionGroup)))
|
|
.ToList();
|
|
|
|
return new VesselYear(dataset.Year, dataset.DatasetId, dataset.Modified, referenceDate, vessels);
|
|
}
|
|
|
|
private static string? Clean(string? value) => string.IsNullOrWhiteSpace(value) ? null : value.Trim();
|
|
|
|
private static DateOnly? ParseDate(string? value) =>
|
|
value is { Length: >= 10 }
|
|
&& DateOnly.TryParseExact(value[..10], "yyyy-MM-dd", CultureInfo.InvariantCulture, DateTimeStyles.None, out var date)
|
|
? date
|
|
: null;
|
|
}
|