Browse Source

add special case to multiple playout mode (#298)

pull/299/head
Jason Dove 5 years ago committed by GitHub
parent
commit
d9457c01e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      CHANGELOG.md
  2. 4
      ErsatzTV.Application/ProgramSchedules/Commands/ProgramScheduleItemCommandBase.cs
  3. 90
      ErsatzTV.Core.Tests/Scheduling/PlayoutBuilderTests.cs
  4. 11
      ErsatzTV.Core/Scheduling/PlayoutBuilder.cs
  5. 2
      ErsatzTV/Pages/ScheduleItemsEditor.razor
  6. 2
      ErsatzTV/Validators/ProgramScheduleItemEditViewModelValidator.cs

3
CHANGELOG.md

@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). @@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
## [Unreleased]
### Added
- Include audio language metadata in all streaming modes
- Add special zero-count case to `Multiple` playout mode
- This configuration will automatically maintain the multiple count so that it is equal to the number of items in the collection
- This configuration should be used if you want to play every item in a collection exactly once before advancing
### Changed
- Use case-insensitive sorting for collections page and `Add to Collection` dialog

4
ErsatzTV.Application/ProgramSchedules/Commands/ProgramScheduleItemCommandBase.cs

@ -30,9 +30,9 @@ namespace ErsatzTV.Application.ProgramSchedules.Commands @@ -30,9 +30,9 @@ namespace ErsatzTV.Application.ProgramSchedules.Commands
case PlayoutMode.One:
break;
case PlayoutMode.Multiple:
if (item.MultipleCount.GetValueOrDefault() <= 0)
if (item.MultipleCount.GetValueOrDefault() < 0)
{
return BaseError.New("[MultipleCount] must be greater than 0 for playout mode 'multiple'");
return BaseError.New("[MultipleCount] must be greater than or equal to 0 for playout mode 'multiple'");
}
break;

90
ErsatzTV.Core.Tests/Scheduling/PlayoutBuilderTests.cs

@ -905,6 +905,96 @@ namespace ErsatzTV.Core.Tests.Scheduling @@ -905,6 +905,96 @@ namespace ErsatzTV.Core.Tests.Scheduling
result.Anchor.MultipleRemaining.Should().Be(1);
}
[Test]
public async Task Auto_Zero_MultipleCount()
{
var collectionOne = new Collection
{
Id = 1,
Name = "Multiple Items 1",
MediaItems = new List<MediaItem>
{
TestMovie(1, TimeSpan.FromHours(1), new DateTime(2020, 1, 1)),
TestMovie(2, TimeSpan.FromHours(1), new DateTime(2020, 1, 1)),
TestMovie(3, TimeSpan.FromHours(1), new DateTime(2020, 1, 1))
}
};
var collectionTwo = new Collection
{
Id = 2,
Name = "Multiple Items 2",
MediaItems = new List<MediaItem>
{
TestMovie(4, TimeSpan.FromHours(1), new DateTime(2020, 1, 1)),
TestMovie(5, TimeSpan.FromHours(1), new DateTime(2020, 1, 1)),
}
};
var fakeRepository = new FakeMediaCollectionRepository(
Map(
(collectionOne.Id, collectionOne.MediaItems.ToList()),
(collectionTwo.Id, collectionTwo.MediaItems.ToList())));
var items = new List<ProgramScheduleItem>
{
new ProgramScheduleItemMultiple
{
Id = 1,
Index = 1,
Collection = collectionOne,
CollectionId = collectionOne.Id,
StartTime = null,
Count = 0
},
new ProgramScheduleItemMultiple
{
Id = 2,
Index = 2,
Collection = collectionTwo,
CollectionId = collectionTwo.Id,
StartTime = null,
Count = 0
}
};
var playout = new Playout
{
ProgramSchedule = new ProgramSchedule
{
Items = items,
MediaCollectionPlaybackOrder = PlaybackOrder.Chronological
},
Channel = new Channel(Guid.Empty) { Id = 1, Name = "Test Channel" },
};
var televisionRepo = new FakeTelevisionRepository();
var artistRepo = new Mock<IArtistRepository>();
var builder = new PlayoutBuilder(fakeRepository, televisionRepo, artistRepo.Object, _logger);
DateTimeOffset start = HoursAfterMidnight(0);
DateTimeOffset finish = start + TimeSpan.FromHours(5);
Playout result = await builder.BuildPlayoutItems(playout, start, finish);
result.Items.Count.Should().Be(5);
result.Items[0].StartOffset.TimeOfDay.Should().Be(TimeSpan.FromHours(0));
result.Items[0].MediaItemId.Should().Be(1);
result.Items[1].StartOffset.TimeOfDay.Should().Be(TimeSpan.FromHours(1));
result.Items[1].MediaItemId.Should().Be(2);
result.Items[2].StartOffset.TimeOfDay.Should().Be(TimeSpan.FromHours(2));
result.Items[2].MediaItemId.Should().Be(3);
result.Items[3].StartOffset.TimeOfDay.Should().Be(TimeSpan.FromHours(3));
result.Items[3].MediaItemId.Should().Be(4);
result.Items[4].StartOffset.TimeOfDay.Should().Be(TimeSpan.FromHours(4));
result.Items[4].MediaItemId.Should().Be(5);
result.Anchor.NextScheduleItem.Should().Be(items[0]);
result.Anchor.MultipleRemaining.Should().BeNull();
}
[Test]
public async Task Alternating_Duration_Should_Maintain_Duration()
{

11
ErsatzTV.Core/Scheduling/PlayoutBuilder.cs

@ -270,7 +270,16 @@ namespace ErsatzTV.Core.Scheduling @@ -270,7 +270,16 @@ namespace ErsatzTV.Core.Scheduling
case ProgramScheduleItemMultiple multiple:
if (multipleRemaining.IsNone)
{
multipleRemaining = multiple.Count;
if (multiple.Count == 0)
{
multipleRemaining = collectionMediaItems[CollectionKeyForItem(scheduleItem)]
.Count;
}
else
{
multipleRemaining = multiple.Count;
}
customGroup = true;
}

2
ErsatzTV/Pages/ScheduleItemsEditor.razor

@ -164,7 +164,7 @@ @@ -164,7 +164,7 @@
<MudText Class="mt-3 mb-2" Typo="Typo.h6">Playout Mode</MudText>
<ul class="mud-typography-body1">
<li><b>One</b> - to play one media item from the collection before advancing to the next schedule item.</li>
<li><b>Multiple</b> - to play a specified <b>count</b> of media items from the collection before advancing to the next schedule item.</li>
<li><b>Multiple</b> - to play a specified <b>count</b> of media items from the collection before advancing to the next schedule item. A count of <b>0</b> is a special case that will automatically and always equal the number of items in the collection, so each item from the collection will be played once before advancing.</li>
<li><b>Duration</b> - to play the maximum number of complete media items that will fit in the specified <b>playout duration</b>, before either going offline for the remainder of the <b>playout duration</b> (an <b>offline tail</b>), or immediately advancing to the next schedule item.</li>
<li><b>Flood</b> - to play media items from the collection forever, or until the next schedule item's <b>start time</b> if one exists.</li>
</ul>

2
ErsatzTV/Validators/ProgramScheduleItemEditViewModelValidator.cs

@ -13,7 +13,7 @@ namespace ErsatzTV.Validators @@ -13,7 +13,7 @@ namespace ErsatzTV.Validators
() => RuleFor(i => i.StartTime).NotNull());
When(
i => i.PlayoutMode == PlayoutMode.Multiple,
() => RuleFor(i => i.MultipleCount).NotNull().GreaterThan(0));
() => RuleFor(i => i.MultipleCount).NotNull().GreaterThanOrEqualTo(0));
When(
i => i.PlayoutMode == PlayoutMode.Duration,
() => RuleFor(i => i.PlayoutDuration).NotNull());

Loading…
Cancel
Save