mirror of
https://github.com/lidarr/Lidarr
synced 2024-12-26 01:27:00 +00:00
updated decision logic to prioritize smaller releases of equal quality.
This commit is contained in:
parent
c744a64d4d
commit
9fcd91f2c5
4 changed files with 49 additions and 12 deletions
|
@ -23,7 +23,7 @@ private Episode GetEpisode(int id)
|
|||
.Build();
|
||||
}
|
||||
|
||||
private RemoteEpisode GetRemoteEpisode(List<Episode> episodes, QualityModel quality)
|
||||
private RemoteEpisode GetRemoteEpisode(List<Episode> episodes, QualityModel quality, int Age = 0, long size = 0)
|
||||
{
|
||||
var remoteEpisode = new RemoteEpisode();
|
||||
remoteEpisode.ParsedEpisodeInfo = new ParsedEpisodeInfo();
|
||||
|
@ -33,7 +33,8 @@ private RemoteEpisode GetRemoteEpisode(List<Episode> episodes, QualityModel qual
|
|||
remoteEpisode.Episodes.AddRange(episodes);
|
||||
|
||||
remoteEpisode.Report = new ReportInfo();
|
||||
remoteEpisode.Report.Age = 0;
|
||||
remoteEpisode.Report.Age = Age;
|
||||
remoteEpisode.Report.Size = size;
|
||||
|
||||
return remoteEpisode;
|
||||
}
|
||||
|
@ -77,7 +78,7 @@ public void should_put_higher_quality_before_lower()
|
|||
}
|
||||
|
||||
[Test]
|
||||
public void should_order_by_lowest_episode_number()
|
||||
public void should_order_by_lowest_number_of_episodes()
|
||||
{
|
||||
var remoteEpisode1 = GetRemoteEpisode(new List<Episode> { GetEpisode(2) }, new QualityModel(Quality.HDTV720p));
|
||||
var remoteEpisode2 = GetRemoteEpisode(new List<Episode> { GetEpisode(1) }, new QualityModel(Quality.HDTV720p));
|
||||
|
@ -91,7 +92,7 @@ public void should_order_by_lowest_episode_number()
|
|||
}
|
||||
|
||||
[Test]
|
||||
public void should_order_by_lowest_episode_number_with_multiple_episodes()
|
||||
public void should_order_by_lowest_number_of_episodes_with_multiple_episodes()
|
||||
{
|
||||
var remoteEpisode1 = GetRemoteEpisode(new List<Episode> { GetEpisode(2), GetEpisode(3) }, new QualityModel(Quality.HDTV720p));
|
||||
var remoteEpisode2 = GetRemoteEpisode(new List<Episode> { GetEpisode(1), GetEpisode(2) }, new QualityModel(Quality.HDTV720p));
|
||||
|
@ -104,21 +105,38 @@ public void should_order_by_lowest_episode_number_with_multiple_episodes()
|
|||
qualifiedReports.First().RemoteEpisode.Episodes.First().EpisodeNumber.Should().Be(1);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void should_order_by_smallest_rounded_to_200mb_then_age()
|
||||
{
|
||||
var remoteEpisodeSd = GetRemoteEpisode(new List<Episode> { GetEpisode(1) }, new QualityModel(Quality.SDTV), size: 100.Megabytes(), Age: 1);
|
||||
var remoteEpisodeHdSmallOld = GetRemoteEpisode(new List<Episode> { GetEpisode(1) }, new QualityModel(Quality.HDTV720p), size:1200.Megabytes(), Age:1000);
|
||||
var remoteEpisodeHdSmallYounge = GetRemoteEpisode(new List<Episode> { GetEpisode(1) }, new QualityModel(Quality.HDTV720p), size:1250.Megabytes(), Age:10);
|
||||
var remoteEpisodeHdLargeYounge = GetRemoteEpisode(new List<Episode> { GetEpisode(1) }, new QualityModel(Quality.HDTV720p), size:3000.Megabytes(), Age:1);
|
||||
|
||||
var decisions = new List<DownloadDecision>();
|
||||
decisions.Add(new DownloadDecision(remoteEpisodeSd));
|
||||
decisions.Add(new DownloadDecision(remoteEpisodeHdSmallOld));
|
||||
decisions.Add(new DownloadDecision(remoteEpisodeHdSmallYounge));
|
||||
decisions.Add(new DownloadDecision(remoteEpisodeHdLargeYounge));
|
||||
|
||||
var qualifiedReports = Subject.GetQualifiedReports(decisions);
|
||||
qualifiedReports.First().RemoteEpisode.Should().Be(remoteEpisodeHdSmallYounge);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_order_by_youngest()
|
||||
{
|
||||
var remoteEpisode1 = GetRemoteEpisode(new List<Episode> { GetEpisode(1) }, new QualityModel(Quality.HDTV720p));
|
||||
var remoteEpisode2 = GetRemoteEpisode(new List<Episode> { GetEpisode(1) }, new QualityModel(Quality.HDTV720p));
|
||||
var remoteEpisode1 = GetRemoteEpisode(new List<Episode> { GetEpisode(1) }, new QualityModel(Quality.HDTV720p), Age: 10);
|
||||
var remoteEpisode2 = GetRemoteEpisode(new List<Episode> { GetEpisode(1) }, new QualityModel(Quality.HDTV720p), Age: 5);
|
||||
|
||||
remoteEpisode1.Report.Age = 10;
|
||||
remoteEpisode2.Report.Age = 5;
|
||||
|
||||
var decisions = new List<DownloadDecision>();
|
||||
decisions.Add(new DownloadDecision(remoteEpisode1));
|
||||
decisions.Add(new DownloadDecision(remoteEpisode2));
|
||||
|
||||
var qualifiedReports = Subject.GetQualifiedReports(decisions);
|
||||
qualifiedReports.First().RemoteEpisode.Report.Age.Should().Be(5);
|
||||
qualifiedReports.First().RemoteEpisode.Should().Be(remoteEpisode2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -271,5 +271,16 @@ public void MinOrDefault_should_return_zero_when_collection_is_null()
|
|||
//Resolve
|
||||
result.Should().Be(0);
|
||||
}
|
||||
|
||||
|
||||
[TestCase(100,100,100)]
|
||||
[TestCase(110,100,100)]
|
||||
[TestCase(199,100,100)]
|
||||
[TestCase(1000,100,1000)]
|
||||
[TestCase(0,100,0)]
|
||||
public void round_to_level(long number, int level, int result)
|
||||
{
|
||||
number.Round(level).Should().Be(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
using System.Linq;
|
||||
using NLog;
|
||||
using NzbDrone.Core.DecisionEngine;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
|
||||
namespace NzbDrone.Core.Download
|
||||
{
|
||||
|
@ -54,11 +55,12 @@ public List<DownloadDecision> DownloadApproved(List<DownloadDecision> decisions)
|
|||
return downloadedReports;
|
||||
}
|
||||
|
||||
public List<DownloadDecision> GetQualifiedReports(List<DownloadDecision> decisions)
|
||||
public List<DownloadDecision> GetQualifiedReports(IEnumerable<DownloadDecision> decisions)
|
||||
{
|
||||
return decisions.Where(c => c.Approved)
|
||||
return decisions.Where(c => c.Approved && c.RemoteEpisode.Episodes.Any())
|
||||
.OrderByDescending(c => c.RemoteEpisode.ParsedEpisodeInfo.Quality)
|
||||
.ThenBy(c => c.RemoteEpisode.Episodes.Select(e => e.EpisodeNumber).MinOrDefault())
|
||||
.ThenBy(c => c.RemoteEpisode.Report.Size.Round(200.Megabytes()) / c.RemoteEpisode.Episodes.Count)
|
||||
.ThenBy(c => c.RemoteEpisode.Report.Age)
|
||||
.ToList();
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ public static string WithDefault(this string actual, object defaultValue)
|
|||
|
||||
public static Int64 Megabytes(this int megabytes)
|
||||
{
|
||||
return Convert.ToInt64(megabytes * 1024L *1024L);
|
||||
return Convert.ToInt64(megabytes * 1024L * 1024L);
|
||||
}
|
||||
|
||||
public static Int64 Gigabytes(this int gigabytes)
|
||||
|
@ -29,6 +29,12 @@ public static Int64 Gigabytes(this int gigabytes)
|
|||
return Convert.ToInt64(gigabytes * 1024L * 1024L * 1024L);
|
||||
}
|
||||
|
||||
|
||||
public static Int64 Round(this long number, long level)
|
||||
{
|
||||
return Convert.ToInt64(Math.Floor((decimal)number / level) * level);
|
||||
}
|
||||
|
||||
public static string ToBestDateString(this DateTime dateTime)
|
||||
{
|
||||
if (dateTime == DateTime.Today.AddDays(-1))
|
||||
|
|
Loading…
Reference in a new issue