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>
62 lines
1.9 KiB
C#
62 lines
1.9 KiB
C#
using Schaad.OpenData.Traffic.Source;
|
|
|
|
namespace Schaad.OpenData.Tests;
|
|
|
|
public class ThurgauTrafficMapperTestShould
|
|
{
|
|
[Fact]
|
|
public void CreateOneStationWithAllDirectionsWhenRecordsShareTheStationCode()
|
|
{
|
|
var import = ThurgauTrafficMapper.Map([
|
|
TestData.Record(direction: "nach Diessenhofen"),
|
|
TestData.Record(direction: "nach Wagenhausen"),
|
|
TestData.Record(direction: "nach Diessenhofen", hour: 14),
|
|
]);
|
|
|
|
import.Stations.Count.ShouldBe(1);
|
|
import.Stations[0].Directions.ShouldBe(["nach Diessenhofen", "nach Wagenhausen"]);
|
|
import.Counts.Count.ShouldBe(3);
|
|
}
|
|
|
|
[Fact]
|
|
public void MapVehicleClassesWhenRecordIsValid()
|
|
{
|
|
var count = ThurgauTrafficMapper.Map([TestData.Record()]).Counts.Single();
|
|
|
|
count.Date.ShouldBe(new DateOnly(2026, 10, 27));
|
|
count.Hour.ShouldBe(13);
|
|
count.Counts.Car.ShouldBe(220);
|
|
count.Counts.Truck.ShouldBe(6);
|
|
count.Counts.Total.ShouldBe(1 + 12 + 220 + 6 + 5);
|
|
}
|
|
|
|
[Fact]
|
|
public void TreatMissingClassCountsAsZeroWhenMapping()
|
|
{
|
|
var count = ThurgauTrafficMapper.Map([TestData.Record(cars: null)]).Counts.Single();
|
|
|
|
count.Counts.Car.ShouldBe(0);
|
|
}
|
|
|
|
[Fact]
|
|
public void SkipRecordWhenDateIsInvalid()
|
|
{
|
|
ThurgauTrafficMapper.Map([TestData.Record(date: "unknown")]).Counts.ShouldBeEmpty();
|
|
}
|
|
|
|
[Fact]
|
|
public void CollapseWhitespaceWhenMappingStationName()
|
|
{
|
|
var station = ThurgauTrafficMapper.Map([TestData.Record()]).Stations.Single();
|
|
|
|
station.Name.ShouldBe("WAGENHAUSEN Wagenhausen - Diessenhofen");
|
|
}
|
|
|
|
[Fact]
|
|
public void AcceptTimestampWhenDateContainsTime()
|
|
{
|
|
var count = ThurgauTrafficMapper.Map([TestData.Record(date: "2026-10-27T00:00:00+00:00")]).Counts.Single();
|
|
|
|
count.Date.ShouldBe(new DateOnly(2026, 10, 27));
|
|
}
|
|
}
|