This commit is contained in:
2026-06-28 13:58:35 +03:00
parent 8f45028715
commit e6bf8258bb
114 changed files with 4365 additions and 874 deletions
@@ -14,6 +14,7 @@ public sealed class LightReplayRunner : IMonitorReplayRunner
private readonly HistoryTimeline _timeline;
private readonly ReplayTimeProvider _timeProvider;
private readonly ReplayTimeline _replayTimeline;
private readonly ReplayDataSeries _dataSeries;
private readonly ILogger<LightReplayRunner> _logger;
private readonly ReplayOptions _replayOptions;
private readonly LightMonitorOptions _lightOptions;
@@ -24,6 +25,7 @@ public sealed class LightReplayRunner : IMonitorReplayRunner
HistoryTimeline timeline,
ReplayTimeProvider timeProvider,
ReplayTimeline replayTimeline,
ReplayDataSeries dataSeries,
ILogger<LightReplayRunner> logger,
IOptions<ReplayOptions> replayOptions,
IOptions<LightMonitorOptions> lightOptions)
@@ -31,6 +33,7 @@ public sealed class LightReplayRunner : IMonitorReplayRunner
_timeline = timeline;
_timeProvider = timeProvider;
_replayTimeline = replayTimeline;
_dataSeries = dataSeries;
_logger = logger;
_replayOptions = replayOptions.Value;
_lightOptions = lightOptions.Value;
@@ -54,14 +57,20 @@ public sealed class LightReplayRunner : IMonitorReplayRunner
foreach (var entry in sunHistory)
{
if (cancellationToken.IsCancellationRequested) break;
if (cancellationToken.IsCancellationRequested)
{
break;
}
if (entry.LastChanged < _replayOptions.StartTime || entry.LastChanged > _replayOptions.EndTime)
{
continue;
}
if (string.Equals(entry.State, LightMonitorConsts.SunBelowHorizon, StringComparison.OrdinalIgnoreCase) &&
var isBelowHorizon = string.Equals(entry.State, LightMonitorConsts.SunBelowHorizon, StringComparison.OrdinalIgnoreCase);
_dataSeries.AddPoint(MonitorName, "SunBelowHorizon", entry.LastChanged, isBelowHorizon ? 1.0 : 0.0);
if (isBelowHorizon &&
!string.Equals(previousSunState, LightMonitorConsts.SunBelowHorizon, StringComparison.OrdinalIgnoreCase))
{
_timeProvider.AdvanceTo(entry.LastChanged);
@@ -72,6 +81,7 @@ public sealed class LightReplayRunner : IMonitorReplayRunner
if (anyoneHome && !lightAlreadyOn)
{
_dataSeries.AddPoint(MonitorName, "LightOn", entry.LastChanged, 1.0);
_replayTimeline.AddEvent(new ReplayEvent
{
Timestamp = entry.LastChanged,
@@ -87,7 +97,7 @@ public sealed class LightReplayRunner : IMonitorReplayRunner
Timestamp = entry.LastChanged,
Monitor = MonitorName,
EventType = ReplayEventType.Info,
Message = "Sun below horizon but nobody home — light stays off"
Message = "Sun below horizon but nobody home -- light stays off"
});
}
else
@@ -115,7 +125,10 @@ public sealed class LightReplayRunner : IMonitorReplayRunner
foreach (var entry in personHistory)
{
if (cancellationToken.IsCancellationRequested) break;
if (cancellationToken.IsCancellationRequested)
{
break;
}
if (entry.LastChanged < _replayOptions.StartTime || entry.LastChanged > _replayOptions.EndTime)
{
@@ -134,6 +147,7 @@ public sealed class LightReplayRunner : IMonitorReplayRunner
if (isDark && !lightAlreadyOn)
{
_dataSeries.AddPoint(MonitorName, "LightOn", entry.LastChanged, 1.0);
_replayTimeline.AddEvent(new ReplayEvent
{
Timestamp = entry.LastChanged,
@@ -169,7 +183,6 @@ public sealed class LightReplayRunner : IMonitorReplayRunner
return true;
}
}
return false;
}
}