mirror of
https://github.com/Cleanuparr/Cleanuparr.git
synced 2026-10-28 10:48:49 -04:00
changed gap strategy to search its largest gap unit
This commit is contained in:
1 parent
fea7e59669
commit
6759fe161d
3 files changed
+36
-3
No files matched your search
+22
@@ -1211,6 +1211,28 @@ public class SeekerUnitEvaluatorTests : IDisposable
|
||||
missingPicks.ShouldBeGreaterThan(600);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task SelectNext_CustomFormatGapWeighted_Sonarr_SearchesTheLargestGapUnit()
|
||||
{
|
||||
// Arrange
|
||||
SetupSonarr([Series(1)], []);
|
||||
await AddSonarrCustomFormatEntryAsync(episodeId: 20, currentScore: 5, cutoffScore: 10);
|
||||
await AddSonarrCustomFormatEntryAsync(episodeId: 21, currentScore: 0, cutoffScore: 30);
|
||||
SeekerEvaluation evaluation = await EvaluateSonarrAsync(InstanceConfig(_sonarr, c =>
|
||||
{
|
||||
c.UseCustomFormatScore = true;
|
||||
c.SonarrSearchMode = SonarrSearchMode.Episode;
|
||||
}));
|
||||
|
||||
// Act
|
||||
List<long> picked = Enumerable.Range(0, 50)
|
||||
.Select(_ => SeekerUnitEvaluator.SelectNext(evaluation, SelectionStrategy.CustomFormatGapWeighted, 1)[0].EpisodeId)
|
||||
.ToList();
|
||||
|
||||
// Assert
|
||||
picked.ShouldAllBe(id => id == 21);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(SelectionStrategy.CustomFormatGapWeighted, false, SelectionStrategy.BalancedWeighted)]
|
||||
[InlineData(SelectionStrategy.CustomFormatGapWeighted, true, SelectionStrategy.CustomFormatGapWeighted)]
|
||||
|
||||
@@ -135,7 +135,7 @@ public sealed class SeekerUnitEvaluator
|
||||
|
||||
return ItemSelectorFactory.Create(strategy)
|
||||
.Select([.. selectionCandidates], count)
|
||||
.Select(id => ToCandidate(PickUnit(remainingByItem[id])))
|
||||
.Select(id => ToCandidate(PickUnit(remainingByItem[id], strategy)))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
@@ -708,9 +708,20 @@ public sealed class SeekerUnitEvaluator
|
||||
|
||||
/// <summary>
|
||||
/// Picks a random season of the item, then its earliest airing unit.
|
||||
/// Under <see cref="SelectionStrategy.CustomFormatGapWeighted"/> it picks the missing unit, else the largest gap unit.
|
||||
/// </summary>
|
||||
private static SeekerSearchUnit PickUnit(List<SeekerSearchUnit> itemUnits)
|
||||
private static SeekerSearchUnit PickUnit(List<SeekerSearchUnit> itemUnits, SelectionStrategy strategy)
|
||||
{
|
||||
if (strategy is SelectionStrategy.CustomFormatGapWeighted)
|
||||
{
|
||||
return itemUnits
|
||||
.OrderByDescending(u => u.Reasons.Contains(SeekerSearchReason.Missing))
|
||||
.ThenByDescending(u => u.CustomFormatGap)
|
||||
.ThenBy(u => u.AirDateUtc ?? DateTimeOffset.MaxValue)
|
||||
.ThenBy(u => u.EpisodeId)
|
||||
.First();
|
||||
}
|
||||
|
||||
List<int> seasons = itemUnits.Select(u => u.SeasonNumber).Distinct().ToList();
|
||||
int seasonNumber = seasons[Random.Shared.Next(seasons.Count)];
|
||||
|
||||
|
||||
Reference in new issue
Block a user