From 5608f183b762ececaf52286a8d9020adeb9b231d Mon Sep 17 00:00:00 2001 From: cat-bro Date: Wed, 12 Jun 2024 12:06:27 +1000 Subject: [PATCH] Alter TagSetManager score function to look at preference only --- tpv/core/entities.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tpv/core/entities.py b/tpv/core/entities.py index 1e214a5..1847ee8 100644 --- a/tpv/core/entities.py +++ b/tpv/core/entities.py @@ -149,10 +149,13 @@ def score(self, other: TagSetManager) -> bool: :param other: :return: """ - return (sum(int(tag.tag_type) * int(o.tag_type) for tag in self.tags for o in other.tags - if tag.name == o.name and tag.value == o.value) - # penalize tags that don't exist in the other - - sum(int(tag.tag_type) for tag in self.tags if not other.contains_tag(tag))) + def a_prefers_b(a_tags, b_tags): + return any( + tag for tag in a_tags.filter(tag_type = TagType.PREFER) + if list(b_tags.filter(tag_type = [TagType.ACCEPT, TagType.PREFER, TagType.REQUIRE], tag_value = tag.value)) + ) + score = 1 if a_prefers_b(self.tags, other.tags) or a_prefers_b(other.tags, self.tags) else 0 + return score def __eq__(self, other): if not isinstance(other, TagSetManager):