Chromium Code Reviews| Index: infra/tools/antibody/compute_stats.py |
| diff --git a/infra/tools/antibody/compute_stats.py b/infra/tools/antibody/compute_stats.py |
| index 7490b6dcfa9518395967bbb8382df92fd02f993f..5c8f5156899d6fdcb9877c8c5761ec96c161d0c5 100644 |
| --- a/infra/tools/antibody/compute_stats.py |
| +++ b/infra/tools/antibody/compute_stats.py |
| @@ -39,10 +39,10 @@ def totaled_ratio_calculator(numerator, denominator): |
| Return: |
| ratio(float): a ratio rounded to three decimal places |
| """ |
| - if denominator != 0: |
| + if denominator != 0: |
| ratio = round(float(numerator) / denominator, 3) |
| else: |
| - raise ZeroDivisionError |
| + ratio = 0 |
| return ratio |
| @@ -313,9 +313,12 @@ def totaled_tbr_no_lgtm(cc, sql_time_specification): # pragma: no cover |
| returned results |
| Return: |
| - result(int): a count of all commits with a TBR and no lgtm |
| + count(int): a count of all commits with a TBR and no lgtm |
| + results(list): a list of lists with all tbr'ed commits with no lgtm in the |
| + format [rietveld_url, git_timestamp, git_subject, git_hash] |
| """ |
| - cc.execute("""SELECT COUNT(*) |
| + cc.execute("""SELECT git_commit.review_url, git_commit.timestamp, |
| + git_commit.subject, git_commit.hash |
| FROM review |
| INNER JOIN git_commit |
| ON review.review_url = git_commit.review_url |
| @@ -329,8 +332,17 @@ def totaled_tbr_no_lgtm(cc, sql_time_specification): # pragma: no cover |
| ON review.review_url = lgtm_count.review_url |
| WHERE lgtm_count.c = 0 OR lgtm_count.c IS NULL |
| AND commit_people.type = 'tbr' AND %s""" % sql_time_specification) |
| - result = cc.fetchone() |
| - return int(result[0]) |
| + result = cc.fetchall() |
| + count = len(result) |
| + results = [] |
| + parsed_commit = [] |
| + for commit in result: |
| + parsed_commit.append(commit[0]) |
| + parsed_commit.append(commit[1].strftime("%Y-%m-%d %H:%M:%S")) |
| + parsed_commit.append(commit[2]) |
| + parsed_commit.append(commit[3]) |
| + results.append(parsed_commit) |
|
pgervais
2015/07/27 20:50:47
Not sure this does what you want. parsed_commit is
|
| + return count, results |
| def totaled_blank_tbr(cc, sql_time_specification): # pragma: no cover |
| @@ -343,16 +355,28 @@ def totaled_blank_tbr(cc, sql_time_specification): # pragma: no cover |
| returned results |
| Return: |
| - result(int): a count of all blank TBRs (TBR=) |
| + count(int): a count of all blank TBRs (TBR=) |
| + results(list): a list of lists with all tbr'ed commits with no lgtm in the |
| + format [rietveld_url, git_timestamp, git_subject, git_hash] |
| """ |
| - cc.execute("""SELECT COUNT(*) |
| + cc.execute("""SELECT git_commit.review_url, git_commit.timestamp, |
| + git_commit.subject, git_commit.hash |
| FROM commit_people |
| INNER JOIN git_commit |
| ON commit_people.git_commit_hash = git_commit.hash |
| WHERE commit_people.people_email_address = 'NOBODY' |
| AND %s""" % sql_time_specification) |
| - result = cc.fetchone() |
| - return int(result[0]) |
| + result = cc.fetchall() |
| + count = len(result) |
| + results = [] |
| + parsed_commit = [] |
| + for commit in result: |
| + parsed_commit.append(commit[0]) |
| + parsed_commit.append(commit[1].strftime("%Y-%m-%d %H:%M:%S")) |
| + parsed_commit.append(commit[2]) |
| + parsed_commit.append(commit[3]) |
| + results.append(parsed_commit) |
| + return count, results |
| def totaled_no_review_url(cc, sql_time_specification): # pragma: no cover |
| @@ -364,13 +388,25 @@ def totaled_no_review_url(cc, sql_time_specification): # pragma: no cover |
| returned results |
| Return: |
| - result(int): a count of all commits with no review_url |
| + count(int): a count of all commits with no review_url |
| + results(list): a list of lists with all tbr'ed commits with no lgtm in the |
| + format [rietveld_url, git_timestamp, git_subject, git_hash] |
| """ |
| - cc.execute("""SELECT COUNT(*) |
| + cc.execute("""SELECT git_commit.review_url, git_commit.timestamp, |
| + git_commit.subject, git_commit.hash |
| FROM git_commit |
| WHERE review_url IS NULL AND %s""" % sql_time_specification) |
| - result = cc.fetchone() |
| - return int(result[0]) |
| + result = cc.fetchall() |
| + count = len(result) |
| + results = [] |
| + parsed_commit = [] |
| + for commit in result: |
| + parsed_commit.append(commit[0]) |
| + parsed_commit.append(commit[1].strftime("%Y-%m-%d %H:%M:%S")) |
| + parsed_commit.append(commit[2]) |
| + parsed_commit.append(commit[3]) |
| + results.append(parsed_commit) |
| + return count, results |
| # TODO(keelerh): change the SQL query to avoid using temporary tables |
| @@ -490,8 +526,10 @@ def compute_stats_by_time(cc): # pragma: no cover |
| Returns: |
| output(list): three dictionaries containing stats for the past 7 days, 30 |
| days, and all time respectively, each including timeframe, |
| - suspicious_to_total_ratio, total_commits, tbr_no_lgtm, |
| - no_review_url, blank_tbr |
| + suspicious_to_total_ratio, a count of the number of commits |
| + for total_commits, tbr_no_lgtm, no_review_url, and blank_tbr, |
| + and a list of lists with the relevant commits for |
| + tbr_no_lgtm, no_review_url, and blank_tbr |
| """ |
| stats_7_days = {'timeframe': '7_days'} |
| stats_30_days = {'timeframe': '30_days'} |
| @@ -508,9 +546,16 @@ def compute_stats_by_time(cc): # pragma: no cover |
| d['suspicious_to_total_ratio'] = totaled_ratio_calculator(tot_suspicious, |
| tot_commits) |
| d['total_commits'] = tot_commits |
| - d['tbr_no_lgtm'] = totaled_tbr_no_lgtm(cc, sql_insert) |
| - d['no_review_url'] = totaled_no_review_url(cc, sql_insert) |
| - d['blank_tbr'] = totaled_blank_tbr(cc, sql_insert) |
| + count_tbr_no_lgtm, tbr_no_lgtm_commits = totaled_tbr_no_lgtm(cc, sql_insert) |
| + d['tbr_no_lgtm'] = count_tbr_no_lgtm |
| + d['tbr_no_lgtm_commits'] = tbr_no_lgtm_commits |
| + count_no_review_url, no_review_url_commits = totaled_no_review_url( |
| + cc, sql_insert) |
| + d['no_review_url'] = count_no_review_url |
| + d['no_review_url_commits'] = no_review_url_commits |
| + count_blank_tbr, blank_tbr_commits = totaled_blank_tbr(cc, sql_insert) |
| + d['blank_tbr'] = count_blank_tbr |
| + d['blank_tbr_commits'] = blank_tbr_commits |
| output = [stats_7_days, stats_30_days, stats_all_time] |
| return output |