1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-04 10:02:40 +01:00

updated decision logic to prioritize smaller releases of equal quality.

This commit is contained in:
Keivan Beigi 2013-08-06 17:49:40 -07:00
parent c744a64d4d
commit 9fcd91f2c5
4 changed files with 49 additions and 12 deletions

View File

@ -23,7 +23,7 @@ private Episode GetEpisode(int id)
.Build(); .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(); var remoteEpisode = new RemoteEpisode();
remoteEpisode.ParsedEpisodeInfo = new ParsedEpisodeInfo(); remoteEpisode.ParsedEpisodeInfo = new ParsedEpisodeInfo();
@ -33,7 +33,8 @@ private RemoteEpisode GetRemoteEpisode(List<Episode> episodes, QualityModel qual
remoteEpisode.Episodes.AddRange(episodes); remoteEpisode.Episodes.AddRange(episodes);
remoteEpisode.Report = new ReportInfo(); remoteEpisode.Report = new ReportInfo();
remoteEpisode.Report.Age = 0; remoteEpisode.Report.Age = Age;
remoteEpisode.Report.Size = size;
return remoteEpisode; return remoteEpisode;
} }
@ -77,7 +78,7 @@ public void should_put_higher_quality_before_lower()
} }
[Test] [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 remoteEpisode1 = GetRemoteEpisode(new List<Episode> { GetEpisode(2) }, new QualityModel(Quality.HDTV720p));
var remoteEpisode2 = GetRemoteEpisode(new List<Episode> { GetEpisode(1) }, 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] [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 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)); 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); 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] [Test]
public void should_order_by_youngest() public void should_order_by_youngest()
{ {
var remoteEpisode1 = 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)); 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>(); var decisions = new List<DownloadDecision>();
decisions.Add(new DownloadDecision(remoteEpisode1)); decisions.Add(new DownloadDecision(remoteEpisode1));
decisions.Add(new DownloadDecision(remoteEpisode2)); decisions.Add(new DownloadDecision(remoteEpisode2));
var qualifiedReports = Subject.GetQualifiedReports(decisions); var qualifiedReports = Subject.GetQualifiedReports(decisions);
qualifiedReports.First().RemoteEpisode.Report.Age.Should().Be(5); qualifiedReports.First().RemoteEpisode.Should().Be(remoteEpisode2);
} }
} }
} }

View File

@ -271,5 +271,16 @@ public void MinOrDefault_should_return_zero_when_collection_is_null()
//Resolve //Resolve
result.Should().Be(0); 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);
}
} }
} }

View File

@ -3,6 +3,7 @@
using System.Linq; using System.Linq;
using NLog; using NLog;
using NzbDrone.Core.DecisionEngine; using NzbDrone.Core.DecisionEngine;
using NzbDrone.Core.Parser.Model;
namespace NzbDrone.Core.Download namespace NzbDrone.Core.Download
{ {
@ -54,11 +55,12 @@ public List<DownloadDecision> DownloadApproved(List<DownloadDecision> decisions)
return downloadedReports; 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) .OrderByDescending(c => c.RemoteEpisode.ParsedEpisodeInfo.Quality)
.ThenBy(c => c.RemoteEpisode.Episodes.Select(e => e.EpisodeNumber).MinOrDefault()) .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) .ThenBy(c => c.RemoteEpisode.Report.Age)
.ToList(); .ToList();
} }

View File

@ -21,7 +21,7 @@ public static string WithDefault(this string actual, object defaultValue)
public static Int64 Megabytes(this int megabytes) 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) 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); 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) public static string ToBestDateString(this DateTime dateTime)
{ {
if (dateTime == DateTime.Today.AddDays(-1)) if (dateTime == DateTime.Today.AddDays(-1))