diff options
author | BoYanZh <32470225+BoYanZh@users.noreply.github.com> | 2020-10-04 23:19:11 +0800 |
---|---|---|
committer | BoYanZh <32470225+BoYanZh@users.noreply.github.com> | 2020-10-04 23:19:11 +0800 |
commit | 4efb05684b767026344ac6f2edb5118eba79e87c (patch) | |
tree | adbd88655f985649db4d672ad69bf3b2523fb0de | |
parent | 8e7ca6a5100846c187c9059df02077e283416277 (diff) |
update: rubric detail
-rw-r--r-- | VG101GradeHelper.py | 10 | ||||
-rw-r--r-- | worker/CanvasWorker.py | 21 | ||||
-rw-r--r-- | worker/GitWorker.py (renamed from worker/GiteaWorker.py) | 162 |
3 files changed, 107 insertions, 86 deletions
diff --git a/VG101GradeHelper.py b/VG101GradeHelper.py index 5530d57..677a25e 100644 --- a/VG101GradeHelper.py +++ b/VG101GradeHelper.py @@ -4,7 +4,7 @@ import argparse import json import os -from worker import CanvasWorker, GiteaWorker, JOJWorker +from worker import CanvasWorker, GitWorker, JOJWorker from settings import * @@ -62,12 +62,12 @@ if __name__ == "__main__": pwd = os.getcwd() args = parse() indvScores, groupScores, jojScores = {}, {}, {} - giteaWorker = GiteaWorker(args, hgroups, + gitWorker = GitWorker(args, hgroups, [item[0] for item in JOJ_INFO["problemInfo"]]) if args.indv: - indvScores = giteaWorker.checkIndv() + indvScores = gitWorker.checkIndv() if args.group: - groupScores = giteaWorker.checkGroup() + groupScores = gitWorker.checkGroup() if args.joj: jojWorker = JOJWorker(args, JOJ_COURSE_ID, SID, hgroups) jojScores = jojWorker.checkGroupJOJ(JOJ_INFO) @@ -78,4 +78,4 @@ if __name__ == "__main__": if args.upload: canvasWorker.grade2Canvas() if args.proj: - giteaWorker.checkProj(args.proj, args.ms) + gitWorker.checkProj(args.proj, args.ms) diff --git a/worker/CanvasWorker.py b/worker/CanvasWorker.py index 99ad61c..e5457a2 100644 --- a/worker/CanvasWorker.py +++ b/worker/CanvasWorker.py @@ -37,11 +37,16 @@ class CanvasWorker(): for _ in range(scoreInfo.get(key, 0)): score += value[0] comment.append(f"{value[1]}, {value[0]}") - comment.extend( - scoreInfo.get("indvComment", []) + - scoreInfo.get("groupComment", []) + - scoreInfo.get("jojComment", [])) - if not comment: comment = ['good job'] + if not comment: + comment = ['good job'] + else: + comment.insert(0, "Genral Info:") + comment.append("") + comment.append("Detail:") + comment.extend( + scoreInfo.get("indvComment", []) + + scoreInfo.get("groupComment", []) + + scoreInfo.get("jojComment", [])) return { 'submission': { 'posted_grade': score @@ -62,12 +67,12 @@ class CanvasWorker(): name = currentUser.name.strip() if name not in self.names: continue data = self.generateHomeworkData(self.scores[name]) - self.logger.debug(data.__repr__()) - # submission.edit(**data) + self.logger.debug(f"{name} {data.__repr__()}") + submission.edit(**data) def exportScores(self, fileName): json.dump(self.scores, open(fileName, "w"), ensure_ascii=False, indent=4) - self.logger.debug("score dump to score.json succeed")
\ No newline at end of file + self.logger.debug(f"score dump to {fileName} succeed")
\ No newline at end of file diff --git a/worker/GiteaWorker.py b/worker/GitWorker.py index 8bbbe60..1213e98 100644 --- a/worker/GiteaWorker.py +++ b/worker/GitWorker.py @@ -20,6 +20,13 @@ class GiteaWorker(): self.processCount = processCount self.mandatoryFiles = mandatoryFiles + @classmethod + def isREADME(cls, fn): + fn = fn.lower() + if len(fn) < 6: return False + if len(fn) == 6: return fn == "readme" + return fn[:7] == "readme." + def checkProjRepoName(self, arg): id_, name, projNum, *_ = arg eng = re.sub('[\u4e00-\u9fa5]', '', name) @@ -30,13 +37,15 @@ class GiteaWorker(): def checkIndvProcess(self, groupNum, hwNum): tidy = self.args.tidy repoName = f"hgroup-{groupNum:02}" - if not os.path.exists(os.path.join('hwrepos', repoName)): + repoDir = os.path.join('hwrepos', repoName) + hwDir = os.path.join(repoDir, f"h{hwNum}") + if not os.path.exists(repoDir): repo = git.Repo.clone_from( f"https://focs.ji.sjtu.edu.cn/git/vg101/{repoName}", - os.path.join('hwrepos', repoName), + repoDir, branch='master') else: - repo = git.Repo(os.path.join('hwrepos', repoName)) + repo = git.Repo(repoDir) repo.git.fetch() remoteBranches = [ref.name for ref in repo.remote().refs] scores = { @@ -54,68 +63,72 @@ class GiteaWorker(): f"{repoName} {stuID} {stuName} branch missing") scores[stuName]['indvFailSubmit'] = 1 scores[stuName]['indvComment'].append( - "individual branch missing") + "individual branch individual branch missing") continue repo.git.checkout(f"{stuID}", "-f") repo.git.reset('--hard') repo.git.pull("origin", f"{stuID}", "-f") repo.git.reset(f"origin/{stuID}", "--hard") repo.git.clean("-d", "-f", "-x") + self.logger.debug(f"{repoName} {stuID} {stuName} pull succeed") if self.args.dir: - copytree(os.path.join('hwrepos', repoName), + copytree(repoDir, os.path.join('indv', f"{repoName} {stuID} {stuName}"), ignore=ignore_patterns('.git')) - hwDir = os.path.join('hwrepos', repoName, f"h{hwNum}") if not os.path.exists(hwDir): self.logger.warning( f"{repoName} {stuID} {stuName} h{hwNum} dir missing") scores[stuName]['indvFailSubmit'] = 1 scores[stuName]['indvComment'].append( - f"h{hwNum} dir missing") + f"individual branch h{hwNum} dir missing") else: - for fn, path in [(fn, - os.path.join('hwrepos', repoName, - f"h{hwNum}", fn)) - for fn in self.mandatoryFiles]: - if not os.path.exists(path): - self.logger.warning( - f"{repoName} {stuID} {stuName} h{hwNum}/{fn} file missing" - ) - scores[stuName]['indvFailSubmit'] = 1 - scores[stuName]['indvComment'].append( - f"h{hwNum}/{fn} file missing") - self.logger.debug(f"{repoName} {stuID} {stuName} succeed") - if tidy: - dirList = os.listdir(os.path.join('hwrepos', repoName)) + for fn, path in [(fn, os.path.join(hwDir, fn)) + for fn in self.mandatoryFiles]: + if os.path.exists(path): continue + self.logger.warning( + f"{repoName} {stuID} {stuName} h{hwNum}/{fn} file missing" + ) + scores[stuName]['indvFailSubmit'] = 1 + scores[stuName]['indvComment'].append( + f"individual branch h{hwNum}/{fn} file missing") + if not list(filter(GiteaWorker.isREADME, + os.listdir(hwDir))): + self.logger.warning( + f"{repoName} {stuID} {stuName} h{hwNum}/README file missing" + ) + scores[stuName]['indvFailSubmit'] = 1 + scores[stuName]['indvComment'].append( + f"individual branch h{hwNum}/README file missing") + if not tidy: continue + dirList = list( + filter( + lambda x: x not in [ + ".git", *[f"h{n}" for n in range(20)] + ] and not GiteaWorker.isREADME(x), + os.listdir(repoDir))) + if dirList: + self.logger.warning( + f"{repoName} {stuID} {stuName} untidy {dirList.__repr__()}" + ) + scores[stuName]['indvUntidy'] = 1 + scores[stuName]['indvComment'].append( + f"individual branch redundant files: {dirList.__repr__()}" + ) + if os.path.exists(hwDir): + dirList = os.listdir(hwDir) dirList = list( filter( - lambda x: x not in [ - "README.md", "README.txt", "README.rst", - ".git", *[f"h{n}" for n in range(20)] - ], dirList)) + lambda x: not x.startswith("ex") and + not GiteaWorker.isREADME(x), dirList)) if dirList: self.logger.warning( - f"{repoName} {stuID} {stuName} untidy {dirList.__repr__()}" + f"{repoName} {stuID} {stuName} h{hwNum}/ untidy {dirList.__repr__()}" ) scores[stuName]['indvUntidy'] = 1 scores[stuName]['indvComment'].append( f"individual branch redundant files: {dirList.__repr__()}" ) - if os.path.exists(hwDir): - dirList = os.listdir(hwDir) - dirList = list( - filter( - lambda x: not x.startswith("ex") and not x. - startswith("README."), dirList)) - if dirList: - self.logger.warning( - f"{repoName} {stuID} {stuName} h{hwNum}/ untidy {dirList.__repr__()}" - ) - scores[stuName]['indvUntidy'] = 1 - scores[stuName]['indvComment'].append( - f"individual branch redundant files: {dirList.__repr__()}" - ) except Exception: self.logger.error(f"{repoName} {stuID} {stuName} error") self.logger.error(traceback.format_exc()) @@ -150,50 +163,55 @@ class GiteaWorker(): scores[stuName]['groupFailSubmit'] = 1 scores[stuName]['groupComment'].append( f"tags/h{hwNum} missing") - return + return scores repo.git.checkout(f"tags/h{hwNum}", "-f") if not os.path.exists(hwDir): self.logger.warning(f"{repoName} h{hwNum} dir missing") for _, stuName in self.hgroups[repoName]: scores[stuName]['groupFailSubmit'] = 1 - scores[stuName]['groupComment'].append(f"h{hwNum} dir missing") + scores[stuName]['groupComment'].append( + f"master branch h{hwNum} dir missing") else: for fn, path in [(fn, os.path.join(hwDir, fn)) - for fn in self.mandatoryFiles]: - if not os.path.exists(path): - self.logger.warning(f"{repoName} h{hwNum}/{fn} file missing") - for _, stuName in self.hgroups[repoName]: - scores[stuName]['groupFailSubmit'] = 1 - scores[stuName]['groupComment'].append( - f"h{hwNum}/{fn} missing") + for fn in self.mandatoryFiles]: + if os.path.exists(path): continue + self.logger.warning(f"{repoName} h{hwNum}/{fn} file missing") + for _, stuName in self.hgroups[repoName]: + scores[stuName]['groupFailSubmit'] = 1 + scores[stuName]['groupComment'].append( + f"master branch h{hwNum}/{fn} missing") + if not list(filter(GiteaWorker.isREADME, os.listdir(hwDir))): + self.logger.warning(f"{repoName} h{hwNum}/README file missing") + for _, stuName in self.hgroups[repoName]: + scores[stuName]['groupFailSubmit'] = 1 + scores[stuName]['groupComment'].append( + f"master branch h{hwNum}/README file missing") self.logger.debug(f"{repoName} checkout to tags/h{hwNum} succeed") - if tidy: - dirList = os.listdir(repoDir) + if not tidy: return scores + dirList = os.listdir(repoDir) + dirList = list( + filter( + lambda x: x not in [".git", *[f"h{n}" for n in range(20)]] and + not GiteaWorker.isREADME(x), dirList)) + if dirList: + self.logger.warning(f"{repoName} untidy {dirList.__repr__()}") + for _, stuName in self.hgroups[repoName]: + scores[stuName]['groupUntidy'] = 1 + scores[stuName]['groupComment'].append( + f"master branch redundant files: {dirList.__repr__()}") + if os.path.exists(hwDir): + dirList = os.listdir(hwDir) dirList = list( filter( - lambda x: x not in - ["README.md", ".git", *[f"h{n}" for n in range(20)]], - dirList)) + lambda x: not x.startswith("ex") and not GiteaWorker. + isREADME(x), dirList)) if dirList: - self.logger.warning(f"{repoName} untidy {dirList.__repr__()}") + self.logger.warning( + f"{repoName} h{hwNum} untidy {dirList.__repr__()}") for _, stuName in self.hgroups[repoName]: scores[stuName]['groupUntidy'] = 1 scores[stuName]['groupComment'].append( f"master branch redundant files: {dirList.__repr__()}") - if os.path.exists(hwDir): - dirList = os.listdir(hwDir) - dirList = list( - filter( - lambda x: not x.startswith("ex") and not x.startswith( - "README."), dirList)) - if dirList: - self.logger.warning( - f"{repoName} h{hwNum} untidy {dirList.__repr__()}") - for _, stuName in self.hgroups[repoName]: - scores[stuName]['groupUntidy'] = 1 - scores[stuName]['groupComment'].append( - f"master branch redundant files: {dirList.__repr__()}" - ) return scores def checkProjProcess(self, id_, name, projNum, milestoneNum): @@ -214,9 +232,7 @@ class GiteaWorker(): repo.git.pull("origin", "master", "-f") repo.git.reset('--hard') repo.git.clean("-d", "-f", "-x") - if not list( - filter(lambda x: x.lower().startswith('readme'), - os.listdir(repoDir))): + if not list(filter(GiteaWorker.isREADME, os.listdir(repoDir))): self.logger.warning(f"{repoName} README missing") if milestoneNum: tagNames = [tag.name for tag in repo.tags] @@ -241,7 +257,7 @@ class GiteaWorker(): return {k: v for d in res for k, v in d.items()} def checkGroup(self): - hwNum, tidy = self.args.hw, self.args.tidy + hwNum = self.args.hw with multiprocessing.Pool(self.processCount) as p: res = p.starmap(self.checkGroupProcess, [(i, hwNum) |