using Schaad.OpenData.Weather.Analysis; using Schaad.OpenData.Weather.Storage; using static Schaad.OpenData.Tests.WeatherTestData; namespace Schaad.OpenData.Tests; public class WeatherAnalysisTestShould { [Fact] public void SummarizeLastHourAndDayWhenBuildingStations() { var snapshot = new WeatherSnapshot( [Station(), Station("STK", "Steckborn")], [ Reading("GUT", Now.AddDays(-2), temperature: -5, precipitation: 9), Reading("GUT", Now.AddHours(-20), temperature: 3, precipitation: 1.2, windGust: 61), Reading("GUT", Now.AddMinutes(-50), temperature: 7, precipitation: 0.3), Reading("GUT", Now.AddMinutes(-10), temperature: 8.6, precipitation: 0.1, windGust: 50.8), Reading("GUT", Now, temperature: 8.4, precipitation: 0, windGust: null), ], Now, Now); var stations = WeatherAnalysis.BuildStations(snapshot); stations.Select(s => s.Abbr).ShouldBe(["GUT", "STK"]); var gut = stations[0]; gut.Time.ShouldBe(Now); gut.Temperature.ShouldBe(8.4); gut.WindGust.ShouldBe(50.8); gut.Precipitation1h.ShouldBe(0.4); gut.Precipitation24h.ShouldBe(1.6); gut.TemperatureMin24h.ShouldBe(3); gut.TemperatureMax24h.ShouldBe(8.6); gut.WindGustMax24h.ShouldBe(61); gut.HistoryFrom.ShouldBe(Now.AddDays(-2)); var stk = stations[1]; stk.Time.ShouldBeNull(); stk.Precipitation24h.ShouldBeNull(); } [Fact] public void ReturnReadingsOfStationSinceStartWhenBuildingHistory() { var snapshot = new WeatherSnapshot( [Station()], [Reading("GUT", Now.AddDays(-8)), Reading("GUT", Now.AddDays(-1), temperature: 5), Reading("STK", Now)], Now, Now); var history = WeatherAnalysis.BuildHistory(snapshot, "GUT", Now.AddDays(-7)); history.ShouldBe([new WeatherHistoryPoint(Now.AddDays(-1), 5, 0, 10, 20)]); } }