Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import json | 5 import json |
| 6 | 6 |
| 7 | 7 |
| 8 def ratio_calculator(numerator, denominator): | 8 def ratio_calculator(numerator, denominator): |
| 9 """Computes the ratio of the counts in two lists | 9 """Computes the ratio of the counts in two lists |
| 10 | 10 |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 32 def totaled_ratio_calculator(numerator, denominator): | 32 def totaled_ratio_calculator(numerator, denominator): |
| 33 """Computes the ratio of the counts in two lists | 33 """Computes the ratio of the counts in two lists |
| 34 | 34 |
| 35 Args: | 35 Args: |
| 36 numerator(int): a totaled count | 36 numerator(int): a totaled count |
| 37 denominator(int): a totaled count | 37 denominator(int): a totaled count |
| 38 | 38 |
| 39 Return: | 39 Return: |
| 40 ratio(float): a ratio rounded to three decimal places | 40 ratio(float): a ratio rounded to three decimal places |
| 41 """ | 41 """ |
| 42 if denominator != 0: | 42 if denominator != 0: |
| 43 ratio = round(float(numerator) / denominator, 3) | 43 ratio = round(float(numerator) / denominator, 3) |
| 44 else: | 44 else: |
| 45 raise ZeroDivisionError | 45 ratio = 0 |
| 46 return ratio | 46 return ratio |
| 47 | 47 |
| 48 | 48 |
| 49 # functions that return stats calculated as lists of lists by month | 49 # functions that return stats calculated as lists of lists by month |
| 50 def total_commits(cc): # pragma: no cover | 50 def total_commits(cc): # pragma: no cover |
| 51 """Counts all the git commits sorted by month and year | 51 """Counts all the git commits sorted by month and year |
| 52 | 52 |
| 53 Args: | 53 Args: |
| 54 cc(cursor) | 54 cc(cursor) |
| 55 | 55 |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 306 def totaled_tbr_no_lgtm(cc, sql_time_specification): # pragma: no cover | 306 def totaled_tbr_no_lgtm(cc, sql_time_specification): # pragma: no cover |
| 307 """Counts the number of commits with a TBR that have not been lgtm'ed | 307 """Counts the number of commits with a TBR that have not been lgtm'ed |
| 308 in a given timeframe | 308 in a given timeframe |
| 309 | 309 |
| 310 Args: | 310 Args: |
| 311 cc(cursor) | 311 cc(cursor) |
| 312 sql_time_specification(str): a sql command to limit the dates of the | 312 sql_time_specification(str): a sql command to limit the dates of the |
| 313 returned results | 313 returned results |
| 314 | 314 |
| 315 Return: | 315 Return: |
| 316 result(int): a count of all commits with a TBR and no lgtm | 316 count(int): a count of all commits with a TBR and no lgtm |
| 317 results(list): a list of lists with all tbr'ed commits with no lgtm in the | |
| 318 format [rietveld_url, git_timestamp, git_subject, git_hash] | |
| 317 """ | 319 """ |
| 318 cc.execute("""SELECT COUNT(*) | 320 cc.execute("""SELECT git_commit.review_url, git_commit.timestamp, |
| 321 git_commit.subject, git_commit.hash | |
| 319 FROM review | 322 FROM review |
| 320 INNER JOIN git_commit | 323 INNER JOIN git_commit |
| 321 ON review.review_url = git_commit.review_url | 324 ON review.review_url = git_commit.review_url |
| 322 INNER JOIN commit_people | 325 INNER JOIN commit_people |
| 323 ON commit_people.git_commit_hash = git_commit.hash | 326 ON commit_people.git_commit_hash = git_commit.hash |
| 324 LEFT JOIN ( | 327 LEFT JOIN ( |
| 325 SELECT review_url, COUNT(*) AS c | 328 SELECT review_url, COUNT(*) AS c |
| 326 FROM review_people | 329 FROM review_people |
| 327 WHERE type = 'lgtm' | 330 WHERE type = 'lgtm' |
| 328 GROUP BY review_url) lgtm_count | 331 GROUP BY review_url) lgtm_count |
| 329 ON review.review_url = lgtm_count.review_url | 332 ON review.review_url = lgtm_count.review_url |
| 330 WHERE lgtm_count.c = 0 OR lgtm_count.c IS NULL | 333 WHERE lgtm_count.c = 0 OR lgtm_count.c IS NULL |
| 331 AND commit_people.type = 'tbr' AND %s""" % sql_time_specification) | 334 AND commit_people.type = 'tbr' AND %s""" % sql_time_specification) |
| 332 result = cc.fetchone() | 335 result = cc.fetchall() |
| 333 return int(result[0]) | 336 count = len(result) |
| 337 results = [] | |
| 338 parsed_commit = [] | |
| 339 for commit in result: | |
| 340 parsed_commit.append(commit[0]) | |
| 341 parsed_commit.append(commit[1].strftime("%Y-%m-%d %H:%M:%S")) | |
| 342 parsed_commit.append(commit[2]) | |
| 343 parsed_commit.append(commit[3]) | |
| 344 results.append(parsed_commit) | |
|
pgervais
2015/07/27 20:50:47
Not sure this does what you want. parsed_commit is
| |
| 345 return count, results | |
| 334 | 346 |
| 335 | 347 |
| 336 def totaled_blank_tbr(cc, sql_time_specification): # pragma: no cover | 348 def totaled_blank_tbr(cc, sql_time_specification): # pragma: no cover |
| 337 """Counts the number of occurences of TBR= with no reviewer listed in a | 349 """Counts the number of occurences of TBR= with no reviewer listed in a |
| 338 given timeframe | 350 given timeframe |
| 339 | 351 |
| 340 Args: | 352 Args: |
| 341 cc(cursor) | 353 cc(cursor) |
| 342 sql_time_specification(str): a sql command to limit the dates of the | 354 sql_time_specification(str): a sql command to limit the dates of the |
| 343 returned results | 355 returned results |
| 344 | 356 |
| 345 Return: | 357 Return: |
| 346 result(int): a count of all blank TBRs (TBR=) | 358 count(int): a count of all blank TBRs (TBR=) |
| 359 results(list): a list of lists with all tbr'ed commits with no lgtm in the | |
| 360 format [rietveld_url, git_timestamp, git_subject, git_hash] | |
| 347 """ | 361 """ |
| 348 cc.execute("""SELECT COUNT(*) | 362 cc.execute("""SELECT git_commit.review_url, git_commit.timestamp, |
| 363 git_commit.subject, git_commit.hash | |
| 349 FROM commit_people | 364 FROM commit_people |
| 350 INNER JOIN git_commit | 365 INNER JOIN git_commit |
| 351 ON commit_people.git_commit_hash = git_commit.hash | 366 ON commit_people.git_commit_hash = git_commit.hash |
| 352 WHERE commit_people.people_email_address = 'NOBODY' | 367 WHERE commit_people.people_email_address = 'NOBODY' |
| 353 AND %s""" % sql_time_specification) | 368 AND %s""" % sql_time_specification) |
| 354 result = cc.fetchone() | 369 result = cc.fetchall() |
| 355 return int(result[0]) | 370 count = len(result) |
| 371 results = [] | |
| 372 parsed_commit = [] | |
| 373 for commit in result: | |
| 374 parsed_commit.append(commit[0]) | |
| 375 parsed_commit.append(commit[1].strftime("%Y-%m-%d %H:%M:%S")) | |
| 376 parsed_commit.append(commit[2]) | |
| 377 parsed_commit.append(commit[3]) | |
| 378 results.append(parsed_commit) | |
| 379 return count, results | |
| 356 | 380 |
| 357 | 381 |
| 358 def totaled_no_review_url(cc, sql_time_specification): # pragma: no cover | 382 def totaled_no_review_url(cc, sql_time_specification): # pragma: no cover |
| 359 """Counts the number of commits with no review url in a given timeframe | 383 """Counts the number of commits with no review url in a given timeframe |
| 360 | 384 |
| 361 Args: | 385 Args: |
| 362 cc(cursor) | 386 cc(cursor) |
| 363 sql_time_specification(str): a sql command to limit the dates of the | 387 sql_time_specification(str): a sql command to limit the dates of the |
| 364 returned results | 388 returned results |
| 365 | 389 |
| 366 Return: | 390 Return: |
| 367 result(int): a count of all commits with no review_url | 391 count(int): a count of all commits with no review_url |
| 392 results(list): a list of lists with all tbr'ed commits with no lgtm in the | |
| 393 format [rietveld_url, git_timestamp, git_subject, git_hash] | |
| 368 """ | 394 """ |
| 369 cc.execute("""SELECT COUNT(*) | 395 cc.execute("""SELECT git_commit.review_url, git_commit.timestamp, |
| 396 git_commit.subject, git_commit.hash | |
| 370 FROM git_commit | 397 FROM git_commit |
| 371 WHERE review_url IS NULL AND %s""" % sql_time_specification) | 398 WHERE review_url IS NULL AND %s""" % sql_time_specification) |
| 372 result = cc.fetchone() | 399 result = cc.fetchall() |
| 373 return int(result[0]) | 400 count = len(result) |
| 401 results = [] | |
| 402 parsed_commit = [] | |
| 403 for commit in result: | |
| 404 parsed_commit.append(commit[0]) | |
| 405 parsed_commit.append(commit[1].strftime("%Y-%m-%d %H:%M:%S")) | |
| 406 parsed_commit.append(commit[2]) | |
| 407 parsed_commit.append(commit[3]) | |
| 408 results.append(parsed_commit) | |
| 409 return count, results | |
| 374 | 410 |
| 375 | 411 |
| 376 # TODO(keelerh): change the SQL query to avoid using temporary tables | 412 # TODO(keelerh): change the SQL query to avoid using temporary tables |
| 377 def tbr_to_total_people_ratio(cc, | 413 def tbr_to_total_people_ratio(cc, |
| 378 sql_time_specification=''): # pragma: no cover | 414 sql_time_specification=''): # pragma: no cover |
| 379 """Calculate TBR stats by author for the Antibody leaderboard and writes | 415 """Calculate TBR stats by author for the Antibody leaderboard and writes |
| 380 them to a json file | 416 them to a json file |
| 381 | 417 |
| 382 Args: | 418 Args: |
| 383 cc(cursor) | 419 cc(cursor) |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 483 | 519 |
| 484 def compute_stats_by_time(cc): # pragma: no cover | 520 def compute_stats_by_time(cc): # pragma: no cover |
| 485 """Computes the stats for the past 7 days, past 30 days, and all time | 521 """Computes the stats for the past 7 days, past 30 days, and all time |
| 486 | 522 |
| 487 Args: | 523 Args: |
| 488 cc(cursor) | 524 cc(cursor) |
| 489 | 525 |
| 490 Returns: | 526 Returns: |
| 491 output(list): three dictionaries containing stats for the past 7 days, 30 | 527 output(list): three dictionaries containing stats for the past 7 days, 30 |
| 492 days, and all time respectively, each including timeframe, | 528 days, and all time respectively, each including timeframe, |
| 493 suspicious_to_total_ratio, total_commits, tbr_no_lgtm, | 529 suspicious_to_total_ratio, a count of the number of commits |
| 494 no_review_url, blank_tbr | 530 for total_commits, tbr_no_lgtm, no_review_url, and blank_tbr, |
| 531 and a list of lists with the relevant commits for | |
| 532 tbr_no_lgtm, no_review_url, and blank_tbr | |
| 495 """ | 533 """ |
| 496 stats_7_days = {'timeframe': '7_days'} | 534 stats_7_days = {'timeframe': '7_days'} |
| 497 stats_30_days = {'timeframe': '30_days'} | 535 stats_30_days = {'timeframe': '30_days'} |
| 498 stats_all_time = {'timeframe': 'all_time'} | 536 stats_all_time = {'timeframe': 'all_time'} |
| 499 for d in [stats_7_days, stats_30_days, stats_all_time]: | 537 for d in [stats_7_days, stats_30_days, stats_all_time]: |
| 500 if d == stats_7_days: | 538 if d == stats_7_days: |
| 501 sql_insert = 'DATEDIFF(NOW(), git_commit.timestamp) <= 7' | 539 sql_insert = 'DATEDIFF(NOW(), git_commit.timestamp) <= 7' |
| 502 elif d == stats_30_days: | 540 elif d == stats_30_days: |
| 503 sql_insert = 'DATEDIFF(NOW(), git_commit.timestamp) <= 30' | 541 sql_insert = 'DATEDIFF(NOW(), git_commit.timestamp) <= 30' |
| 504 elif d == stats_all_time: | 542 elif d == stats_all_time: |
| 505 sql_insert = 'DATEDIFF(git_commit.timestamp, NOW()) < 0' | 543 sql_insert = 'DATEDIFF(git_commit.timestamp, NOW()) < 0' |
| 506 tot_commits = totaled_total_commits(cc, sql_insert) | 544 tot_commits = totaled_total_commits(cc, sql_insert) |
| 507 tot_suspicious = totaled_total_suspicious(cc, sql_insert) | 545 tot_suspicious = totaled_total_suspicious(cc, sql_insert) |
| 508 d['suspicious_to_total_ratio'] = totaled_ratio_calculator(tot_suspicious, | 546 d['suspicious_to_total_ratio'] = totaled_ratio_calculator(tot_suspicious, |
| 509 tot_commits) | 547 tot_commits) |
| 510 d['total_commits'] = tot_commits | 548 d['total_commits'] = tot_commits |
| 511 d['tbr_no_lgtm'] = totaled_tbr_no_lgtm(cc, sql_insert) | 549 count_tbr_no_lgtm, tbr_no_lgtm_commits = totaled_tbr_no_lgtm(cc, sql_insert) |
| 512 d['no_review_url'] = totaled_no_review_url(cc, sql_insert) | 550 d['tbr_no_lgtm'] = count_tbr_no_lgtm |
| 513 d['blank_tbr'] = totaled_blank_tbr(cc, sql_insert) | 551 d['tbr_no_lgtm_commits'] = tbr_no_lgtm_commits |
| 552 count_no_review_url, no_review_url_commits = totaled_no_review_url( | |
| 553 cc, sql_insert) | |
| 554 d['no_review_url'] = count_no_review_url | |
| 555 d['no_review_url_commits'] = no_review_url_commits | |
| 556 count_blank_tbr, blank_tbr_commits = totaled_blank_tbr(cc, sql_insert) | |
| 557 d['blank_tbr'] = count_blank_tbr | |
| 558 d['blank_tbr_commits'] = blank_tbr_commits | |
| 514 output = [stats_7_days, stats_30_days, stats_all_time] | 559 output = [stats_7_days, stats_30_days, stats_all_time] |
| 515 return output | 560 return output |
| 516 | 561 |
| 517 | 562 |
| 518 def all_monthly_stats(cc, filename): # pragma: no cover | 563 def all_monthly_stats(cc, filename): # pragma: no cover |
| 519 """Write stats calculated over different time segments as json to file | 564 """Write stats calculated over different time segments as json to file |
| 520 | 565 |
| 521 Args: | 566 Args: |
| 522 cc(cursor) | 567 cc(cursor) |
| 523 filename(str): the json file to write to | 568 filename(str): the json file to write to |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 549 """Writes stats for the past month Antibody leaderboard to a json file | 594 """Writes stats for the past month Antibody leaderboard to a json file |
| 550 | 595 |
| 551 Args: | 596 Args: |
| 552 cc(cursor) | 597 cc(cursor) |
| 553 filename(str): the json file to write to | 598 filename(str): the json file to write to |
| 554 """ | 599 """ |
| 555 sql_time_specification = 'AND DATEDIFF(NOW(), git_commit.timestamp) <= 30' | 600 sql_time_specification = 'AND DATEDIFF(NOW(), git_commit.timestamp) <= 30' |
| 556 output = tbr_to_total_people_ratio(cc, sql_time_specification) | 601 output = tbr_to_total_people_ratio(cc, sql_time_specification) |
| 557 with open(filename, 'w') as f: | 602 with open(filename, 'w') as f: |
| 558 json.dump(output, f) | 603 json.dump(output, f) |
| OLD | NEW |