updated decision logic to prioritize smaller releases of equal quality.

pull/6/head
Keivan Beigi 12 years ago
parent c744a64d4d
commit 9fcd91f2c5

@ -23,7 +23,7 @@ namespace NzbDrone.Core.Test.Download.DownloadApprovedReportsTests
.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 @@ namespace NzbDrone.Core.Test.Download.DownloadApprovedReportsTests
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 @@ namespace NzbDrone.Core.Test.Download.DownloadApprovedReportsTests
} }
[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 @@ namespace NzbDrone.Core.Test.Download.DownloadApprovedReportsTests
} }
[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 @@ namespace NzbDrone.Core.Test.Download.DownloadApprovedReportsTests
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);
} }
} }
} }

@ -271,5 +271,16 @@ namespace NzbDrone.Core.Test
//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);
}
} }
} }

@ -3,6 +3,7 @@ using System.Collections.Generic;
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 @@ namespace NzbDrone.Core.Download
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();
} }

@ -21,7 +21,7 @@ namespace NzbDrone.Core
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 @@ namespace NzbDrone.Core
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))

Loading…
Cancel
Save