Patrick Williams | 4ea3413 | 2022-01-07 06:05:13 -0600 | [diff] [blame] | 1 | #!/usr/bin/python3 |
| 2 | |
| 3 | import argparse |
| 4 | import json |
| 5 | import os |
| 6 | |
| 7 | |
| 8 | class subcmd: |
| 9 | def __init__(self, parser: argparse._SubParsersAction) -> None: |
| 10 | p = parser.add_parser( |
| 11 | "report", help="Create final report" |
| 12 | ) |
| 13 | |
| 14 | p.set_defaults(cmd=self) |
| 15 | |
| 16 | |
| 17 | def run(self, args: argparse.Namespace) -> int: |
| 18 | commits_fp = os.path.join(args.dir, "commits.json") |
| 19 | reviews_fp = os.path.join(args.dir, "reviews.json") |
| 20 | |
| 21 | results = {} |
| 22 | |
| 23 | if not os.path.isfile(commits_fp): |
Ed Tanous | 385fd07 | 2022-02-17 13:03:06 -0800 | [diff] [blame] | 24 | print("Missing commits.json; run analyze-commits?") |
Patrick Williams | 4ea3413 | 2022-01-07 06:05:13 -0600 | [diff] [blame] | 25 | return 1 |
| 26 | |
| 27 | if not os.path.isfile(reviews_fp): |
Ed Tanous | 385fd07 | 2022-02-17 13:03:06 -0800 | [diff] [blame] | 28 | print("Missing reviews.json; run analyze-reviews?") |
Patrick Williams | 4ea3413 | 2022-01-07 06:05:13 -0600 | [diff] [blame] | 29 | return 1 |
| 30 | |
| 31 | with open(commits_fp, "r") as commits_file: |
| 32 | commits = json.load(commits_file) |
| 33 | |
| 34 | with open(reviews_fp, "r") as reviews_file: |
| 35 | reviews = json.load(reviews_file) |
| 36 | |
| 37 | for user in sorted(set(commits.keys()).union(reviews.keys())): |
| 38 | user_commits = len(commits.get(user, [])) |
| 39 | user_reviews = len(reviews.get(user, [])) |
| 40 | |
| 41 | points = user_commits * 3 + user_reviews |
| 42 | print(user, points, user_commits, user_reviews) |
| 43 | |
| 44 | qualified = points >= 15 |
| 45 | |
| 46 | results[user] = { "qualified": qualified, "points": points, |
| 47 | "commits": user_commits, "reviews": user_reviews } |
| 48 | |
| 49 | with open(os.path.join(args.dir, "report.json"), "w") as outfile: |
| 50 | outfile.write(json.dumps(results, indent = 4)) |
| 51 | |
| 52 | return 0 |