- Thurgau hourly traffic counts (data.tg.ch) refreshed every 6 h into a per-day JSON cache - Road geometry per station direction from swisstopo swissTLM3D; roundabout arms run outward from the roundabout centre - Leaflet map with animated vehicles by class, time controls and base map switcher (grey, colour, aerial) - Station panel with per-class counts and Chart.js charts - Start page with map tiles; traffic map at /verkehr/thurgau - Dockerfile and docker-compose, xUnit tests 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>
38 lines
1.5 KiB
C#
38 lines
1.5 KiB
C#
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Options;
|
|
using Schaad.OpenData.Traffic.Geometry;
|
|
using Schaad.OpenData.Traffic.Source;
|
|
using Schaad.OpenData.Traffic.Storage;
|
|
|
|
namespace Schaad.OpenData.Traffic;
|
|
|
|
public static class TrafficServiceCollectionExtensions
|
|
{
|
|
private const string UserAgent = "OpenDataVisualizer/1.0";
|
|
|
|
public static IServiceCollection AddTraffic(this IServiceCollection services, IConfiguration configuration)
|
|
{
|
|
services.Configure<TrafficOptions>(configuration.GetSection(TrafficOptions.SectionName));
|
|
services.AddSingleton(TimeProvider.System);
|
|
services.AddSingleton<TrafficDataStore>();
|
|
services.AddSingleton<TrafficCacheStorage>();
|
|
services.AddSingleton<StationGeometryService>();
|
|
services.AddSingleton<TrafficRefresher>();
|
|
services.AddHostedService<TrafficRefreshService>();
|
|
|
|
services.AddHttpClient<ThurgauTrafficClient>(client =>
|
|
{
|
|
client.Timeout = TimeSpan.FromMinutes(5);
|
|
client.DefaultRequestHeaders.UserAgent.ParseAdd(UserAgent);
|
|
});
|
|
services.AddHttpClient<SwisstopoClient>((provider, client) =>
|
|
{
|
|
client.BaseAddress = new Uri(provider.GetRequiredService<IOptions<TrafficOptions>>().Value.SwisstopoBaseUrl);
|
|
client.Timeout = TimeSpan.FromSeconds(30);
|
|
client.DefaultRequestHeaders.UserAgent.ParseAdd(UserAgent);
|
|
});
|
|
|
|
return services;
|
|
}
|
|
}
|