Skip to content

Commit

Permalink
merge form absent messages into existing lessons and don't show them …
Browse files Browse the repository at this point in the history
…as separate, extra taking place lessons

(cherry picked from commit d6df06b)
  • Loading branch information
Belissimo-T committed Sep 28, 2024
1 parent a5a96f3 commit 64acba3
Showing 1 changed file with 53 additions and 25 deletions.
78 changes: 53 additions & 25 deletions backend/plan_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
from collections import defaultdict
from xml.etree import ElementTree as ET

from stundenplan24_py import indiware_mobil, substitution_plan
from stundenplan24_py import indiware_mobil
from stundenplan24_py import substitution_plan as substitution_plan_sp24

from . import lesson_info, default_plan
from .lesson_info import process_additional_info
Expand Down Expand Up @@ -101,27 +102,30 @@ def __init__(self, plan_kl: str, vplan_kl: str | None, teachers: Teachers, *,
if vplan_kl is None:
self.substitution_plan = None
else:
self.substitution_plan = substitution_plan.SubstitutionPlan.from_xml(ET.fromstring(vplan_kl))
self.substitution_plan = substitution_plan_sp24.SubstitutionPlan.from_xml(ET.fromstring(vplan_kl))
self.add_lessons_for_unavailable_from_subst_plan()

self.fill_in_lesson_times()

self.form_plan_extractor = SubPlanExtractor(
self.plan,
"forms",
self.teachers,
forms_plan=self.plan,
substitution_plan=self.substitution_plan,
plan_type="forms",
teachers=self.teachers,
logger=self._logger
)
self.room_plan_extractor = SubPlanExtractor(
self.plan,
"rooms",
self.teachers,
forms_plan=self.plan,
substitution_plan=self.substitution_plan,
plan_type="rooms",
teachers=self.teachers,
logger=self._logger
)
self.teacher_plan_extractor = SubPlanExtractor(
self.plan,
"teachers",
self.teachers,
forms_plan=self.plan,
substitution_plan=self.substitution_plan,
plan_type="teachers",
teachers=self.teachers,
logger=self._logger
)

Expand Down Expand Up @@ -165,26 +169,33 @@ def add_lessons_for_unavailable_from_subst_plan(self):
lesson.parsed_info = lesson_info.create_literal_parsed_info(info)
self.plan.lessons.lessons.append(lesson)

for form_str in self.substitution_plan.absent_forms:
form, periods = parse_absent_element(form_str)

for period in periods or range(1, 11):
info = f"Klasse {form}{' den ganzen Tag' if not periods else ''} abwesend laut Vertretungsplan"
lesson = Lesson.create_internal(self.plan.indiware_plan.date)
lesson.periods = {period}
lesson.forms = {form}
lesson.info = info
lesson.parsed_info = lesson_info.create_literal_parsed_info(info)

self.plan.lessons.lessons.append(lesson)
# for form_str in self.substitution_plan.absent_forms:
# form, periods = parse_absent_element(form_str)
#
# for period in periods or range(1, 11):
# info = f"Klasse {form}{' den ganzen Tag' if not periods else ''} abwesend laut Vertretungsplan"
# lesson = Lesson.create_internal(self.plan.indiware_plan.date)
# lesson.periods = {period}
# lesson.forms = {form}
# lesson.info = info
# lesson.parsed_info = lesson_info.create_literal_parsed_info(info)
#
# self.plan.lessons.lessons.append(lesson)

def default_plan(self) -> default_plan.DefaultPlanInfo:
return default_plan.DefaultPlanInfo.from_lessons(self.plan.lessons, self.plan.indiware_plan.week)


class SubPlanExtractor:
def __init__(self, forms_plan: Plan, plan_type: typing.Literal["forms", "rooms", "teachers"],
teachers: Teachers, *, logger: logging.Logger):
def __init__(
self,
forms_plan: Plan,
substitution_plan: substitution_plan_sp24.SubstitutionPlan | None,
plan_type: typing.Literal["forms", "rooms", "teachers"],
teachers: Teachers,
*,
logger: logging.Logger
):
self._logger = logger
self.plan_type = plan_type
self.forms_lessons_grouped = (
Expand All @@ -193,6 +204,9 @@ def __init__(self, forms_plan: Plan, plan_type: typing.Literal["forms", "rooms",
.group_blocks_and_lesson_info(origin_plan_type="forms")
)

if substitution_plan is not None:
self.add_form_absent_info(substitution_plan)

if self.plan_type in ("teachers", ):
self.forms_lessons_grouped = self.forms_lessons_grouped.filter(lambda l: not l.is_internal)

Expand All @@ -201,6 +215,20 @@ def __init__(self, forms_plan: Plan, plan_type: typing.Literal["forms", "rooms",

self.extrapolate_lesson_times(self.forms_lessons_grouped)

def add_form_absent_info(self, substitution_plan: substitution_plan_sp24.SubstitutionPlan | None):
for form_str in substitution_plan.absent_forms:
form, periods = parse_absent_element(form_str)

info_str = f"Klasse {form}{' den ganzen Tag' if not periods else ''} abwesend laut Vertretungsplan"
info = lesson_info.create_literal_parsed_info(info_str)

for lesson in self.forms_lessons_grouped:
if (
form in lesson.forms
and (not periods or lesson.periods & set(periods))
):
lesson.parsed_info.paragraphs += info.paragraphs

@staticmethod
def extrapolate_lesson_times(lessons: Lessons):
# very sketchy
Expand Down

0 comments on commit 64acba3

Please sign in to comment.