1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-10-29 23:12:39 +01:00

New: Minimum Upgrade Score for Custom Formats

Closes #6800
This commit is contained in:
somniumV 2024-09-15 19:20:03 +02:00 committed by GitHub
parent 24f03fc1e9
commit 8b20a9449c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
14 changed files with 164 additions and 11 deletions

View File

@ -123,6 +123,7 @@ class EditQualityProfileModalContent extends Component {
upgradeAllowed,
cutoff,
minFormatScore,
minUpgradeFormatScore,
cutoffFormatScore,
items,
formatItems
@ -244,6 +245,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
}
<div className={styles.formatItemLarge}>
{getCustomFormatRender(formatItems, otherProps)}
</div>

View File

@ -16,6 +16,7 @@ interface QualityProfile {
items: QualityProfileQualityItem[];
minFormatScore: number;
cutoffFormatScore: number;
minUpgradeFormatScore: number;
formatItems: QualityProfileFormatItem[];
id: number;
}

View File

@ -5,6 +5,7 @@ using NzbDrone.Core.Configuration;
using NzbDrone.Core.CustomFormats;
using NzbDrone.Core.DecisionEngine;
using NzbDrone.Core.DecisionEngine.Specifications;
using NzbDrone.Core.Profiles;
using NzbDrone.Core.Profiles.Qualities;
using NzbDrone.Core.Qualities;
using NzbDrone.Core.Test.Framework;
@ -79,9 +80,9 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
GivenAutoDownloadPropers(ProperDownloadTypes.DoNotPrefer);
var profile = new QualityProfile
{
Items = Qualities.QualityFixture.GetDefaultQualities(),
};
{
Items = Qualities.QualityFixture.GetDefaultQualities(),
};
Subject.IsUpgradable(
profile,
@ -96,9 +97,9 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
public void should_return_false_if_release_and_existing_file_are_the_same()
{
var profile = new QualityProfile
{
Items = Qualities.QualityFixture.GetDefaultQualities()
};
{
Items = Qualities.QualityFixture.GetDefaultQualities()
};
Subject.IsUpgradable(
profile,
@ -146,5 +147,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);
}
}
}

View File

@ -0,0 +1,14 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(212)]
public class add_minium_upgrade_format_score_to_quality_profiles : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Alter.Table("QualityProfiles").AddColumn("MinUpgradeFormatScore").AsInt32().WithDefaultValue(1);
}
}
}

View File

@ -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,

View File

@ -77,6 +77,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);
}
}

View File

@ -7,6 +7,7 @@ namespace NzbDrone.Core.DecisionEngine
BetterRevision,
QualityCutoff,
CustomFormatScore,
CustomFormatCutoff
CustomFormatCutoff,
MinCustomFormatScore
}
}

View File

@ -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);
}
}
}

View File

@ -1176,6 +1176,8 @@
"MinimumAgeHelpText": "Usenet only: Minimum age in minutes of NZBs before they are grabbed. Use this to give new releases time to propagate to your usenet provider.",
"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",

View File

@ -18,6 +18,7 @@ namespace NzbDrone.Core.Profiles.Qualities
public int Cutoff { get; set; }
public int MinFormatScore { get; set; }
public int CutoffFormatScore { get; set; }
public int MinUpgradeFormatScore { get; set; }
public List<ProfileFormatItem> FormatItems { get; set; }
public List<QualityProfileQualityItem> Items { get; set; }

View File

@ -174,6 +174,7 @@ namespace NzbDrone.Core.Profiles.Qualities
{
profile.MinFormatScore = 0;
profile.CutoffFormatScore = 0;
profile.MinUpgradeFormatScore = 1;
}
Update(profile);
@ -232,6 +233,7 @@ namespace NzbDrone.Core.Profiles.Qualities
Items = items,
MinFormatScore = 0,
CutoffFormatScore = 0,
MinUpgradeFormatScore = 1,
FormatItems = formatItems
};

View File

@ -15,20 +15,19 @@ namespace Sonarr.Api.V3.Profiles.Quality
public class QualityProfileController : RestController<QualityProfileResource>
{
private readonly IQualityProfileService _profileService;
private readonly ICustomFormatService _formatService;
public QualityProfileController(IQualityProfileService profileService, ICustomFormatService formatService)
{
_profileService = profileService;
_formatService = formatService;
SharedValidator.RuleFor(c => c.Name).NotEmpty();
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();

View File

@ -15,6 +15,7 @@ namespace Sonarr.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; }
}
@ -56,6 +57,7 @@ namespace Sonarr.Api.V3.Profiles.Quality
Items = model.Items.ConvertAll(ToResource),
MinFormatScore = model.MinFormatScore,
CutoffFormatScore = model.CutoffFormatScore,
MinUpgradeFormatScore = model.MinUpgradeFormatScore,
FormatItems = model.FormatItems.ConvertAll(ToResource)
};
}
@ -103,6 +105,7 @@ namespace Sonarr.Api.V3.Profiles.Quality
Items = resource.Items.ConvertAll(ToModel),
MinFormatScore = resource.MinFormatScore,
CutoffFormatScore = resource.CutoffFormatScore,
MinUpgradeFormatScore = resource.MinUpgradeFormatScore,
FormatItems = resource.FormatItems.ConvertAll(ToModel)
};
}

View File

@ -10673,6 +10673,10 @@
"type": "integer",
"format": "int32"
},
"minUpgradeFormatScore": {
"type": "integer",
"format": "int32"
},
"formatItems": {
"type": "array",
"items": {