Skip to content

Commit

Permalink
Merge pull request #309 from parthsharma2/stable-demo
Browse files Browse the repository at this point in the history
stable-demo: added metrics & api-docs from dev
  • Loading branch information
sgoggins authored Jun 30, 2019
2 parents 26e675f + c9f4472 commit 12a3ff6
Show file tree
Hide file tree
Showing 17 changed files with 10,852 additions and 851 deletions.
93 changes: 90 additions & 3 deletions augur/datasources/augur_db/augur_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,54 @@ def issue_duration(self, repo_group_id, repo_id=None):
results['duration'] = results['duration'].astype(str)
return results

@annotate(tag='issue-participants')
def issue_participants(self, repo_group_id, repo_id=None):
"""Returns number of participants per issue.
:param repo_group_id: The repository's repo_group_id
:param repo_id: The repository's repo_id, defaults to None
:return: DataFrame of count of participants per issue.
"""
if not repo_id:
issue_participants_SQL = s.sql.text("""
SELECT
repo_id,
derived.issue_id,
COUNT(DISTINCT derived.cntrb_id) AS participants
FROM (
(SELECT issue_id, cntrb_id FROM issues WHERE cntrb_id IS NOT NULL)
UNION
(SELECT issue_id, cntrb_id FROM issue_message_ref, message
WHERE issue_message_ref.msg_id = message.msg_id)
) AS derived, issues
WHERE derived.issue_id = issues.issue_id
AND repo_id IN (SELECT repo_id FROM repo WHERE repo_group_id = :repo_group_id)
GROUP BY repo_id, derived.issue_id
ORDER BY repo_id
""")

result = pd.read_sql(issue_participants_SQL, self.db, params={'repo_group_id': repo_group_id})
return result
else:
issue_participants_SQL = s.sql.text("""
SELECT
derived.issue_id,
COUNT(DISTINCT derived.cntrb_id) AS participants
FROM (
(SELECT issue_id, cntrb_id FROM issues WHERE cntrb_id IS NOT NULL)
UNION
(SELECT issue_id, cntrb_id FROM issue_message_ref, message
WHERE issue_message_ref.msg_id = message.msg_id)
) AS derived, issues
WHERE derived.issue_id = issues.issue_id
AND repo_id = :repo_id
GROUP BY repo_id, derived.issue_id
ORDER BY repo_id
""")

result = pd.read_sql(issue_participants_SQL, self.db, params={'repo_id': repo_id})
return result

@annotate(tag='issue-backlog')
def issue_backlog(self, repo_group_id, repo_id=None):
"""Returns number of issues currently open.
Expand Down Expand Up @@ -778,6 +826,45 @@ def issue_backlog(self, repo_group_id, repo_id=None):
result = pd.read_sql(issue_backlog_SQL, self.db, params={'repo_id': repo_id})
return result

@annotate(tag='issue-throughput')
def issue_throughput(self, repo_group_id, repo_id=None):
"""Returns the ratio of issues closed to total issues
:param repo_group_id: The repository's repo_group_id
:param repo_id: The repository's repo_id, defaults to None
:return: DataFrame of ratio of issues closed to total issues.
"""
if not repo_id:
issue_throughput_SQL = s.sql.text("""
SELECT table1.repo_id, (tot1 / tot2) AS throughput
FROM
(SELECT repo_id, COUNT(issue_id)::REAL AS tot1
FROM issues WHERE issue_state='closed'
AND repo_id IN (SELECT repo_id FROM repo WHERE repo_group_id = :repo_group_id)
GROUP BY repo_id) AS table1,
(SELECT repo_id, COUNT(issue_id)::REAL AS tot2
FROM issues
WHERE repo_id IN (SELECT repo_id FROM repo WHERE repo_group_id = :repo_group_id)
GROUP BY repo_id) AS table2
WHERE table1.repo_id = table2.repo_id
""")

results = pd.read_sql(issue_throughput_SQL, self.db, params={'repo_group_id': repo_group_id})
return results

else:
issue_throughput_SQL = s.sql.text("""
SELECT (tot1 / tot2) AS throughput
FROM
(SELECT COUNT(issue_id)::REAL AS tot1 FROM issues
WHERE issue_state='closed' AND repo_id=:repo_id) AS table1,
(SELECT COUNT(issue_id)::REAL AS tot2 FROM issues
WHERE repo_id=:repo_id) AS table2
""")

result = pd.read_sql(issue_throughput_SQL, self.db, params={'repo_id': repo_id})
return result

@annotate(tag='issues-open-age')
def issues_open_age(self, repo_group_id, repo_id=None):
"""
Expand Down Expand Up @@ -851,13 +938,13 @@ def issues_closed_resolution_duration(self, repo_group_id, repo_id=None):
FROM issues
WHERE closed_at NOTNULL AND repo_id = :repo_id
GROUP BY gh_issue_number, issue_title, created_at, closed_at, DIFFDATE
ORDER BY DIFFDATE DESC
ORDER BY DIFFDATE DESC
""")
results = pd.read_sql(issueSQL, self.db,
params={'repo_id': repo_id})

return results

#####################################
### RISK ###
#####################################
Expand Down Expand Up @@ -1056,7 +1143,7 @@ def open_issues_count(self, repo_group_id, repo_id=None):
""")
results = pd.read_sql(openIssueCountSQL, self.db, params={'repo_id': repo_id})
return results


@annotate(tag='closed-issues-count')
def closed_issues_count(self, repo_group_id, repo_id=None):
Expand Down
Loading

0 comments on commit 12a3ff6

Please sign in to comment.