<commit_before># MIT License
# Copyright (c) 2017 MassChallenge, Inc.

from django.db.models import Q
from impact.v1.helpers.criterion_helper import CriterionHelper


class MatchingCriterionHelper(CriterionHelper):
    def __init__(self, subject):
        super().__init__(subject)
        self._app_ids_to_targets = {}
        self._target_counts = {}

    def app_count(self, apps, option_name):
        return self.target_counts(apps).get(option_name, 0)

    def find_app_ids(self, feedbacks, apps, target):
        if not feedbacks:
            return []
        result = []
        app_map = self.app_ids_to_targets(apps)
        return [app_id for app_id in
                feedbacks.values_list("application_id", flat=True)
                if app_id in app_map and app_map[app_id] == target.id]

    def app_ids_to_targets(self, apps):
        self._check_cache(apps)
        return self._app_ids_to_targets

    def target_counts(self, apps):
        self._check_cache(apps)<commit_msg>[AC-5626] Fix pycodestyle issues<commit_after># MIT License
# Copyright (c) 2017 MassChallenge, Inc.

from impact.v1.helpers.criterion_helper import CriterionHelper


class MatchingCriterionHelper(CriterionHelper):
    def __init__(self, subject):
        super().__init__(subject)
        self._app_ids_to_targets = {}
        self._target_counts = {}

    def app_count(self, apps, option_name):
        return self.target_counts(apps).get(option_name, 0)

    def find_app_ids(self, feedbacks, apps, target):
        if not feedbacks:
            return []
        app_map = self.app_ids_to_targets(apps)
        return [app_id for app_id in
                feedbacks.values_list("application_id", flat=True)
                if app_id in app_map and app_map[app_id] == target.id]

    def app_ids_to_targets(self, apps):
        self._check_cache(apps)
        return self._app_ids_to_targets

    def target_counts(self, apps):
        self._check_cache(apps)
{'fraction_non_alphanumeric': 0.09193054136874361, 'fraction_numerical': 0.008171603677221655, 'mean_word_length': 2.981707317073171, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5041770', 'n_tokens_mistral': 639, 'n_tokens_neox': 606, 'n_words': 131}