2019-11-30 17:47:52 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
|
|
|
|
import datetime
|
2019-11-30 22:47:08 +01:00
|
|
|
import re
|
2019-11-30 17:47:52 +01:00
|
|
|
from typing import Dict, List
|
|
|
|
|
|
|
|
|
|
|
|
class Submission:
|
2020-06-08 17:39:36 +02:00
|
|
|
MAIL_CONTENT = re.compile(r"<pre>((.*\s+)+)<\/pre>")
|
2020-05-25 23:49:52 +02:00
|
|
|
|
2019-11-30 17:47:52 +01:00
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
uco: str,
|
|
|
|
login: str,
|
|
|
|
path: str,
|
2019-12-02 10:52:57 +01:00
|
|
|
submission_id: str,
|
2019-11-30 17:47:52 +01:00
|
|
|
points: float,
|
|
|
|
homework: str,
|
|
|
|
correction: bool,
|
2019-11-30 22:47:08 +01:00
|
|
|
mail: str,
|
2019-11-30 17:47:52 +01:00
|
|
|
) -> None:
|
|
|
|
self.uco = uco
|
|
|
|
self.login = login
|
|
|
|
self.path = path
|
2019-12-02 10:52:57 +01:00
|
|
|
self.submission_id = submission_id
|
2019-11-30 17:47:52 +01:00
|
|
|
self.points = points
|
|
|
|
self.homework = homework
|
|
|
|
self.correction = correction
|
2019-11-30 22:47:08 +01:00
|
|
|
self.mail = mail
|
2019-11-30 17:47:52 +01:00
|
|
|
|
|
|
|
self.submitted_at = None
|
|
|
|
self.submitted_before_deadline = None
|
|
|
|
self.flag = None
|
|
|
|
self.branch = f"{homework}{'-opravne' if correction else ''}-{login}"
|
|
|
|
self.__set_submission_date()
|
|
|
|
|
|
|
|
def __set_submission_date(self) -> None:
|
|
|
|
self.submitted_at = datetime.datetime.strptime(
|
2019-12-02 10:52:57 +01:00
|
|
|
self.submission_id[-16:], "%Y_%m%d_%H%M%S"
|
2019-11-30 17:47:52 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
def set_late_tag(self, deadline: datetime.datetime) -> None:
|
|
|
|
self.submitted_before_deadline = self.submitted_at < deadline
|
|
|
|
if not self.submitted_before_deadline:
|
|
|
|
self.flag = "LATE"
|
|
|
|
|
2019-11-30 22:47:08 +01:00
|
|
|
def get_mail(self) -> str:
|
2020-05-25 23:49:52 +02:00
|
|
|
left = self.mail.find("<pre>")
|
|
|
|
right = self.mail.rfind("</pre>")
|
2020-06-08 17:39:36 +02:00
|
|
|
return self.mail[left + 5 : right]
|
2019-11-30 22:47:08 +01:00
|
|
|
|
2019-11-30 17:47:52 +01:00
|
|
|
|
|
|
|
def print_submissions(all_submissions: Dict[str, List[Submission]]) -> None:
|
|
|
|
header = (
|
|
|
|
"| "
|
|
|
|
+ " | ".join(
|
|
|
|
[
|
|
|
|
"###",
|
|
|
|
"UCO".center(6),
|
|
|
|
"LOGIN".center(8),
|
|
|
|
"SUBMITTED".center(19),
|
|
|
|
"POINTS",
|
|
|
|
"FLAG".center(6),
|
|
|
|
]
|
|
|
|
)
|
|
|
|
+ " |"
|
|
|
|
)
|
|
|
|
SEPARATOR = "-" * len(header)
|
|
|
|
print(SEPARATOR)
|
|
|
|
print(header)
|
|
|
|
print(SEPARATOR)
|
|
|
|
|
|
|
|
FORMAT = "| {:>3} | {:>6s} | {:>8s} | {} | {:>6.2f} | {:^6s} |"
|
|
|
|
|
|
|
|
for _, submissions in all_submissions.items():
|
|
|
|
for i, submission in enumerate(submissions):
|
|
|
|
date = submission.submitted_at.strftime("%Y-%m-%d %H:%M:%S")
|
|
|
|
print(
|
|
|
|
FORMAT.format(
|
|
|
|
i,
|
|
|
|
submission.uco if i == 0 else "",
|
|
|
|
submission.login if i == 0 else "",
|
|
|
|
date,
|
|
|
|
submission.points,
|
|
|
|
submission.flag if submission.flag else "",
|
|
|
|
)
|
|
|
|
)
|
|
|
|
print(SEPARATOR)
|