<commit_before>""" Metrics module provide metrics for the Media Collections. """


class MediaCollectionsMetrics(object):

    """ Media Collections Metrics.

    Attributes:
            collections (list): list of MediaCollections
    """

    def __init__(self, collections):
        """ Constructor. """
        self.collections = collections

    def listall(self):
        """ List allmedia Media objects from the list of Media Collections. """
        allmedia = []
        for collection in self.collections:
            allmedia.append(collection.listall())
        return allmedia

    def mediacount(self):
        """ Return the mediacount metric. """
        return len(self.listall())

    def qicount(self):
        """ Return the qicount metric which represents the amount of 
        quality images in the set of collection."""
        qualityimages = [qi for qi in self.listall() if qi.quality_image]
        return len(qualityimages)<commit_msg>adds caching for listall() adds vicount metric<commit_after>""" Metrics module provide metrics for the Media Collections. """


class MediaCollectionsMetrics(object):

    """ Media Collections Metrics.

    Attributes:
            collections (list): list of MediaCollections
    """

    def __init__(self, collections):
        """ Constructor. """
        self.collections = collections
        self.cache_allmedia = None

    def listall(self):
        """ List allmedia Media objects from the list of the set
        of media collections. """
        if self.cache_allmedia is None:
            self.cache_allmedia = []
            for collection in self.collections:
                self.cache_allmedia.append(collection.listall())
        # else returns the cache value
        return self.cache_allmedia

    def mediacount(self):
        """ Return the mediacount metric. """
        return len(self.listall())

    def qicount(self):
        """ Return the qicount metric which represents the amount of
        quality images in the set of collections."""
        qualityimages = [qi for qi in self.listall() if qi.quality_image]
        return len(qualityimages)

    def vicount(self):
        """ Return the vicount metric which counts the amount of valued images
        in the set of collections. """
        valuedimages = [vi for vi in self.listall() if vi.valued_images]
        return len(valuedimages)
{'fraction_non_alphanumeric': 0.08930817610062892, 'fraction_numerical': 0.0, 'mean_word_length': 2.550595238095238, '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': '1526734', 'n_tokens_mistral': 606, 'n_tokens_neox': 582, 'n_words': 211}