- 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>
32 lines
1.2 KiB
C#
32 lines
1.2 KiB
C#
using System.Text.Json;
|
|
using Microsoft.Extensions.Options;
|
|
using Schaad.OpenData.Traffic.Models;
|
|
|
|
namespace Schaad.OpenData.Traffic.Source;
|
|
|
|
public class ThurgauTrafficClient(HttpClient httpClient, IOptions<TrafficOptions> options)
|
|
{
|
|
public virtual async Task<TrafficImport> FetchAsync(DateOnly? since, CancellationToken cancellationToken)
|
|
{
|
|
var url = options.Value.SourceUrl;
|
|
if (since is { } from)
|
|
{
|
|
url += "?where=" + Uri.EscapeDataString($"datum >= date'{from:yyyy-MM-dd}'");
|
|
}
|
|
|
|
using var response = await httpClient.GetAsync(url, HttpCompletionOption.ResponseHeadersRead, cancellationToken);
|
|
response.EnsureSuccessStatusCode();
|
|
await using var stream = await response.Content.ReadAsStreamAsync(cancellationToken);
|
|
|
|
var records = new List<ThurgauTrafficRecord>();
|
|
await foreach (var record in JsonSerializer.DeserializeAsyncEnumerable<ThurgauTrafficRecord>(stream, cancellationToken: cancellationToken))
|
|
{
|
|
if (record is not null)
|
|
{
|
|
records.Add(record);
|
|
}
|
|
}
|
|
|
|
return ThurgauTrafficMapper.Map(records);
|
|
}
|
|
}
|