Refactored GetRoundedSIze

This commit is contained in:
pcjones 2023-09-30 12:36:52 +02:00
parent ac5bc5eaf2
commit 78d114219e
1 changed files with 17 additions and 15 deletions

View File

@ -199,7 +199,7 @@ namespace NzbDrone.Core.DecisionEngine
private int CompareSize(DownloadDecision x, DownloadDecision y)
{
var sizeCompare = CompareBy(x.RemoteEpisode, y.RemoteEpisode, remoteEpisode =>
var sizeCompare = CompareBy(x.RemoteEpisode, y.RemoteEpisode, remoteEpisode =>
{
var preferredSize = _qualityDefinitionService.Get(remoteEpisode.ParsedEpisodeInfo.Quality.Quality).PreferredSize;
@ -222,22 +222,24 @@ namespace NzbDrone.Core.DecisionEngine
private long GetRoundedSize(long size)
{
if (size < 1.5.Gigabytes())
var roundingRules = new List<(long threshold, long roundTo)>
{
(1.5.Gigabytes(), 200.Megabytes()),
(3.5.Gigabytes(), 300.Megabytes()),
(6.Gigabytes(), 450.Megabytes()),
(15.Gigabytes(), 800.Megabytes()),
(30.Gigabytes(), 1600.Megabytes())
};
foreach (var (threshold, roundTo) in roundingRules)
{
return size.Round(200.Megabytes());
}
else if (size < 2.5.Gigabytes())
{
return size.Round(300.Megabytes());
}
else if (size < 3.5.Gigabytes())
{
return size.Round(400.Megabytes());
}
else
{
return size.Round(550.Megabytes());
if (size < threshold)
{
return size.Round(roundTo);
}
}
return size.Round(4500.Megabytes()); // Default rounding for sizes >= 30GB
}
private string SanitizeReleaseName(string releaseName)