ASP.NET Core 10 API and React client that visualize the canton of Thurgau's hourly traffic counts by vehicle class (data.tg.ch, CC0). - Background refresh from data.tg.ch every 6 h into a per-day JSON cache, so history grows beyond the source's two-week window - Road geometry per station direction from swisstopo swissTLM3D, oriented by geocoding the direction's target town; roundabout arms follow the road outward only - Leaflet map with canvas animation: dots drive along the road in both directions, density by hourly count, colour by vehicle class, right-hand traffic; play/pause, time slider and day selection - Station panel with per-class counts and Chart.js charts (hourly, weekday/weekend profile, daily totals, class mix) - swisstopo base map switcher (grey, colour, aerial) - Dockerfile and docker-compose with a data volume - xUnit tests for mapping, cache, geometry, geocoding and analysis Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
43 lines
1.8 KiB
C#
43 lines
1.8 KiB
C#
using Schaad.OpenData.Traffic.Analysis;
|
|
using Schaad.OpenData.Traffic.Models;
|
|
using Schaad.OpenData.Traffic.Storage;
|
|
|
|
namespace Schaad.OpenData.Server.Traffic;
|
|
|
|
public static class TrafficEndpoints
|
|
{
|
|
public static IEndpointRouteBuilder MapTrafficEndpoints(this IEndpointRouteBuilder endpoints)
|
|
{
|
|
var group = endpoints.MapGroup("/api/traffic");
|
|
|
|
group.MapGet("/meta", (TrafficDataStore store) =>
|
|
{
|
|
var snapshot = store.Current;
|
|
return new MetaResponse(
|
|
"Verkehrszähldaten motorisierter Individualverkehr nach Fahrzeugklassen",
|
|
"Kanton Thurgau, Tiefbauamt (data.tg.ch / opendata.swiss)",
|
|
"https://opendata.swiss/de/dataset/verkehrszahldaten-motorisierter-individualverkehr-nach-fahrzeugklassen",
|
|
"CC0 1.0",
|
|
Enum.GetNames<VehicleClass>().Select(n => char.ToLowerInvariant(n[0]) + n[1..]).ToList(),
|
|
snapshot.Dates,
|
|
snapshot.LastRefresh);
|
|
});
|
|
|
|
group.MapGet("/stations", (TrafficDataStore store) =>
|
|
{
|
|
var snapshot = store.Current;
|
|
return snapshot.Stations.Values
|
|
.OrderBy(s => s.Code)
|
|
.Select(s => StationResponse.From(s, snapshot.Geometry.GetValueOrDefault(s.Code)))
|
|
.ToList();
|
|
});
|
|
|
|
group.MapGet("/days/{date}", (DateOnly date, TrafficDataStore store) =>
|
|
TrafficAnalysis.BuildDay(store.Current, date) is { } day ? Results.Ok(day) : Results.NotFound());
|
|
|
|
group.MapGet("/stations/{code:int}/summary", (int code, DateOnly? from, DateOnly? to, TrafficDataStore store) =>
|
|
TrafficAnalysis.BuildStationSummary(store.Current, code, from, to) is { } summary ? Results.Ok(summary) : Results.NotFound());
|
|
|
|
return endpoints;
|
|
}
|
|
}
|