- 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>
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();
|
|
}
|
|
}
|