mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-10-30 07:22:35 +01:00
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:
parent
210a0c1936
commit
8d9e69af96
@ -120,7 +120,6 @@ namespace NzbDrone.Core.Test.ProviderTests.EpisodeProviderTests
|
||||
//Act
|
||||
Mocker.Resolve<EpisodeProvider>().GetEpisode(1);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void GetEpisodesBySeason_success()
|
||||
@ -181,7 +180,6 @@ namespace NzbDrone.Core.Test.ProviderTests.EpisodeProviderTests
|
||||
actualCount.Should().Be(episodeCount);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
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.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -158,41 +158,29 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||
var episodes = Builder<Episode>.CreateListOfSize(10).Build();
|
||||
var historyEpisode = episodes[6];
|
||||
|
||||
var history0 = Builder<History>.CreateNew()
|
||||
.With(h => h.Quality = QualityTypes.DVD)
|
||||
.With(h => h.IsProper = true)
|
||||
.With(h => h.EpisodeId = historyEpisode.EpisodeId)
|
||||
.Build();
|
||||
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.Bluray720p)
|
||||
.With(h => h.IsProper = false)
|
||||
.TheNext(1)
|
||||
.With(h => h.Quality = QualityTypes.Bluray720p)
|
||||
.With(h => h.IsProper = true)
|
||||
.TheNext(1)
|
||||
.With(h => h.Quality = QualityTypes.Bluray720p)
|
||||
.With(h => h.IsProper = false)
|
||||
.TheNext(1)
|
||||
.With(h => h.Quality = QualityTypes.SDTV)
|
||||
.With(h => h.IsProper = true)
|
||||
.Build();
|
||||
|
||||
var history1 = Builder<History>.CreateNew()
|
||||
.With(h => h.Quality = QualityTypes.Bluray720p)
|
||||
.With(h => h.IsProper = false)
|
||||
.With(h => h.EpisodeId = historyEpisode.EpisodeId)
|
||||
.Build();
|
||||
|
||||
var history2 = Builder<History>.CreateNew()
|
||||
.With(h => h.Quality = QualityTypes.Bluray720p)
|
||||
.With(h => h.IsProper = true)
|
||||
.With(h => h.EpisodeId = historyEpisode.EpisodeId)
|
||||
.Build();
|
||||
|
||||
var history3 = Builder<History>.CreateNew()
|
||||
.With(h => h.Quality = QualityTypes.Bluray720p)
|
||||
.With(h => h.IsProper = false)
|
||||
.With(h => h.EpisodeId = historyEpisode.EpisodeId)
|
||||
.Build();
|
||||
|
||||
var history4 = Builder<History>.CreateNew()
|
||||
.With(h => h.Quality = QualityTypes.SDTV)
|
||||
.With(h => h.IsProper = true)
|
||||
.With(h => h.EpisodeId = historyEpisode.EpisodeId)
|
||||
.Build();
|
||||
|
||||
Db.Insert(history0);
|
||||
Db.Insert(history1);
|
||||
Db.Insert(history2);
|
||||
Db.Insert(history2);
|
||||
Db.Insert(history4);
|
||||
Db.InsertMany(history);
|
||||
Db.InsertMany(episodes);
|
||||
|
||||
//Act
|
||||
@ -205,6 +193,49 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||
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]
|
||||
public void add_item()
|
||||
{
|
||||
|
@ -60,17 +60,16 @@ namespace NzbDrone.Core.Providers
|
||||
|
||||
public virtual QualityModel GetBestQualityInHistory(int seriesId, int seasonNumber, int episodeNumber)
|
||||
{
|
||||
var quality = _database.SingleOrDefault<dynamic>(@"SELECT TOP 1 History.Quality , History.IsProper FROM History
|
||||
INNER JOIN Episodes ON History.EpisodeId = Episodes.EpisodeId
|
||||
WHERE Episodes.seriesId = @0 AND
|
||||
var quality = _database.Fetch<QualityModel>(@"SELECT History.Quality , History.IsProper as Proper FROM History
|
||||
INNER JOIN Episodes ON History.EpisodeId = Episodes.EpisodeId
|
||||
WHERE Episodes.seriesId = @0 AND
|
||||
Episodes.SeasonNumber = @1 AND
|
||||
Episodes.EpisodeNumber = @2
|
||||
ORDER BY History.Quality DESC, History.IsProper DESC"
|
||||
Episodes.EpisodeNumber = @2"
|
||||
, 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)
|
||||
|
Loading…
Reference in New Issue
Block a user