예제 #1
0
    def test_data_in_index(self):
        """Verify the data we are indexing."""
        r = reply(locale='de', save=True)

        self.refresh()

        eq_(ReplyMetricsMappingType.search().count(), 1)
        data = ReplyMetricsMappingType.search().values_dict()[0]
        eq_(data['locale'], r.locale)
        eq_(data['creator_id'], r.user_id)
예제 #2
0
    def test_add_and_delete(self):
        """Adding a reply should add it to the index.

        Deleting should delete it.
        """
        r = reply(save=True)
        self.refresh()
        eq_(ReplyMetricsMappingType.search().count(), 1)

        r.delete()
        self.refresh()
        eq_(ReplyMetricsMappingType.search().count(), 0)
예제 #3
0
파일: utils.py 프로젝트: Bootz/kitsune
def top_contributors_aoa(start=None, end=None, locale=None, count=10, page=1, use_cache=True):
    """Get the top Army of Awesome contributors."""

    if use_cache:
        cache_key = u'{}_{}_{}_{}_{}'.format(start, end, locale, count, page)
        cache_key = hashlib.sha1(cache_key.encode('utf-8')).hexdigest()
        cache_key = u'top_contributors_aoa_{}'.format(cache_key)
        cached = cache.get(cache_key, None)

        if cached:
            return cached

    # Get the user ids and contribution count of the top contributors.
    query = ReplyMetricsMappingType.search()

    # twitter only does language
    locale = locale.split('-')[0] if locale else None

    query = _apply_filters(query, start, end, locale)
    tweets = [q.id for q in query.all()[:HUGE_NUMBER]]
    users = (User.objects
             .filter(tweet_replies__in=tweets)
             .annotate(query_count=Count('tweet_replies'))
             .order_by('-query_count'))

    counts = _get_creator_counts(users, count, page)
    if use_cache:
        cache.set(cache_key, counts, 60*15)  # 15 minutes
    return counts
예제 #4
0
파일: utils.py 프로젝트: timbury/kitsune
def top_contributors_aoa(start=None,
                         end=None,
                         locale=None,
                         count=10,
                         page=1,
                         use_cache=True):
    """Get the top Army of Awesome contributors."""

    if use_cache:
        cache_key = u'{}_{}_{}_{}_{}'.format(start, end, locale, count, page)
        cache_key = hashlib.sha1(cache_key.encode('utf-8')).hexdigest()
        cache_key = u'top_contributors_aoa_{}'.format(cache_key)
        cached = cache.get(cache_key, None)

        if cached:
            return cached

    # Get the user ids and contribution count of the top contributors.
    query = ReplyMetricsMappingType.search()

    # twitter only does language
    locale = locale.split('-')[0] if locale else None

    query = _apply_filters(query, start, end, locale)
    tweets = [q.id for q in query.all()[:HUGE_NUMBER]]
    users = (User.objects.filter(tweet_replies__in=tweets).annotate(
        query_count=Count('tweet_replies')).order_by('-query_count'))

    counts = _get_creator_counts(users, count, page)
    if use_cache:
        cache.set(cache_key, counts, 60 * 15)  # 15 minutes
    return counts
예제 #5
0
파일: utils.py 프로젝트: rik/kitsune
def top_contributors_aoa(start=None, end=None, locale=None, count=10, page=1):
    """Get the top Army of Awesome contributors."""
    # Get the user ids and contribution count of the top contributors.
    query = ReplyMetricsMappingType.search().facet("creator_id", filtered=True, size=BIG_NUMBER)

    # twitter only does language
    locale = locale.split("-")[0] if locale else None

    query = _apply_filters(query, start, end, locale)

    return _get_creator_counts(query, count, page)
예제 #6
0
def top_contributors_aoa(start=None, end=None, locale=None, count=10, page=1):
    """Get the top Army of Awesome contributors."""
    # Get the user ids and contribution count of the top contributors.
    query = (ReplyMetricsMappingType.search().facet('creator_id',
                                                    filtered=True,
                                                    size=BIG_NUMBER))

    # twitter only does language
    locale = locale.split('-')[0] if locale else None

    query = _apply_filters(query, start, end, locale)

    return _get_creator_counts(query, count, page)