This repository has been archived on 2023-07-17. You can view files and clone it, but cannot push or open issues or pull requests.
pushee/submission.py

87 lines
2.3 KiB
Python
Raw Normal View History

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:
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:
match = re.search(r"<pre>((.*\s+)+)<\/pre>", self.mail)
return match.group(1) if match else self.mail
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)