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>
75 lines
2.4 KiB
C#
75 lines
2.4 KiB
C#
using Schaad.OpenData.Traffic.Analysis;
|
|
using Schaad.OpenData.Traffic.Storage;
|
|
|
|
namespace Schaad.OpenData.Tests;
|
|
|
|
public class TrafficAnalysisTestShould
|
|
{
|
|
private static readonly DateOnly Friday = new(2026, 10, 30);
|
|
private static readonly DateOnly Saturday = new(2026, 10, 31);
|
|
private static readonly DateOnly Sunday = new(2026, 11, 1);
|
|
|
|
private static TrafficSnapshot Snapshot() => new(
|
|
[TestData.Station(7, "nach A", "nach B")],
|
|
[
|
|
TestData.Count(7, "nach A", Friday, 8, 100, 10),
|
|
TestData.Count(7, "nach B", Friday, 8, 50),
|
|
TestData.Count(7, "nach A", Saturday, 8, 40),
|
|
TestData.Count(7, "nach A", Sunday, 8, 20),
|
|
],
|
|
[],
|
|
null);
|
|
|
|
[Fact]
|
|
public void ReturnTwentyFourHoursPerDirectionWhenBuildingDay()
|
|
{
|
|
var day = TrafficAnalysis.BuildDay(Snapshot(), Friday)!;
|
|
|
|
var directions = day.Stations.ShouldHaveSingleItem().Directions;
|
|
directions.Count.ShouldBe(2);
|
|
directions[0].Hours.Count.ShouldBe(24);
|
|
directions[0].Hours[8]![2].ShouldBe(100);
|
|
directions[0].Hours[9].ShouldBeNull();
|
|
}
|
|
|
|
[Fact]
|
|
public void ReturnNullWhenBuildingDayWithoutData()
|
|
{
|
|
TrafficAnalysis.BuildDay(Snapshot(), new DateOnly(2020, 1, 1)).ShouldBeNull();
|
|
}
|
|
|
|
[Fact]
|
|
public void SeparateWeekdayAndWeekendWhenBuildingProfiles()
|
|
{
|
|
var summary = TrafficAnalysis.BuildStationSummary(Snapshot(), 7, null, null)!;
|
|
|
|
var directionA = summary.Directions[0];
|
|
directionA.WeekdayProfile[8].ShouldBe(110);
|
|
directionA.WeekendProfile[8].ShouldBe(30);
|
|
directionA.WeekdayProfile[3].ShouldBe(0);
|
|
}
|
|
|
|
[Fact]
|
|
public void SumAllClassesAndDirectionsWhenBuildingClassTotals()
|
|
{
|
|
var summary = TrafficAnalysis.BuildStationSummary(Snapshot(), 7, null, null)!;
|
|
|
|
summary.ClassTotals[2].ShouldBe(210);
|
|
summary.ClassTotals[7].ShouldBe(10);
|
|
}
|
|
|
|
[Fact]
|
|
public void LimitToDateRangeWhenBuildingSummary()
|
|
{
|
|
var summary = TrafficAnalysis.BuildStationSummary(Snapshot(), 7, Saturday, Sunday)!;
|
|
|
|
summary.Directions[0].Daily.Select(d => d.Date).ShouldBe([Saturday, Sunday]);
|
|
summary.Directions[1].Hourly.ShouldBeEmpty();
|
|
}
|
|
|
|
[Fact]
|
|
public void ReturnNullWhenStationIsUnknown()
|
|
{
|
|
TrafficAnalysis.BuildStationSummary(Snapshot(), 999, null, null).ShouldBeNull();
|
|
}
|
|
}
|