Exemple #1
0
def author_stats_table(scope, limit=None):
    """
    this drives the author tables, both ranged and non-ranged, accessed off the main repo list.
    the interval 'LF' shows lifetime stats, but elsewhere we just do daily roundups, so this parameter
    should really be a boolean.  The limit parameter is not yet used.
    """

    # FIXME: this performs one query PER author and could be rewritten to be a LOT more intelligent.

    (repos, authors) = scope.standardize_repos_and_authors()
    interval = 'DY'
    stats = Statistic.queryset_for_range(repos=repos,
                                         authors=authors,
                                         start=scope.start,
                                         end=scope.end,
                                         interval=interval)
    data = None
    if not scope.author:
        stats = Statistic.annotate(
            stats.values('author__email')).order_by('author__email')
        data = _annotations_to_table(stats, 'author', 'author__email')
    else:
        stats = Statistic.annotate(
            stats.values('repo__name')).order_by('repo__name')
        data = _annotations_to_table(stats, 'repo', 'repo__name')
    return data
Exemple #2
0
def repo_table(scope):  # repos, start, end):

    #this drives the list of all repos within an organization, showing the statistics for them within the selected
    #time range, along with navigation links.

    (repos, authors) = scope.standardize_repos_and_authors()
    interval = 'DY'
    # FIXME: explain
    repos = [x.pk for x in scope.available_repos.all()]
    stats = Statistic.queryset_for_range(repos=repos,
                                         authors=authors,
                                         start=scope.start,
                                         end=scope.end,
                                         interval=interval)
    stats = Statistic.annotate(
        stats.values('repo__name')).order_by('repo__name')
    data = _annotations_to_table(stats, 'repo', 'repo__name')

    # FIXME: insert in author count, which is ... complicated ... this can be optimized later
    # we should be able to grab every repo and annotate it with the author count in one extra query tops
    # but it might require manually writing it.
    for d in data:
        repo = d['repo']
        author_count = Author.author_count(repo,
                                           start=scope.start,
                                           end=scope.end)
        d['author_count'] = author_count

    # some repos won't have been scanned, and this requires a second query to fill them into the table
    repos = Repository.objects.filter(last_scanned=None,
                                      organization=scope.org)
    for unscanned in repos:
        data.append(dict(repo=unscanned.name))
    return data