Option to treat negative scores as ignored

The `--strict-negative-scores` option will take any negative preferred
term scores and move those terms to the "Must Not Contains" (ignored)
field of the release profile.
pull/5/head
Robert Dailey 3 years ago
parent 09c24a911d
commit cdc5973cde

@ -16,6 +16,7 @@ Features list will continue to grow. See the limitations & roadmap section for m
* Profiles get created if they do not exist, or updated if they already exist. Profiles get a unique
name based on the guide and this name is used to find them in subsequent runs.
* Tags can be added to any updated or created profiles.
* Ability to convert preferred with negative scores to "Must not contain" terms.
* Sonarr Quality Definitions
* Anime and Non-Anime quality definitions are now synced to Sonarr
@ -135,7 +136,6 @@ the following limitations:
In addition to the above limitations, the following items are planned for the future.
* Better and more polished error handling (it's pretty minimal right now)
* Add a way to convert preferred with negative scores to "Must not contain" terms.
* Implement some sort of guide versioning (e.g. to avoid updating a release profile if the guide did
not change).
* Unit Testing

@ -39,6 +39,8 @@ def setup_and_parse_args(args_override=None):
})
profile_p.add_argument('--tags', help='Tags to assign to the profiles that are created or updated. These tags will replace any existing tags when updating profiles.',
nargs='+')
profile_p.add_argument('--strict-negative-scores', help='Any negative scores get added to the list of "Must Not Contain" items',
action='store_true')
# Subcommands for 'quality'
quality_p = subparsers.add_parser('quality', help='Pages in the guide that provide quality definitions',

@ -32,7 +32,7 @@ def parse_category(line):
return None
# --------------------------------------------------------------------------------------------------
def parse_markdown(logger, markdown_content):
def parse_markdown(args, logger, markdown_content):
results = defaultdict(ProfileData)
profile_name = None
score = None
@ -72,7 +72,10 @@ def parse_markdown(logger, markdown_content):
elif bracket_depth:
if score is not None:
logger.debug(f' [Preferred] Score: {score}, Term: {line}')
profile.preferred[score].append(line)
if args.strict_negative_scores and score < 0:
profile.ignored.append(line)
else:
profile.preferred[score].append(line)
elif category == TermCategory.Ignored and bracket_depth:
# Sometimes a comma is present at the end of these regexes, because when it's
# pasted into Sonarr it acts as a delimiter. However, when using them with the

@ -9,7 +9,10 @@ def test_parse_markdown_complete_doc():
with open(md_file) as file:
test_markdown = file.read()
results = anime.parse_markdown(MockLogger(), test_markdown)
class args:
strict_negative_scores = False
results = anime.parse_markdown(args, MockLogger(), test_markdown)
assert len(results) == 1
profile = next(iter(results.values()))
@ -22,3 +25,31 @@ def test_parse_markdown_complete_doc():
assert len(profile.preferred) == 1
assert profile.preferred.get(100) == ['term1']
def test_parse_markdown_strict_negative_scores():
test_markdown = '''
# Test Release Profile
This score is negative [-1]
```
abc
```
This score is positive [0]
```
xyz
```
'''
class args:
strict_negative_scores = True
results = anime.parse_markdown(args, MockLogger(), test_markdown)
assert len(results['Test Release Profile'].required) == 0
assert len(results['Test Release Profile'].ignored) == 1
assert results['Test Release Profile'].ignored[0] == 'abc'
assert len(results['Test Release Profile'].preferred) == 1
assert results['Test Release Profile'].preferred[0] == ['xyz']

@ -10,7 +10,7 @@ from app.cmd import setup_and_parse_args
from app.logger import Logger
def process_sonarr_profile(args, logger):
profiles = anime.parse_markdown(logger, anime.get_trash_anime_markdown())
profiles = anime.parse_markdown(args, logger, anime.get_trash_anime_markdown())
# A few false-positive profiles are added sometimes. We filter these out by checking if they
# actually have meaningful data attached to them, such as preferred terms. If they are mostly empty,

Loading…
Cancel
Save