Refactor GridScheduleGenerator and related components to improve cursor management and group handling
ci / build-backend (push) Successful in 1m17s
ci / build-frontend (push) Successful in 56s
ci / tests (push) Successful in 1m29s
ci / sonar (push) Successful in 3m34s

Updated the GridScheduleGenerator to reset cursors for slots with no aired positions, ensuring proper state management during rebuilds. Introduced a new method, ResetUnairedCursorsAsync, to handle cursor resets effectively. Enhanced the handling of interstitial groups in the scheduling process, preventing them from being included in slots or fallback groups. Updated related tests to verify the correct behavior of these changes, ensuring robust scheduling logic and accurate group categorization.
This commit is contained in:
Leonid Pershin
2026-07-30 09:55:14 +03:00
parent 5032614773
commit 398b60facc
14 changed files with 317 additions and 31 deletions
@@ -559,6 +559,37 @@ public class SchedulePlannerTests
Assert.Contains(result.Items, i => i.SlotId == background.SlotId);
}
[Fact]
public void Pad_CapCountsWholeSeam_WhenBackgroundHasNothingToPlay()
{
// Часовая дыра и пустой фоновый слой: добор до якоря и остаток перед ним сходятся встык,
// и без общего потолка в эфир ушло бы двадцать минут рекламы подряд вместо десяти.
var result = Run(
Input(
[Slot(T0.AddHours(1), 30, [Element(1, 30)], isAnchor: true)],
horizonHours: 2,
pad: [Ad(5)],
maxPad: TimeSpan.FromMinutes(10)
)
);
// Считается самый длинный рекламный блок подряд: два добора по разные стороны от фона —
// это два шва, а сошедшиеся встык — один, и он потолком и ограничен.
var longest = TimeSpan.Zero;
var current = TimeSpan.Zero;
foreach (var item in result.Items.OrderBy(i => i.StartsAtUtc))
{
current =
item.Kind == PlannedItemKind.Ad
? current + (item.EndsAtUtc - item.StartsAtUtc)
: TimeSpan.Zero;
if (current > longest)
longest = current;
}
Assert.Equal(TimeSpan.FromMinutes(10), longest);
}
[Fact]
public void Pad_ClosesTailWhenProgrammeDoesNotFit()
{