[scheduling] Add a new mode RandomRotation that randomly picks an item from a randomly choosen group (show/artist) for block schedule (#1885)
* init * minor naming change * address to comments round 1 * update dependencies * formatting * make sure it rotates * update changelog --------- Co-authored-by: Jason Dove <1695733+jasongdove@users.noreply.github.com>
This commit is contained in:
@@ -43,7 +43,8 @@ public class BlockPlayoutBuilder(
|
||||
PlaybackOrder.Chronological,
|
||||
PlaybackOrder.SeasonEpisode,
|
||||
PlaybackOrder.Shuffle,
|
||||
PlaybackOrder.Random
|
||||
PlaybackOrder.Random,
|
||||
PlaybackOrder.RandomRotation
|
||||
];
|
||||
|
||||
DateTimeOffset start = DateTimeOffset.Now;
|
||||
@@ -264,6 +265,12 @@ public class BlockPlayoutBuilder(
|
||||
playout,
|
||||
blockItem,
|
||||
historyKey),
|
||||
PlaybackOrder.RandomRotation => BlockPlayoutEnumerator.RandomRotation(
|
||||
collectionItems,
|
||||
currentTime,
|
||||
playout,
|
||||
blockItem,
|
||||
historyKey),
|
||||
_ => new RandomizedMediaCollectionEnumerator(
|
||||
collectionItems,
|
||||
new CollectionEnumeratorState { Seed = new Random().Next(), Index = 0 })
|
||||
|
||||
@@ -137,4 +137,31 @@ public static class BlockPlayoutEnumerator
|
||||
// as long as already-played items are not included
|
||||
return new BlockPlayoutShuffledMediaCollectionEnumerator(mediaItems, state);
|
||||
}
|
||||
|
||||
public static IMediaCollectionEnumerator RandomRotation(
|
||||
List<MediaItem> collectionItems,
|
||||
DateTimeOffset currentTime,
|
||||
Playout playout,
|
||||
BlockItem blockItem,
|
||||
string historyKey)
|
||||
{
|
||||
DateTime historyTime = currentTime.UtcDateTime;
|
||||
Option<PlayoutHistory> maybeHistory = playout.PlayoutHistory
|
||||
.Filter(h => h.BlockId == blockItem.BlockId)
|
||||
.Filter(h => h.Key == historyKey)
|
||||
.Filter(h => h.When < historyTime)
|
||||
.OrderByDescending(h => h.When)
|
||||
.HeadOrNone();
|
||||
|
||||
var state = new CollectionEnumeratorState { Seed = playout.Seed + blockItem.BlockId, Index = 0 };
|
||||
foreach (PlayoutHistory h in maybeHistory)
|
||||
{
|
||||
// Make sure to only increase the index by 1 since we can only
|
||||
// guarantee the next one is a different show. h.Index comes from
|
||||
// the previous play item which already increased by 1.
|
||||
state.Index = h.Index;
|
||||
}
|
||||
|
||||
return new RandomizedRotatingMediaCollectionEnumerator(collectionItems, state);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user