Update
This commit is contained in:
@@ -105,9 +105,20 @@ public sealed class ConsoleReportRenderer
|
||||
var stateChanges = events.Count(e => e.EventType == ReplayEventType.StateChange);
|
||||
|
||||
var parts = new List<string>();
|
||||
if (decisions > 0) parts.Add($"{decisions} decision(s)");
|
||||
if (stateChanges > 0) parts.Add($"{stateChanges} state change(s)");
|
||||
if (warnings > 0) parts.Add($"{warnings} warning(s)");
|
||||
if (decisions > 0)
|
||||
{
|
||||
parts.Add($"{decisions} decision(s)");
|
||||
}
|
||||
|
||||
if (stateChanges > 0)
|
||||
{
|
||||
parts.Add($"{stateChanges} state change(s)");
|
||||
}
|
||||
|
||||
if (warnings > 0)
|
||||
{
|
||||
parts.Add($"{warnings} warning(s)");
|
||||
}
|
||||
|
||||
if (parts.Count > 0)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace HomeAssistant.HistoryReplay.Reporting;
|
||||
|
||||
public sealed class ReplayDataPoint
|
||||
{
|
||||
public required DateTimeOffset Timestamp { get; init; }
|
||||
public required string Monitor { get; init; }
|
||||
public required string Series { get; init; }
|
||||
public required double Value { get; init; }
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace HomeAssistant.HistoryReplay.Reporting;
|
||||
|
||||
public sealed class ReplayDataSeries
|
||||
{
|
||||
private readonly ConcurrentBag<ReplayDataPoint> _points = [];
|
||||
|
||||
public void AddPoint(ReplayDataPoint point)
|
||||
{
|
||||
_points.Add(point);
|
||||
}
|
||||
|
||||
public void AddPoint(string monitor, string series, DateTimeOffset timestamp, double value)
|
||||
{
|
||||
_points.Add(new ReplayDataPoint
|
||||
{
|
||||
Monitor = monitor,
|
||||
Series = series,
|
||||
Timestamp = timestamp,
|
||||
Value = value
|
||||
});
|
||||
}
|
||||
|
||||
public IReadOnlyList<ReplayDataPoint> GetSeries(string monitor, string series) =>
|
||||
_points
|
||||
.Where(p => string.Equals(p.Monitor, monitor, StringComparison.OrdinalIgnoreCase)
|
||||
&& string.Equals(p.Series, series, StringComparison.OrdinalIgnoreCase))
|
||||
.OrderBy(p => p.Timestamp)
|
||||
.ToList();
|
||||
|
||||
public IReadOnlyList<ReplayDataPoint> GetAllForMonitor(string monitor) =>
|
||||
_points
|
||||
.Where(p => string.Equals(p.Monitor, monitor, StringComparison.OrdinalIgnoreCase))
|
||||
.OrderBy(p => p.Timestamp)
|
||||
.ToList();
|
||||
|
||||
public IReadOnlyList<string> GetSeriesNames(string monitor) =>
|
||||
_points
|
||||
.Where(p => string.Equals(p.Monitor, monitor, StringComparison.OrdinalIgnoreCase))
|
||||
.Select(p => p.Series)
|
||||
.Distinct(StringComparer.OrdinalIgnoreCase)
|
||||
.Order()
|
||||
.ToList();
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
_points.Clear();
|
||||
}
|
||||
}
|
||||
@@ -22,4 +22,9 @@ public sealed class ReplayTimeline
|
||||
|
||||
public IReadOnlyList<string> GetMonitors() =>
|
||||
_events.Select(e => e.Monitor).Distinct(StringComparer.OrdinalIgnoreCase).Order().ToList();
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
_events.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user