From 129c1f28f395486f4748ac7b0d4822e98c2cab2b Mon Sep 17 00:00:00 2001 From: Frederick Yin Date: Tue, 12 Oct 2021 18:44:30 +0800 Subject: Show JOJ progress, -i argument now optional --- README.md | 4 ++-- leningrade.py | 32 +++++++++++++++++--------------- worker/JOJWorker.py | 14 ++++++++++---- 3 files changed, 29 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 234ded6..1821427 100644 --- a/README.md +++ b/README.md @@ -103,14 +103,14 @@ Finally, we are ready to run Leningrade. If you are not sure, run `python leningrade.py --help`. ``` -usage: leningrade [-h] -n HOMEWORK_NUMBER -i HOMEWORK_ID [-I] [-G] [-J] +usage: leningrade [-h] -n HOMEWORK_NUMBER [-i HOMEWORK_ID] [-I] [-G] [-J] optional arguments: -h, --help show this help message and exit -n HOMEWORK_NUMBER, --homework-number HOMEWORK_NUMBER An integer. For h1, the value should be 1. -i HOMEWORK_ID, --homework-id HOMEWORK_ID - A hexadecimal string obtained from the JOJ URL of the homework. + A hexadecimal string obtained from the JOJ URL of the homework. Can be omitted if -J is set. -I, --no-individual Do not check individual submissions. -G, --no-group Do not check group submission. -J, --no-joj Do not upload group code to JOJ. JOJ may consume a lot of time. Set this flag if your group work has proven to pass JOJ. diff --git a/leningrade.py b/leningrade.py index fe7ee9a..d37a846 100644 --- a/leningrade.py +++ b/leningrade.py @@ -15,8 +15,11 @@ parser.add_argument( parser.add_argument( "-i", "--homework-id", - required=True, - help="A hexadecimal string obtained from the JOJ URL of the homework.", + required=False, + help=( + "A hexadecimal string obtained from the JOJ URL of the homework. " + "Can be omitted if -J is set." + ), ) parser.add_argument( "-I", @@ -60,19 +63,6 @@ gitWorker = GitWorker(args, HGROUP, None, LANGUAGE, MANDATORY_FILES, OPTIONAL_FI giteaWorker = GiteaWorker(args, GITEA_API_BASE, GITEA_ORG, GITEA_TOKEN, HGROUP) jojWorker = JOJWorker(args, JOJ_COURSE_ID, JOJ_SESSION_ID, HGROUP) -JOJ_INFO = { - "homeworkID": cli_args.homework_id, - "lang": LANGUAGE, - # "problemInfo": [ - # # filenames, problem ID, # of test cases - # (["ex2.m"], "61553cffb3c06a0006f45da3", 10), - # (["ex4.m"], "61553e5fb3c06a0006f45da9", 10), - # (["ex5.m"], "61553f8cb3c06a0006f45db2", 10), - # (["ex6.m"], "6155414cb3c06a0006f45dc7", 10), - # ], - "problemInfo": problem_info(cli_args.homework_id), -} - indvScores = {} groupScores = {} jojScores = {} @@ -90,6 +80,18 @@ if not cli_args.no_group: groupScores[key] = {**groupScores.get(key, {}), **tmpScores.get(key, {})} # JOJ (This will consume a lot of time when the code is in MATLAB) if not cli_args.no_joj: + JOJ_INFO = { + "homeworkID": cli_args.homework_id, + "lang": LANGUAGE, + # "problemInfo": [ + # # filenames, problem ID, # of test cases + # (["ex2.m"], "61553cffb3c06a0006f45da3", 10), + # (["ex4.m"], "61553e5fb3c06a0006f45da9", 10), + # (["ex5.m"], "61553f8cb3c06a0006f45db2", 10), + # (["ex6.m"], "6155414cb3c06a0006f45dc7", 10), + # ], + "problemInfo": problem_info(cli_args.homework_id), + } print("JOJ is now running (this may take a while)...") jojScores = jojWorker.checkGroupJOJ(JOJ_INFO) diff --git a/worker/JOJWorker.py b/worker/JOJWorker.py index 4e17956..4846096 100644 --- a/worker/JOJWorker.py +++ b/worker/JOJWorker.py @@ -24,6 +24,7 @@ class JOJWorker(): self.courseID = courseID self.hgroups = hgroups self.logger = logger + self.joj_progress = 0 # number of JOJ problems checked def uploadZip(self, homeworkID, problemID, zipPath, lang): files = { @@ -112,10 +113,15 @@ class JOJWorker(): # self.checkGroupJOJProcess, # [[HGROUP_NO, hwNum, jojInfo, fns, problemID] # for fns, problemID, _ in jojInfo["problemInfo"]]) - scores = [ - self.checkGroupJOJProcess(HGROUP_NO, hwNum, jojInfo, fns, problemID) - for fns, problemID, _ in jojInfo["problemInfo"] - ] + scores = [] + for fns, problemID, _ in jojInfo["problemInfo"]: + scores.append( + self.checkGroupJOJProcess(HGROUP_NO, hwNum, jojInfo, fns, problemID) + ) + files = ", ".join(jojInfo["problemInfo"][self.joj_progress][0]) + self.joj_progress += 1 + problem_count = len(jojInfo["problemInfo"]) + print(f"-> Checked: {files} ({self.joj_progress}/{problem_count})") scores = [(scores[i], jojInfo["problemInfo"][i][2]) for i in range(len(scores))] self.logger.info(f"{key} h{hwNum} score {scores.__repr__()}") -- cgit v1.2.3