mirror of
https://github.com/Radarr/Radarr.git
synced 2025-04-24 06:27:08 -04:00
New: Minimum Upgrade Score for Custom Formats
(cherry picked from commit 8b20a9449c1ae5ffd1e8d12f1ca771727b8c52a5)
This commit is contained in:
parent
5757fa797f
commit
bb43d0c796
13 changed files with 155 additions and 5 deletions
|
@ -125,6 +125,7 @@ class EditQualityProfileModalContent extends Component {
|
|||
upgradeAllowed,
|
||||
cutoff,
|
||||
minFormatScore,
|
||||
minUpgradeFormatScore,
|
||||
cutoffFormatScore,
|
||||
language,
|
||||
items,
|
||||
|
@ -249,6 +250,25 @@ class EditQualityProfileModalContent extends Component {
|
|||
</FormGroup>
|
||||
}
|
||||
|
||||
{
|
||||
upgradeAllowed.value && formatItems.value.length > 0 ?
|
||||
<FormGroup size={sizes.EXTRA_SMALL}>
|
||||
<FormLabel size={sizes.SMALL}>
|
||||
{translate('MinimumCustomFormatScoreIncrement')}
|
||||
</FormLabel>
|
||||
|
||||
<FormInputGroup
|
||||
type={inputTypes.NUMBER}
|
||||
name="minUpgradeFormatScore"
|
||||
min={1}
|
||||
{...minUpgradeFormatScore}
|
||||
helpText={translate('MinimumCustomFormatScoreIncrementHelpText')}
|
||||
onChange={onInputChange}
|
||||
/>
|
||||
</FormGroup> :
|
||||
null
|
||||
}
|
||||
|
||||
<FormGroup size={sizes.EXTRA_SMALL}>
|
||||
<FormLabel size={sizes.SMALL}>
|
||||
{translate('Language')}
|
||||
|
|
|
@ -16,6 +16,7 @@ interface QualityProfile {
|
|||
items: QualityProfileQualityItem[];
|
||||
minFormatScore: number;
|
||||
cutoffFormatScore: number;
|
||||
minUpgradeFormatScore: number;
|
||||
formatItems: QualityProfileFormatItem[];
|
||||
id: number;
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ using NzbDrone.Core.CustomFormats;
|
|||
using NzbDrone.Core.DecisionEngine;
|
||||
using NzbDrone.Core.DecisionEngine.Specifications;
|
||||
using NzbDrone.Core.Parser;
|
||||
using NzbDrone.Core.Profiles;
|
||||
using NzbDrone.Core.Profiles.Qualities;
|
||||
using NzbDrone.Core.Qualities;
|
||||
using NzbDrone.Core.Test.CustomFormats;
|
||||
|
@ -160,5 +161,95 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
|||
new List<CustomFormat>())
|
||||
.Should().Be(UpgradeableRejectReason.QualityCutoff);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_false_if_minimum_custom_score_is_not_met()
|
||||
{
|
||||
var customFormatOne = new CustomFormat
|
||||
{
|
||||
Id = 1,
|
||||
Name = "One"
|
||||
};
|
||||
|
||||
var customFormatTwo = new CustomFormat
|
||||
{
|
||||
Id = 2,
|
||||
Name = "Two"
|
||||
};
|
||||
|
||||
var profile = new QualityProfile
|
||||
{
|
||||
Items = Qualities.QualityFixture.GetDefaultQualities(),
|
||||
UpgradeAllowed = true,
|
||||
MinUpgradeFormatScore = 11,
|
||||
CutoffFormatScore = 100,
|
||||
FormatItems = new List<ProfileFormatItem>
|
||||
{
|
||||
new ProfileFormatItem
|
||||
{
|
||||
Format = customFormatOne,
|
||||
Score = 10
|
||||
},
|
||||
new ProfileFormatItem
|
||||
{
|
||||
Format = customFormatTwo,
|
||||
Score = 20
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Subject.IsUpgradable(
|
||||
profile,
|
||||
new QualityModel(Quality.DVD),
|
||||
new List<CustomFormat> { customFormatOne },
|
||||
new QualityModel(Quality.DVD),
|
||||
new List<CustomFormat> { customFormatTwo })
|
||||
.Should().Be(UpgradeableRejectReason.MinCustomFormatScore);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_if_minimum_custom_score_is_met()
|
||||
{
|
||||
var customFormatOne = new CustomFormat
|
||||
{
|
||||
Id = 1,
|
||||
Name = "One"
|
||||
};
|
||||
|
||||
var customFormatTwo = new CustomFormat
|
||||
{
|
||||
Id = 2,
|
||||
Name = "Two"
|
||||
};
|
||||
|
||||
var profile = new QualityProfile
|
||||
{
|
||||
Items = Qualities.QualityFixture.GetDefaultQualities(),
|
||||
UpgradeAllowed = true,
|
||||
MinUpgradeFormatScore = 10,
|
||||
CutoffFormatScore = 100,
|
||||
FormatItems = new List<ProfileFormatItem>
|
||||
{
|
||||
new ProfileFormatItem
|
||||
{
|
||||
Format = customFormatOne,
|
||||
Score = 10
|
||||
},
|
||||
new ProfileFormatItem
|
||||
{
|
||||
Format = customFormatTwo,
|
||||
Score = 20
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Subject.IsUpgradable(
|
||||
profile,
|
||||
new QualityModel(Quality.DVD),
|
||||
new List<CustomFormat> { customFormatOne },
|
||||
new QualityModel(Quality.DVD),
|
||||
new List<CustomFormat> { customFormatTwo })
|
||||
.Should().Be(UpgradeableRejectReason.None);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
using FluentMigrator;
|
||||
using NzbDrone.Core.Datastore.Migration.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Datastore.Migration
|
||||
{
|
||||
[Migration(239)]
|
||||
public class add_minimum_upgrade_format_score_to_quality_profiles : NzbDroneMigrationBase
|
||||
{
|
||||
protected override void MainDbUpgrade()
|
||||
{
|
||||
Alter.Table("QualityProfiles").AddColumn("MinUpgradeFormatScore").AsInt32().WithDefaultValue(1);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -95,6 +95,17 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
|
|||
return UpgradeableRejectReason.CustomFormatCutoff;
|
||||
}
|
||||
|
||||
if (newFormatScore < currentFormatScore + qualityProfile.MinUpgradeFormatScore)
|
||||
{
|
||||
_logger.Debug("New item's custom formats [{0}] ({1}) do not meet minimum custom format score increment of {3} required for upgrade, skipping. Existing: [{4}] ({5}).",
|
||||
newCustomFormats.ConcatToString(),
|
||||
newFormatScore,
|
||||
qualityProfile.MinUpgradeFormatScore,
|
||||
currentCustomFormats.ConcatToString(),
|
||||
currentFormatScore);
|
||||
return UpgradeableRejectReason.MinCustomFormatScore;
|
||||
}
|
||||
|
||||
_logger.Debug("New item's custom formats [{0}] ({1}) improve on [{2}] ({3}), accepting",
|
||||
newCustomFormats.ConcatToString(),
|
||||
newFormatScore,
|
||||
|
|
|
@ -78,6 +78,9 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
|
|||
|
||||
case UpgradeableRejectReason.CustomFormatScore:
|
||||
return Decision.Reject("Existing file on disk has a equal or higher custom format score: {0}", qualityProfile.CalculateCustomFormatScore(customFormats));
|
||||
|
||||
case UpgradeableRejectReason.MinCustomFormatScore:
|
||||
return Decision.Reject("Existing file differential between new release does not meet minimum Custom Format score increment: {0}", qualityProfile.MinFormatScore);
|
||||
}
|
||||
|
||||
return Decision.Accept();
|
||||
|
|
|
@ -7,6 +7,7 @@ namespace NzbDrone.Core.DecisionEngine
|
|||
BetterRevision,
|
||||
QualityCutoff,
|
||||
CustomFormatScore,
|
||||
CustomFormatCutoff
|
||||
CustomFormatCutoff,
|
||||
MinCustomFormatScore
|
||||
}
|
||||
}
|
||||
|
|
|
@ -65,6 +65,7 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
|
|||
{
|
||||
profile.MinFormatScore = 0;
|
||||
profile.CutoffFormatScore = 0;
|
||||
profile.MinUpgradeFormatScore = 1;
|
||||
}
|
||||
|
||||
updatedProfiles.Add(profile);
|
||||
|
@ -73,7 +74,7 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
|
|||
|
||||
if (updatedProfiles.Any())
|
||||
{
|
||||
_repository.SetFields(updatedProfiles, p => p.FormatItems, p => p.MinFormatScore, p => p.CutoffFormatScore);
|
||||
_repository.SetFields(updatedProfiles, p => p.FormatItems, p => p.MinFormatScore, p => p.CutoffFormatScore, p => p.MinUpgradeFormatScore);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -910,6 +910,8 @@
|
|||
"MinimumAvailability": "Minimum Availability",
|
||||
"MinimumCustomFormatScore": "Minimum Custom Format Score",
|
||||
"MinimumCustomFormatScoreHelpText": "Minimum custom format score allowed to download",
|
||||
"MinimumCustomFormatScoreIncrement": "Minimum Custom Format Score Increment",
|
||||
"MinimumCustomFormatScoreIncrementHelpText": "Minimum required improvement of the custom format score between existing and new releases before {appName} considers it an upgrade",
|
||||
"MinimumFreeSpace": "Minimum Free Space",
|
||||
"MinimumFreeSpaceHelpText": "Prevent import if it would leave less than this amount of disk space available",
|
||||
"MinimumLimits": "Minimum Limits",
|
||||
|
|
|
@ -19,6 +19,7 @@ namespace NzbDrone.Core.Profiles.Qualities
|
|||
public List<QualityProfileQualityItem> Items { get; set; }
|
||||
public int MinFormatScore { get; set; }
|
||||
public int CutoffFormatScore { get; set; }
|
||||
public int MinUpgradeFormatScore { get; set; }
|
||||
public List<ProfileFormatItem> FormatItems { get; set; }
|
||||
public Language Language { get; set; }
|
||||
public bool UpgradeAllowed { get; set; }
|
||||
|
|
|
@ -112,6 +112,7 @@ namespace NzbDrone.Core.Profiles.Qualities
|
|||
{
|
||||
profile.MinFormatScore = 0;
|
||||
profile.CutoffFormatScore = 0;
|
||||
profile.MinUpgradeFormatScore = 1;
|
||||
}
|
||||
|
||||
Update(profile);
|
||||
|
@ -262,6 +263,7 @@ namespace NzbDrone.Core.Profiles.Qualities
|
|||
Language = Language.English,
|
||||
MinFormatScore = 0,
|
||||
CutoffFormatScore = 0,
|
||||
MinUpgradeFormatScore = 1,
|
||||
FormatItems = formatItems
|
||||
};
|
||||
|
||||
|
|
|
@ -15,22 +15,22 @@ namespace Radarr.Api.V3.Profiles.Quality
|
|||
public class QualityProfileController : RestController<QualityProfileResource>
|
||||
{
|
||||
private readonly IQualityProfileService _qualityProfileService;
|
||||
private readonly ICustomFormatService _formatService;
|
||||
|
||||
public QualityProfileController(IQualityProfileService qualityProfileService, ICustomFormatService formatService)
|
||||
{
|
||||
_qualityProfileService = qualityProfileService;
|
||||
_formatService = formatService;
|
||||
|
||||
SharedValidator.RuleFor(c => c.Name).NotEmpty();
|
||||
|
||||
// TODO: Need to validate the cutoff is allowed and the ID/quality ID exists
|
||||
// TODO: Need to validate the Items to ensure groups have names and at no item has no name, no items and no quality
|
||||
SharedValidator.RuleFor(c => c.MinUpgradeFormatScore).GreaterThanOrEqualTo(1);
|
||||
SharedValidator.RuleFor(c => c.Cutoff).ValidCutoff();
|
||||
SharedValidator.RuleFor(c => c.Items).ValidItems();
|
||||
|
||||
SharedValidator.RuleFor(c => c.FormatItems).Must(items =>
|
||||
{
|
||||
var all = _formatService.All().Select(f => f.Id).ToList();
|
||||
var all = formatService.All().Select(f => f.Id).ToList();
|
||||
var ids = items.Select(i => i.Format);
|
||||
|
||||
return all.Except(ids).Empty();
|
||||
|
|
|
@ -16,6 +16,7 @@ namespace Radarr.Api.V3.Profiles.Quality
|
|||
public List<QualityProfileQualityItemResource> Items { get; set; }
|
||||
public int MinFormatScore { get; set; }
|
||||
public int CutoffFormatScore { get; set; }
|
||||
public int MinUpgradeFormatScore { get; set; }
|
||||
public List<ProfileFormatItemResource> FormatItems { get; set; }
|
||||
public Language Language { get; set; }
|
||||
}
|
||||
|
@ -58,6 +59,7 @@ namespace Radarr.Api.V3.Profiles.Quality
|
|||
Items = model.Items.ConvertAll(ToResource),
|
||||
MinFormatScore = model.MinFormatScore,
|
||||
CutoffFormatScore = model.CutoffFormatScore,
|
||||
MinUpgradeFormatScore = model.MinUpgradeFormatScore,
|
||||
FormatItems = model.FormatItems.ConvertAll(ToResource),
|
||||
Language = model.Language
|
||||
};
|
||||
|
@ -106,6 +108,7 @@ namespace Radarr.Api.V3.Profiles.Quality
|
|||
Items = resource.Items.ConvertAll(ToModel),
|
||||
MinFormatScore = resource.MinFormatScore,
|
||||
CutoffFormatScore = resource.CutoffFormatScore,
|
||||
MinUpgradeFormatScore = resource.MinUpgradeFormatScore,
|
||||
FormatItems = resource.FormatItems.ConvertAll(ToModel),
|
||||
Language = resource.Language
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue