BestQualityInHistory fixed

#ND-138 fixed
#ND-138 comment "No issue with Disk upgrade check, just history."
Fixed: An issue with some qualities being treated as lower than expected
when checking history
This commit is contained in:
Mark McDowall 2013-01-10 17:15:36 -08:00
parent 210a0c1936
commit 8d9e69af96
3 changed files with 92 additions and 43 deletions

View File

@ -121,7 +121,6 @@ namespace NzbDrone.Core.Test.ProviderTests.EpisodeProviderTests
Mocker.Resolve<EpisodeProvider>().GetEpisode(1); Mocker.Resolve<EpisodeProvider>().GetEpisode(1);
} }
[Test] [Test]
public void GetEpisodesBySeason_success() public void GetEpisodesBySeason_success()
{ {
@ -181,7 +180,6 @@ namespace NzbDrone.Core.Test.ProviderTests.EpisodeProviderTests
actualCount.Should().Be(episodeCount); actualCount.Should().Be(episodeCount);
} }
[Test] [Test]
public void RefreshEpisodeInfo_should_set_older_than_1900_to_null() public void RefreshEpisodeInfo_should_set_older_than_1900_to_null()
{ {
@ -1518,5 +1516,26 @@ namespace NzbDrone.Core.Test.ProviderTests.EpisodeProviderTests
result.Where(e => e.Ignored).Should().HaveCount(episodeCount - 1); result.Where(e => e.Ignored).Should().HaveCount(episodeCount - 1);
result.Single(e => e.SeasonNumber == 1).Ignored.Should().BeFalse(); result.Single(e => e.SeasonNumber == 1).Ignored.Should().BeFalse();
} }
[Test]
public void GetEpisode_with_EpisodeFile_should_have_quality_set_properly()
{
WithRealDb();
var fakeSeries = Builder<Series>.CreateNew().Build();
var fakeFile = Builder<EpisodeFile>.CreateNew().With(f => f.EpisodeFileId).With(c => c.Quality = QualityTypes.WEBDL1080p).Build();
var fakeEpisodes = Builder<Episode>.CreateListOfSize(5)
.All().With(e => e.SeriesId = 1).TheFirst(1).With(e => e.EpisodeFileId = 1).With(e => e.EpisodeFile = fakeFile).Build();
Db.Insert(fakeSeries);
Db.InsertMany(fakeEpisodes);
Db.Insert(fakeFile);
//Act
var episode = Mocker.Resolve<EpisodeProvider>().GetEpisode(1);
//Assert
episode.EpisodeFile.Quality.Should().Be(QualityTypes.WEBDL1080p);
}
} }
} }

View File

@ -158,41 +158,29 @@ namespace NzbDrone.Core.Test.ProviderTests
var episodes = Builder<Episode>.CreateListOfSize(10).Build(); var episodes = Builder<Episode>.CreateListOfSize(10).Build();
var historyEpisode = episodes[6]; var historyEpisode = episodes[6];
var history0 = Builder<History>.CreateNew() var history = Builder<History>
.CreateListOfSize(5)
.All()
.With(h => h.EpisodeId = historyEpisode.EpisodeId)
.With(h => h.SeriesId = historyEpisode.SeriesId)
.TheFirst(1)
.With(h => h.Quality = QualityTypes.DVD) .With(h => h.Quality = QualityTypes.DVD)
.With(h => h.IsProper = true) .With(h => h.IsProper = true)
.With(h => h.EpisodeId = historyEpisode.EpisodeId) .TheNext(1)
.Build();
var history1 = Builder<History>.CreateNew()
.With(h => h.Quality = QualityTypes.Bluray720p) .With(h => h.Quality = QualityTypes.Bluray720p)
.With(h => h.IsProper = false) .With(h => h.IsProper = false)
.With(h => h.EpisodeId = historyEpisode.EpisodeId) .TheNext(1)
.Build();
var history2 = Builder<History>.CreateNew()
.With(h => h.Quality = QualityTypes.Bluray720p) .With(h => h.Quality = QualityTypes.Bluray720p)
.With(h => h.IsProper = true) .With(h => h.IsProper = true)
.With(h => h.EpisodeId = historyEpisode.EpisodeId) .TheNext(1)
.Build();
var history3 = Builder<History>.CreateNew()
.With(h => h.Quality = QualityTypes.Bluray720p) .With(h => h.Quality = QualityTypes.Bluray720p)
.With(h => h.IsProper = false) .With(h => h.IsProper = false)
.With(h => h.EpisodeId = historyEpisode.EpisodeId) .TheNext(1)
.Build();
var history4 = Builder<History>.CreateNew()
.With(h => h.Quality = QualityTypes.SDTV) .With(h => h.Quality = QualityTypes.SDTV)
.With(h => h.IsProper = true) .With(h => h.IsProper = true)
.With(h => h.EpisodeId = historyEpisode.EpisodeId)
.Build(); .Build();
Db.Insert(history0); Db.InsertMany(history);
Db.Insert(history1);
Db.Insert(history2);
Db.Insert(history2);
Db.Insert(history4);
Db.InsertMany(episodes); Db.InsertMany(episodes);
//Act //Act
@ -205,6 +193,49 @@ namespace NzbDrone.Core.Test.ProviderTests
result.Proper.Should().BeTrue(); result.Proper.Should().BeTrue();
} }
[Test]
public void GetBestQualityInHistory_should_return_highest_weighted_result()
{
WithRealDb();
var episodes = Builder<Episode>.CreateListOfSize(10).Build();
var historyEpisode = episodes[6];
var history = Builder<History>
.CreateListOfSize(5)
.All()
.With(h => h.EpisodeId = historyEpisode.EpisodeId)
.With(h => h.SeriesId = historyEpisode.SeriesId)
.TheFirst(1)
.With(h => h.Quality = QualityTypes.DVD)
.With(h => h.IsProper = true)
.TheNext(1)
.With(h => h.Quality = QualityTypes.WEBDL720p)
.With(h => h.IsProper = false)
.TheNext(1)
.With(h => h.Quality = QualityTypes.WEBDL720p)
.With(h => h.IsProper = true)
.TheNext(1)
.With(h => h.Quality = QualityTypes.WEBDL1080p)
.With(h => h.IsProper = false)
.TheNext(1)
.With(h => h.Quality = QualityTypes.SDTV)
.With(h => h.IsProper = true)
.Build();
Db.InsertMany(history);
Db.InsertMany(episodes);
//Act
var result = Mocker.Resolve<HistoryProvider>()
.GetBestQualityInHistory(historyEpisode.SeriesId, historyEpisode.SeasonNumber, historyEpisode.EpisodeNumber);
//Assert
result.Should().NotBeNull();
result.Quality.Should().Be(QualityTypes.WEBDL1080p);
result.Proper.Should().BeFalse();
}
[Test] [Test]
public void add_item() public void add_item()
{ {

View File

@ -60,17 +60,16 @@ namespace NzbDrone.Core.Providers
public virtual QualityModel GetBestQualityInHistory(int seriesId, int seasonNumber, int episodeNumber) public virtual QualityModel GetBestQualityInHistory(int seriesId, int seasonNumber, int episodeNumber)
{ {
var quality = _database.SingleOrDefault<dynamic>(@"SELECT TOP 1 History.Quality , History.IsProper FROM History var quality = _database.Fetch<QualityModel>(@"SELECT History.Quality , History.IsProper as Proper FROM History
INNER JOIN Episodes ON History.EpisodeId = Episodes.EpisodeId INNER JOIN Episodes ON History.EpisodeId = Episodes.EpisodeId
WHERE Episodes.seriesId = @0 AND WHERE Episodes.seriesId = @0 AND
Episodes.SeasonNumber = @1 AND Episodes.SeasonNumber = @1 AND
Episodes.EpisodeNumber = @2 Episodes.EpisodeNumber = @2"
ORDER BY History.Quality DESC, History.IsProper DESC"
, seriesId, seasonNumber, episodeNumber); , seriesId, seasonNumber, episodeNumber);
if (quality == null) return null; var best = quality.OrderByDescending(q => q).FirstOrDefault();
return new QualityModel((QualityTypes)quality.Quality, quality.IsProper); return best;
} }
public virtual void Delete(int historyId) public virtual void Delete(int historyId)