Filter submissions
This commit is contained in:
parent
d992e18bbd
commit
35ca777f67
2 changed files with 91 additions and 17 deletions
|
@ -2,9 +2,15 @@
|
||||||
|
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
|
import functools
|
||||||
|
import itertools
|
||||||
from mailbox import mbox, mboxMessage
|
from mailbox import mbox, mboxMessage
|
||||||
|
import math
|
||||||
import re
|
import re
|
||||||
from typing import Tuple
|
from typing import Dict, List, Tuple
|
||||||
|
|
||||||
|
|
||||||
|
from submission import Submission, print_submissions
|
||||||
|
|
||||||
|
|
||||||
class Parser:
|
class Parser:
|
||||||
|
@ -38,25 +44,86 @@ class Parser:
|
||||||
match = Parser.get_match_from_mail(Parser.POINTS_REGEX, mail)
|
match = Parser.get_match_from_mail(Parser.POINTS_REGEX, mail)
|
||||||
return float(match.group(1))
|
return float(match.group(1))
|
||||||
|
|
||||||
def submitted_before_deadline(self, submission: str) -> bool:
|
|
||||||
submitted = datetime.datetime.strptime(
|
|
||||||
submission.split("/")[-1][-16:], Parser.DATE_FORMAT
|
|
||||||
)
|
|
||||||
return self.deadline > submitted
|
|
||||||
|
|
||||||
def __init__(self, path: str, deadline: str, correction: bool = False) -> None:
|
def __init__(self, path: str, deadline: str, correction: bool = False) -> None:
|
||||||
self.box = mbox(path)
|
self.box = mbox(path)
|
||||||
|
|
||||||
self.deadline = datetime.datetime.strptime(deadline, Parser.DATE_FORMAT)
|
self.deadline = datetime.datetime.strptime(deadline, Parser.DATE_FORMAT)
|
||||||
|
self.correction = correction
|
||||||
if correction:
|
if correction:
|
||||||
# in case of correction pass the date of
|
# in case of correction pass the date of
|
||||||
# submitting review to IS for automatic computation
|
# submitting review to IS for automatic computation
|
||||||
self.deadline = self.deadline.replace(hour=0, minute=0, second=0)
|
self.deadline = self.deadline.replace(hour=0, minute=0, second=0)
|
||||||
self.deadline += Parser.OFFSET_FOR_CORRECTION
|
self.deadline += Parser.OFFSET_FOR_CORRECTION
|
||||||
|
|
||||||
|
def __get_submissions(self, hw_tag: str) -> Dict[str, List[Submission]]:
|
||||||
|
submissions = []
|
||||||
|
|
||||||
|
for mail in self.box.values():
|
||||||
|
uco, login = Parser.parse_info(mail)
|
||||||
|
path = Parser.parse_submission(mail)
|
||||||
|
points = Parser.parse_points(mail)
|
||||||
|
|
||||||
|
submissions.append(
|
||||||
|
Submission(uco, login, path, points, hw_tag, self.correction)
|
||||||
|
)
|
||||||
|
submissions[-1].set_late_tag(self.deadline)
|
||||||
|
|
||||||
|
submissions.sort(key=lambda e: (e.login, e.submitted_at))
|
||||||
|
return dict(
|
||||||
|
map(
|
||||||
|
lambda val: (val[0], list(val[1])),
|
||||||
|
itertools.groupby(submissions, key=lambda s: s.login),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
def __filter(self, all_submissions: Dict[str, List[Submission]]) -> None:
|
||||||
|
for _, submissions in all_submissions.items():
|
||||||
|
length = len(submissions)
|
||||||
|
i = -1
|
||||||
|
while not submissions[i].submitted_before_deadline and i >= -length:
|
||||||
|
i -= 1
|
||||||
|
|
||||||
|
if i >= -length:
|
||||||
|
submissions[i].flag = "REVIEW"
|
||||||
|
|
||||||
|
def __correct_errors(self, all_submissions: Dict[str, List[Submission]]) -> None:
|
||||||
|
response = input("Do you wish to fix errors? ").strip()
|
||||||
|
if not response or response == "n":
|
||||||
|
return True
|
||||||
|
|
||||||
|
print("Choose indices of submissions that are to be reviewed")
|
||||||
|
for login, submissions in all_submissions.items():
|
||||||
|
response = input(f"==> Choose submission to review for {login}: ").strip()
|
||||||
|
if not response or response == "n":
|
||||||
|
continue
|
||||||
|
|
||||||
|
j = int(response)
|
||||||
|
for i, submission in enumerate(submissions):
|
||||||
|
if submission.flag == "REVIEW":
|
||||||
|
submission.flag = None
|
||||||
|
if i == j:
|
||||||
|
submission.flag = "REVIEW"
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
|
def parse(self, hw_tag: str) -> List[Submission]:
|
||||||
|
def __reducer(lst, submission):
|
||||||
|
if submission.flag == "REVIEW":
|
||||||
|
lst.append(submission)
|
||||||
|
return lst
|
||||||
|
|
||||||
|
submissions = self.__get_submissions(hw_tag)
|
||||||
|
|
||||||
|
self.__filter(submissions)
|
||||||
|
print_submissions(submissions)
|
||||||
|
|
||||||
|
while not self.__correct_errors(submissions):
|
||||||
|
print_submissions(submissions)
|
||||||
|
|
||||||
|
result = []
|
||||||
|
for something in submissions.values():
|
||||||
|
functools.reduce(
|
||||||
|
__reducer, something, result,
|
||||||
|
)
|
||||||
|
return result
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
mails = mbox("~/xyz.mbox")
|
|
||||||
_, mail = mails.popitem()
|
|
||||||
print(Parser.parse_info(mail))
|
|
||||||
print(Parser.parse_submission(mail))
|
|
||||||
print(Parser.parse_points(mail))
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ import sys
|
||||||
|
|
||||||
|
|
||||||
from commands import MergeRequests, UpdateAssignees, Comments, Merge, Test
|
from commands import MergeRequests, UpdateAssignees, Comments, Merge, Test
|
||||||
from constants import SUBMISSIONS
|
from kontr_emails import Parser
|
||||||
|
|
||||||
|
|
||||||
COMMANDS = {
|
COMMANDS = {
|
||||||
|
@ -18,20 +18,27 @@ COMMANDS = {
|
||||||
|
|
||||||
|
|
||||||
def print_usage():
|
def print_usage():
|
||||||
print("Usage:")
|
print(f"{sys.argv[0]} <path_to_mbox> <homework> <correction> <deadline> <command>")
|
||||||
|
print()
|
||||||
|
print("Commands:")
|
||||||
print("\tmrs\t\t\tFetch files and create merge requests for them")
|
print("\tmrs\t\t\tFetch files and create merge requests for them")
|
||||||
print("\tupdate-assignees\tUpdate assignees on MRs")
|
print("\tupdate-assignees\tUpdate assignees on MRs")
|
||||||
print("\tcomments\t\tFetch all comments on MRs")
|
print("\tcomments\t\tFetch all comments on MRs")
|
||||||
print("\tmerge\t\t\tMerge all MRs")
|
print("\tmerge\t\t\tMerge all MRs")
|
||||||
print("\ttest\t\t\tDebugging function")
|
print("\ttest\t\t\tDebugging function")
|
||||||
|
print("Format of date: %Y_%m%d_%H%M%S")
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
if len(sys.argv) < 2 or sys.argv[1] not in COMMANDS:
|
if len(sys.argv) != 6 or sys.argv[5] not in COMMANDS:
|
||||||
print_usage()
|
print_usage()
|
||||||
exit(2)
|
exit(2)
|
||||||
|
|
||||||
COMMANDS[sys.argv[1]](SUBMISSIONS)()
|
_, path, hw, correction, deadline, command = sys.argv
|
||||||
|
correction = correction == "y"
|
||||||
|
|
||||||
|
submissions = Parser(path, deadline, correction).parse(hw)
|
||||||
|
COMMANDS[command](submissions)()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
Reference in a new issue