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
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
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. """ results = [] for repo in scope.repos: stats = Statistic.queryset_for_range(repo, author=None, interval='DY', start=scope.start, end=scope.end) stat2 = Statistic.compute_interval_statistic(stats, interval='DY', repo=repo, author=None, start=scope.start, end=scope.end) stat2 = stat2.to_dict() stat2['name'] = repo.name # providing pk's for link columns in the repo chart for x in ['details1', 'details2', 'details3']: stat2[x] = repo.pk results.append(stat2) results = sorted(results, key=lambda x: x['name']) return json.dumps(results)
def add_stat(author, repo): stat1 = Statistic.queryset_for_range(repo, author=author, start=scope.start, end=scope.end, interval=scope.interval) stat2 = Statistic.compute_interval_statistic(stat1, interval=scope.interval, repo=repo, author=author, start=scope.start, end=scope.end) stat2 = stat2.to_dict() stat2['author'] = author.email stat2['repo'] = repo.name if stat2['lines_changed']: # skip authors with no contribution in the time range results.append(stat2)