Browse Source

add matched_points to filler expression (#2148)

pull/2149/head
Jason Dove 1 month ago committed by GitHub
parent
commit
39b107eb0f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 1
      CHANGELOG.md
  2. 44
      ErsatzTV.Core.Tests/Scheduling/FillerExpressionTests.cs
  3. 4
      ErsatzTV.Core/Scheduling/FillerExpression.cs
  4. 2
      ErsatzTV/Pages/FillerPresetEditor.razor

1
CHANGELOG.md

@ -66,6 +66,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Add `Expression` for mid-roll filler to allow custom logic for using or skipping chapter markers - Add `Expression` for mid-roll filler to allow custom logic for using or skipping chapter markers
- The following parameters can be used: - The following parameters can be used:
- `total_points`: total number of potential mid-roll points - `total_points`: total number of potential mid-roll points
- `matched_points`: number of mid-roll points that have already matched the expression
- `total_duration`: total duration of the content, in seconds - `total_duration`: total duration of the content, in seconds
- `total_progress`: normalized position from 0 to 1 - `total_progress`: normalized position from 0 to 1
- `last_mid_filler`: seconds since last mid-roll filler - `last_mid_filler`: seconds since last mid-roll filler

44
ErsatzTV.Core.Tests/Scheduling/FillerExpressionTests.cs

@ -0,0 +1,44 @@
using ErsatzTV.Core.Domain;
using ErsatzTV.Core.Domain.Filler;
using ErsatzTV.Core.Scheduling;
using NUnit.Framework;
using Shouldly;
namespace ErsatzTV.Core.Tests.Scheduling;
[TestFixture]
public class FillerExpressionTests
{
[Test]
public void Two_Points_In_30_Minute_Content()
{
// 30 min content
var playoutItem = new PlayoutItem { Start = DateTimeOffset.Now.UtcDateTime };
playoutItem.Finish = playoutItem.Start + TimeSpan.FromMinutes(30);
// chapters every 5 min
var chapters = new List<MediaChapter>
{
new() { ChapterId = 1, StartTime = TimeSpan.Zero, EndTime = TimeSpan.FromMinutes(5) },
new() { ChapterId = 2, StartTime = TimeSpan.FromMinutes(5), EndTime = TimeSpan.FromMinutes(10) },
new() { ChapterId = 3, StartTime = TimeSpan.FromMinutes(10), EndTime = TimeSpan.FromMinutes(15) },
new() { ChapterId = 4, StartTime = TimeSpan.FromMinutes(15), EndTime = TimeSpan.FromMinutes(20) },
new() { ChapterId = 5, StartTime = TimeSpan.FromMinutes(20), EndTime = TimeSpan.FromMinutes(25) },
new() { ChapterId = 6, StartTime = TimeSpan.FromMinutes(25), EndTime = TimeSpan.FromMinutes(30) }
};
// skip first 5 min of content, wait at least 5 min between points, only match up to 2 points
var fillerPreset = new FillerPreset
{
FillerKind = FillerKind.MidRoll,
Expression = "(point > 5 * 60) and (last_mid_filler > 5 * 60) and (matched_points < 2)"
};
List<MediaChapter> result = FillerExpression.FilterChapters(fillerPreset, chapters, playoutItem);
result.Count.ShouldBe(3);
result[0].EndTime.ShouldBe(TimeSpan.FromMinutes(10));
result[1].EndTime.ShouldBe(TimeSpan.FromMinutes(20));
result[2].EndTime.ShouldBe(TimeSpan.FromMinutes(30));
}
}

4
ErsatzTV.Core/Scheduling/FillerExpression.cs

@ -22,6 +22,7 @@ public static class FillerExpression
double lastFiller = start.TotalSeconds - 99999.0; double lastFiller = start.TotalSeconds - 99999.0;
double contentDuration = (playoutItem.FinishOffset - playoutItem.StartOffset).TotalSeconds; double contentDuration = (playoutItem.FinishOffset - playoutItem.StartOffset).TotalSeconds;
var matches = 0;
for (var index = 0; index < chapterPoints.Count; index++) for (var index = 0; index < chapterPoints.Count; index++)
{ {
@ -29,6 +30,7 @@ public static class FillerExpression
var expression = new Expression(fillerPreset.Expression); var expression = new Expression(fillerPreset.Expression);
int chapterNum = index + 1; int chapterNum = index + 1;
double sinceLastFiller = chapterPoint.TotalSeconds - lastFiller; double sinceLastFiller = chapterPoint.TotalSeconds - lastFiller;
int matchedPoints = matches;
expression.EvaluateParameter += (name, e) => expression.EvaluateParameter += (name, e) =>
{ {
e.Result = name switch e.Result = name switch
@ -38,6 +40,7 @@ public static class FillerExpression
"total_duration" => contentDuration, "total_duration" => contentDuration,
"total_progress" => chapterPoint.TotalSeconds / end.TotalSeconds, "total_progress" => chapterPoint.TotalSeconds / end.TotalSeconds,
"remaining_duration" => contentDuration - chapterPoint.TotalSeconds, "remaining_duration" => contentDuration - chapterPoint.TotalSeconds,
"matched_points" => matchedPoints,
"point" => chapterPoint.TotalSeconds, "point" => chapterPoint.TotalSeconds,
"num" => chapterNum, "num" => chapterNum,
_ => e.Result _ => e.Result
@ -46,6 +49,7 @@ public static class FillerExpression
if (expression.Evaluate() as bool? == true) if (expression.Evaluate() as bool? == true)
{ {
matches += 1;
lastFiller = chapterPoint.TotalSeconds; lastFiller = chapterPoint.TotalSeconds;
newChapters.Add(effectiveChapters[index]); newChapters.Add(effectiveChapters[index]);
} }

2
ErsatzTV/Pages/FillerPresetEditor.razor

@ -192,6 +192,8 @@
<MudText Typo="Typo.body2"> <MudText Typo="Typo.body2">
<span style="font-weight: bold;">total_points</span>: total number of potential mid-roll points <span style="font-weight: bold;">total_points</span>: total number of potential mid-roll points
<br /> <br />
<span style="font-weight: bold;">matched_points</span>: number of mid-roll points that have already matched the expression
<br />
<span style="font-weight: bold;">total_duration</span>: total duration of the content, in seconds <span style="font-weight: bold;">total_duration</span>: total duration of the content, in seconds
<br /> <br />
<span style="font-weight: bold;">total_progress</span>: normalized position from 0 to 1 <span style="font-weight: bold;">total_progress</span>: normalized position from 0 to 1

Loading…
Cancel
Save