<commit_before>from flask import g

from annotator.annotation import Annotation as Annotation_
from annotator.authz import permissions_filter

class Annotation(Annotation_):

    @classmethod
    def stats_for_user(cls, user):
        stats = {}

        q = {'query': {'match_all': {}},
             'filter': {'and': [permissions_filter(g.user),
                                {'or': [{'term': {'user': user.id}},
                                        {'term': {'user.id': user.id}}]}]}}

        stats['num_annotations'] = cls.es.conn.count({'filtered': q})['count']

        uris_res = cls.es.conn.search_raw({
            'query': {'filtered': q},
            'facets': {'uri': {'terms': {'field': 'uri'}}},
            'size': 0
        })
        stats['num_uris'] = len(uris_res['facets']['uri']['terms'])

        return stats
<commit_msg>Specify index and type when counting annotations<commit_after>from flask import g

from annotator.annotation import Annotation as Annotation_
from annotator.authz import permissions_filter

class Annotation(Annotation_):

    @classmethod
    def stats_for_user(cls, user):
        stats = {}

        q = {'query': {'match_all': {}},
             'filter': {'and': [permissions_filter(g.user),
                                {'or': [{'term': {'user': user.id}},
                                        {'term': {'user.id': user.id}}]}]}}

        res = cls.es.conn.count({'filtered': q}, cls.es.index, cls.__type__)
        stats['num_annotations'] = res['count']

        uris_res = cls.es.conn.search_raw({
            'query': {'filtered': q},
            'facets': {'uri': {'terms': {'field': 'uri'}}},
            'size': 0
        }, cls.es.index, cls.__type__)
        stats['num_uris'] = len(uris_res['facets']['uri']['terms'])

        return stats

{'fraction_non_alphanumeric': 0.17614577581446714, 'fraction_numerical': 0.0011043622308117063, 'mean_word_length': 2.247311827956989, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '219169', 'n_tokens_mistral': 550, 'n_tokens_neox': 526, 'n_words': 118}