feature: Explainable Alerts

This commit is contained in:
voltsrage
2026-06-25 00:25:31 +08:00
parent 279add1e45
commit 666d683d67
61 changed files with 9553 additions and 125 deletions
@@ -0,0 +1,26 @@
public static class TrendContextBuilder
{
public static TrendContext? BuildContext(
string observationCode,
IReadOnlyList<TrendHistoryEntry> history,
decimal currentValue)
{
if (history.Count < 2) return null;
var oldest = history.First();
var newest = history.Last();
var duration = newest.RecordedAt - oldest.RecordedAt;
if (duration <= TimeSpan.Zero || oldest.Value == 0) return null;
var pctChange = (double)((newest.Value - oldest.Value) / oldest.Value * 100m);
var direction = pctChange >= 0 ? "Increasing" : "Decreasing";
return new TrendContext
{
Parameter = TrendCalculator.DisplayName(observationCode),
PercentChange = Math.Round(Math.Abs(pctChange), 1),
Duration = duration,
Direction = direction
};
}
}