INNER CODE UNIT · Python
get_sentence_counts
center-for-threat-informed-defense/tram · src/tram/models.py:41
def get_sentence_counts(cls, accept_threshold=0):
"""
accept_threshold - Only return AttackTechniques where accepted_sentences >= accept_threshold
return: The list of AttackTechnique objects, annotated with how many training sentences
have been accepted, pending, and there are in total.
"""
sentence_counts = (
cls.objects.annotate(
accepted_sentences=Count(
"sentences", filter=Q(sentences__disposition="accept")
),
pending_sentences=Count(
"sentences", filter=Q(sentences__disposition=None)
),
total_sentences=Count("sentences"),
)
.order_by("-accepted_sentences", "attack_id")
.filter(accepted_sentences__gte=accept_threshold)