cqwu-ehall/cqwu/types/exam.py

71 lines
1.9 KiB
Python
Raw Normal View History

2023-06-01 09:03:36 +00:00
import datetime
from typing import Tuple
from pydantic import BaseModel
2023-12-29 10:04:00 +00:00
class ExamType:
supplementation: str
""" 开学补缓考 """
graduate: str
""" 毕业年级考试 """
scattered: str
""" 分散考试 """
concentration: str
""" 集中考试 """
def __init__(
self,
supplementation: str = "",
graduate: str = "",
scattered: str = "",
concentration: str = "",
):
self.supplementation = supplementation
self.graduate = graduate
self.scattered = scattered
self.concentration = concentration
2023-06-01 09:03:36 +00:00
class AiExam(BaseModel):
name: str
""" 课程名称 """
credit: float
""" 学分 """
time: str
""" 考试时间 """
position: str
""" 考试地点 """
seat: str
""" 座位号 """
2023-12-29 10:04:00 +00:00
exam_round: str
2023-06-01 09:03:36 +00:00
""" 考试轮次 """
@property
def name_no_id(self) -> str:
2023-12-29 10:04:00 +00:00
"""获取课程名称(去除课程编号)"""
2023-06-01 09:03:36 +00:00
return self.name.split("]")[-1]
2023-06-01 11:17:03 +00:00
@property
def days_left(self) -> int:
2023-12-29 10:04:00 +00:00
"""获取距离考试的天数"""
2023-06-01 11:17:03 +00:00
return (self.get_time()[0] - datetime.datetime.now()).days
2023-06-01 09:03:36 +00:00
def get_time(self) -> Tuple[datetime.datetime, datetime.datetime]:
2023-12-29 10:04:00 +00:00
"""获取格式化后的考试时间"""
2023-06-01 09:03:36 +00:00
# 2023-06-25(18周 星期日)09:00-11:00
day = datetime.datetime.strptime(self.time.split("(")[0], "%Y-%m-%d")
2023-12-29 10:04:00 +00:00
start_time = datetime.datetime.strptime(
self.time.split(")")[1].split("-")[0], "%H:%M"
)
start_time = datetime.datetime(
day.year, day.month, day.day, start_time.hour, start_time.minute
)
end_time = datetime.datetime.strptime(
self.time.split(")")[1].split("-")[1], "%H:%M"
)
end_time = datetime.datetime(
day.year, day.month, day.day, end_time.hour, end_time.minute
)
2023-06-01 09:03:36 +00:00
return start_time, end_time