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>
61 lines
2.2 KiB
C#
61 lines
2.2 KiB
C#
using Schaad.OpenData.Traffic.Models;
|
|
using Schaad.OpenData.Traffic.Storage;
|
|
|
|
namespace Schaad.OpenData.Tests;
|
|
|
|
public class TrafficSnapshotTestShould
|
|
{
|
|
private static readonly DateOnly Monday = new(2026, 10, 26);
|
|
private static readonly DateOnly Tuesday = new(2026, 10, 27);
|
|
private static readonly DateTimeOffset RefreshedAt = new(2026, 11, 6, 12, 0, 0, TimeSpan.Zero);
|
|
|
|
[Fact]
|
|
public void ReplaceImportedDaysWhenMerging()
|
|
{
|
|
var snapshot = new TrafficSnapshot(
|
|
[TestData.Station(1, "nach A")],
|
|
[TestData.Count(1, "nach A", Tuesday, 8, 10), TestData.Count(1, "nach A", Tuesday, 9, 20)],
|
|
[],
|
|
null);
|
|
var import = new TrafficImport([TestData.Station(1, "nach A")], [TestData.Count(1, "nach A", Tuesday, 8, 99)]);
|
|
|
|
var merged = snapshot.Merge(import, RefreshedAt, out var changedDays);
|
|
|
|
merged.CountsByDate[Tuesday].ShouldHaveSingleItem().Counts.Car.ShouldBe(99);
|
|
changedDays.ShouldBe([Tuesday]);
|
|
merged.LastRefresh.ShouldBe(RefreshedAt);
|
|
}
|
|
|
|
[Fact]
|
|
public void KeepDaysMissingInImportWhenMerging()
|
|
{
|
|
var snapshot = new TrafficSnapshot([TestData.Station(1, "nach A")], [TestData.Count(1, "nach A", Monday, 8, 10)], [], null);
|
|
var import = new TrafficImport([], [TestData.Count(1, "nach A", Tuesday, 8, 20)]);
|
|
|
|
var merged = snapshot.Merge(import, RefreshedAt, out _);
|
|
|
|
merged.Dates.ShouldBe([Monday, Tuesday]);
|
|
merged.Stations.Keys.ShouldContain(1);
|
|
}
|
|
|
|
[Fact]
|
|
public void KeepGeometryWhenMerging()
|
|
{
|
|
var geometry = new StationGeometry(1, true, []);
|
|
var snapshot = new TrafficSnapshot([TestData.Station(1, "nach A")], [], [geometry], null);
|
|
|
|
var merged = snapshot.Merge(new TrafficImport([TestData.Station(1, "nach A")], []), RefreshedAt, out _);
|
|
|
|
merged.Geometry[1].ShouldBeSameAs(geometry);
|
|
}
|
|
|
|
[Fact]
|
|
public void ReplaceStationGeometryWhenAddingGeometry()
|
|
{
|
|
var snapshot = new TrafficSnapshot([TestData.Station(1, "nach A")], [], [new StationGeometry(1, false, [])], null);
|
|
|
|
var updated = snapshot.WithGeometry([new StationGeometry(1, true, [])]);
|
|
|
|
updated.Geometry[1].FollowsRoad.ShouldBeTrue();
|
|
}
|
|
}
|