show schedule context by target type
This commit is contained in:
parent
1003afd6e8
commit
b33256c63e
1 changed files with 33 additions and 9 deletions
|
|
@ -184,14 +184,20 @@ def _minutes_to_time(value: int | None) -> list[int]:
|
||||||
|
|
||||||
|
|
||||||
class Lesson:
|
class Lesson:
|
||||||
def __init__(self, data: dict[str, Any], subgroup_names: list[str]) -> None:
|
def __init__(
|
||||||
|
self,
|
||||||
|
data: dict[str, Any],
|
||||||
|
target_kind: TargetKind,
|
||||||
|
group_names: list[str],
|
||||||
|
) -> None:
|
||||||
self.start = _minutes_to_time(data.get("time_start"))
|
self.start = _minutes_to_time(data.get("time_start"))
|
||||||
self.end = _minutes_to_time(data.get("time_end"))
|
self.end = _minutes_to_time(data.get("time_end"))
|
||||||
self.name = str(data.get("name") or "Без названия")
|
self.name = str(data.get("name") or "Без названия")
|
||||||
self.type = str(data.get("type") or "пара")
|
self.type = str(data.get("type") or "пара")
|
||||||
self.teacher_ids = [str(value) for value in data.get("teacher_ids", [])]
|
self.teacher_ids = [str(value) for value in data.get("teacher_ids", [])]
|
||||||
self.room_ids = [str(value) for value in data.get("room_ids", [])]
|
self.room_ids = [str(value) for value in data.get("room_ids", [])]
|
||||||
self.subgroup_names = subgroup_names
|
self.target_kind = target_kind
|
||||||
|
self.group_names = group_names
|
||||||
self.info = self.teacher_ids + [f"ауд. {room}" for room in self.room_ids]
|
self.info = self.teacher_ids + [f"ауд. {room}" for room in self.room_ids]
|
||||||
self.is_odd_week = bool(data.get("is_odd_week"))
|
self.is_odd_week = bool(data.get("is_odd_week"))
|
||||||
self.is_even_week = bool(data.get("is_even_week"))
|
self.is_even_week = bool(data.get("is_even_week"))
|
||||||
|
|
@ -211,13 +217,19 @@ class Lesson:
|
||||||
minutes = int((lesson_end - now).total_seconds() // 60)
|
minutes = int((lesson_end - now).total_seconds() // 60)
|
||||||
date_text = f"<i>Сейчас идет</i> {lesson_type}, закончится через {max(minutes, 1)} мин."
|
date_text = f"<i>Сейчас идет</i> {lesson_type}, закончится через {max(minutes, 1)} мин."
|
||||||
|
|
||||||
details = [html.escape(teacher) for teacher in self.teacher_ids]
|
teachers = [html.escape(teacher) for teacher in self.teacher_ids]
|
||||||
details.extend(
|
rooms = [
|
||||||
f'<a href="https://rasp.pgups.ru/schedule/room?room={quote(room)}">ауд. {html.escape(room)}</a>'
|
f'<a href="https://rasp.pgups.ru/schedule/room?room={quote(room)}">ауд. {html.escape(room)}</a>'
|
||||||
for room in self.room_ids
|
for room in self.room_ids
|
||||||
)
|
]
|
||||||
if self.subgroup_names:
|
groups = [f"гр. {html.escape(group)}" for group in self.group_names]
|
||||||
details.append(html.escape(", ".join(self.subgroup_names)))
|
|
||||||
|
if self.target_kind == "teacher":
|
||||||
|
details = rooms + groups
|
||||||
|
elif self.target_kind == "room":
|
||||||
|
details = groups + teachers
|
||||||
|
else:
|
||||||
|
details = teachers + rooms + groups
|
||||||
|
|
||||||
info = ", ".join(details) if details else "Дополнительная информация отсутствует"
|
info = ", ".join(details) if details else "Дополнительная информация отсутствует"
|
||||||
return f"<blockquote><b>{html.escape(self.name)}</b>\n{date_text}\n{info}</blockquote>"
|
return f"<blockquote><b>{html.escape(self.name)}</b>\n{date_text}\n{info}</blockquote>"
|
||||||
|
|
@ -236,6 +248,10 @@ class Schedule:
|
||||||
self.weekDay = current.weekday()
|
self.weekDay = current.weekday()
|
||||||
self.days: list[list[Lesson]] = [[] for _ in range(5)]
|
self.days: list[list[Lesson]] = [[] for _ in range(5)]
|
||||||
|
|
||||||
|
groups_by_id = {
|
||||||
|
str(group["id"]): str(group["name"])
|
||||||
|
for group in groups
|
||||||
|
}
|
||||||
target_ids = {target["id"]}
|
target_ids = {target["id"]}
|
||||||
child_names: dict[str, str] = {}
|
child_names: dict[str, str] = {}
|
||||||
field = {"group": "group_ids", "room": "room_ids", "teacher": "teacher_ids"}[target["kind"]]
|
field = {"group": "group_ids", "room": "room_ids", "teacher": "teacher_ids"}[target["kind"]]
|
||||||
|
|
@ -254,8 +270,16 @@ class Schedule:
|
||||||
matched_ids = target_ids.intersection(map(str, raw_lesson.get(field, [])))
|
matched_ids = target_ids.intersection(map(str, raw_lesson.get(field, [])))
|
||||||
if not matched_ids:
|
if not matched_ids:
|
||||||
continue
|
continue
|
||||||
subgroup_names = sorted(child_names[item] for item in matched_ids if item in child_names)
|
if target["kind"] == "group":
|
||||||
self.days[weekday - 1].append(Lesson(raw_lesson, subgroup_names))
|
group_names = sorted(child_names[item] for item in matched_ids if item in child_names)
|
||||||
|
else:
|
||||||
|
group_names = sorted(
|
||||||
|
{
|
||||||
|
groups_by_id.get(str(group_id), str(group_id))
|
||||||
|
for group_id in raw_lesson.get("group_ids", [])
|
||||||
|
}
|
||||||
|
)
|
||||||
|
self.days[weekday - 1].append(Lesson(raw_lesson, target["kind"], group_names))
|
||||||
|
|
||||||
for day in self.days:
|
for day in self.days:
|
||||||
day.sort(key=lambda lesson: (lesson.start, lesson.name.casefold()))
|
day.sort(key=lambda lesson: (lesson.start, lesson.name.casefold()))
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue