tof-voters: add report subcommand
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: Ic8c4321cfee847a6ac19924cb5c8e2716468cb0f
diff --git a/tof-voters/libvoters/entry_point.py b/tof-voters/libvoters/entry_point.py
index 78d963f..1a4e049 100644
--- a/tof-voters/libvoters/entry_point.py
+++ b/tof-voters/libvoters/entry_point.py
@@ -8,6 +8,7 @@
"analyze-commits",
"analyze-reviews",
"dump-gerrit",
+ "report",
]
diff --git a/tof-voters/libvoters/subcmd/report.py b/tof-voters/libvoters/subcmd/report.py
new file mode 100644
index 0000000..c9e096c
--- /dev/null
+++ b/tof-voters/libvoters/subcmd/report.py
@@ -0,0 +1,52 @@
+#!/usr/bin/python3
+
+import argparse
+import json
+import os
+
+
+class subcmd:
+ def __init__(self, parser: argparse._SubParsersAction) -> None:
+ p = parser.add_parser(
+ "report", help="Create final report"
+ )
+
+ p.set_defaults(cmd=self)
+
+
+ def run(self, args: argparse.Namespace) -> int:
+ commits_fp = os.path.join(args.dir, "commits.json")
+ reviews_fp = os.path.join(args.dir, "reviews.json")
+
+ results = {}
+
+ if not os.path.isfile(commits_fp):
+ print("Missing commits.json; run analyze-commits?");
+ return 1
+
+ if not os.path.isfile(reviews_fp):
+ print("Missing reviews.json; run analyze-reviews?");
+ return 1
+
+ with open(commits_fp, "r") as commits_file:
+ commits = json.load(commits_file)
+
+ with open(reviews_fp, "r") as reviews_file:
+ reviews = json.load(reviews_file)
+
+ for user in sorted(set(commits.keys()).union(reviews.keys())):
+ user_commits = len(commits.get(user, []))
+ user_reviews = len(reviews.get(user, []))
+
+ points = user_commits * 3 + user_reviews
+ print(user, points, user_commits, user_reviews)
+
+ qualified = points >= 15
+
+ results[user] = { "qualified": qualified, "points": points,
+ "commits": user_commits, "reviews": user_reviews }
+
+ with open(os.path.join(args.dir, "report.json"), "w") as outfile:
+ outfile.write(json.dumps(results, indent = 4))
+
+ return 0