blob: 87aa713b671b140203786b75d86f2e895a402c0c [file] [log] [blame]
Patrick Williams4ea34132022-01-07 06:05:13 -06001#!/usr/bin/python3
2
3import argparse
4import json
5import os
6
7
8class subcmd:
9 def __init__(self, parser: argparse._SubParsersAction) -> None:
Patrick Williamsa3db66b2022-12-04 16:27:08 -060010 p = parser.add_parser("report", help="Create final report")
Patrick Williams4ea34132022-01-07 06:05:13 -060011
12 p.set_defaults(cmd=self)
13
Patrick Williams4ea34132022-01-07 06:05:13 -060014 def run(self, args: argparse.Namespace) -> int:
15 commits_fp = os.path.join(args.dir, "commits.json")
16 reviews_fp = os.path.join(args.dir, "reviews.json")
17
18 results = {}
19
20 if not os.path.isfile(commits_fp):
Ed Tanous385fd072022-02-17 13:03:06 -080021 print("Missing commits.json; run analyze-commits?")
Patrick Williams4ea34132022-01-07 06:05:13 -060022 return 1
23
24 if not os.path.isfile(reviews_fp):
Ed Tanous385fd072022-02-17 13:03:06 -080025 print("Missing reviews.json; run analyze-reviews?")
Patrick Williams4ea34132022-01-07 06:05:13 -060026 return 1
27
28 with open(commits_fp, "r") as commits_file:
29 commits = json.load(commits_file)
30
31 with open(reviews_fp, "r") as reviews_file:
32 reviews = json.load(reviews_file)
33
34 for user in sorted(set(commits.keys()).union(reviews.keys())):
35 user_commits = len(commits.get(user, []))
36 user_reviews = len(reviews.get(user, []))
37
38 points = user_commits * 3 + user_reviews
39 print(user, points, user_commits, user_reviews)
40
41 qualified = points >= 15
42
Patrick Williamsa3db66b2022-12-04 16:27:08 -060043 results[user] = {
44 "qualified": qualified,
45 "points": points,
46 "commits": user_commits,
47 "reviews": user_reviews,
48 }
Patrick Williams4ea34132022-01-07 06:05:13 -060049
50 with open(os.path.join(args.dir, "report.json"), "w") as outfile:
Patrick Williamsa3db66b2022-12-04 16:27:08 -060051 outfile.write(json.dumps(results, indent=4))
Patrick Williams4ea34132022-01-07 06:05:13 -060052
53 return 0