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
@@ -16,16 +16,20 @@ public sealed class NordPoolReplayRunner : IMonitorReplayRunner
private readonly HistoryTimeline _timeline;
private readonly ReplayTimeProvider _timeProvider;
private readonly ReplayTimeline _replayTimeline;
private readonly ReplayDataSeries _dataSeries;
private readonly ICheapestIntervalsFinder _cheapestIntervalsFinder;
private readonly ILogger<NordPoolReplayRunner> _logger;
private readonly ReplayOptions _options;
private const string NordPoolHaSensorId = "sensor.nordpool_kwh_lt_eur_3_10_0";
public string MonitorName => "NordPool";
public NordPoolReplayRunner(
HistoryTimeline timeline,
ReplayTimeProvider timeProvider,
ReplayTimeline replayTimeline,
ReplayDataSeries dataSeries,
ICheapestIntervalsFinder cheapestIntervalsFinder,
ILogger<NordPoolReplayRunner> logger,
IOptions<ReplayOptions> options)
@@ -33,6 +37,7 @@ public sealed class NordPoolReplayRunner : IMonitorReplayRunner
_timeline = timeline;
_timeProvider = timeProvider;
_replayTimeline = replayTimeline;
_dataSeries = dataSeries;
_cheapestIntervalsFinder = cheapestIntervalsFinder;
_logger = logger;
_options = options.Value;
@@ -50,11 +55,15 @@ public sealed class NordPoolReplayRunner : IMonitorReplayRunner
{
_timeProvider.AdvanceTo(currentTime);
var priceEntry = _timeline.GetStateAt(NordPoolConsts.CurrentPriceEntityId, currentTime);
var priceEntry = _timeline.GetStateAt(NordPoolHaSensorId, currentTime)
?? _timeline.GetStateAt(NordPoolConsts.CurrentPriceEntityId, currentTime);
if (priceEntry?.State is not null &&
double.TryParse(priceEntry.State, CultureInfo.InvariantCulture, out var currentPrice))
{
if (lastReportedPrice is null || Math.Abs(currentPrice - lastReportedPrice.Value) > 0.001)
_dataSeries.AddPoint(MonitorName, "Price", currentTime, currentPrice);
if (lastReportedPrice is null || Math.Abs(currentPrice - lastReportedPrice.Value) > 0.01)
{
_replayTimeline.AddEvent(new ReplayEvent
{
@@ -84,6 +93,8 @@ public sealed class NordPoolReplayRunner : IMonitorReplayRunner
var isNowCheap = _cheapestIntervalsFinder.IsCurrentIntervalCheap(
cheapest, currentTime.LocalDateTime);
_dataSeries.AddPoint(MonitorName, "IsCheap", currentTime, isNowCheap ? 1.0 : 0.0);
if (isNowCheap)
{
var currentInterval = cheapest.FirstOrDefault(i =>