feature: Explainable Alerts
This commit is contained in:
@@ -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
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user