Skip to content
Snippets Groups Projects

Resolve "Add task for checking plausibility of data"

Merged Jonathan Weth requested to merge 91-add-task-for-checking-plausibility-of-data into master
All threads resolved!
Compare and Show latest version
2 files
+ 47
26
Compare changes
  • Side-by-side
  • Inline
Files
2
import logging
from django.contrib.contenttypes.models import ContentType
from django.db.models import F
from django.db.models.expressions import ExpressionWrapper, Func, Value
from django.db.models.fields import DateField
from django.db.models.functions import Concat
from django.db.models.query_utils import Q
from django.utils.translation import gettext as _
from calendarweek import CalendarWeek
from aleksis.apps.chronos.util.date import week_weekday_to_date
from aleksis.core.data_checks import DATA_CHECK_REGISTRY, DataCheck, IgnoreSolveOption, SolveOption
from aleksis.core.data_checks import DataCheck, IgnoreSolveOption, SolveOption
class DeleteRelatedObjectSolveOption(SolveOption):
@@ -44,7 +43,6 @@ class ResetPersonalNoteSolveOption(SolveOption):
check_result.delete()
@DATA_CHECK_REGISTRY.register
class NoPersonalNotesInCancelledLessonsDataCheck(DataCheck):
name = "no_personal_notes_in_cancelled_lessons"
verbose_name = _("Ensure that there are no personal notes in cancelled lessons")
@@ -69,7 +67,6 @@ class NoPersonalNotesInCancelledLessonsDataCheck(DataCheck):
cls.register_result(note)
@DATA_CHECK_REGISTRY.register
class NoGroupsOfPersonsSetInPersonalNotesDataCheck(DataCheck):
name = "no_groups_of_persons_set_in_personal_notes"
verbose_name = _("Ensure that 'groups_of_person' is set for every personal note")
@@ -91,7 +88,15 @@ class NoGroupsOfPersonsSetInPersonalNotesDataCheck(DataCheck):
cls.register_result(note)
@DATA_CHECK_REGISTRY.register
weekday_to_date = ExpressionWrapper(
Func(
Concat(F("year"), F("week")), Value("IYYYIW"), output_field=DateField(), function="TO_DATE"
)
+ F("lesson_period__period__weekday"),
output_field=DateField(),
)
class LessonDocumentationOnHolidaysDataCheck(DataCheck):
"""Checks for lesson documentation objects on holidays.
@@ -112,21 +117,21 @@ class LessonDocumentationOnHolidaysDataCheck(DataCheck):
from .models import LessonDocumentation
holidays = list(Holiday.objects.all())
holidays = Holiday.objects.all()
documentations = LessonDocumentation.objects.filter(
~Q(topic="") | ~Q(group_note="") | ~Q(homework="")
)
for doc in documentations:
logging.info(f"Check lesson documentation {doc}")
day = week_weekday_to_date(doc.calendar_week, doc.lesson_period.period.weekday)
if len(list(filter(lambda h: h.date_start <= day <= h.date_end, holidays))) > 0:
logging.info(" ... on holidays")
).annotate(actual_date=weekday_to_date)
for holiday in holidays:
docs_filtered_by_date = documentations.filter(
actual_date__gte=holiday.date_start, actual_date__lte=holiday.date_end
)
for doc in docs_filtered_by_date:
logging.info(f"Lesson documentation {doc} is on holidays")
cls.register_result(doc)
@DATA_CHECK_REGISTRY.register
class PersonalNoteOnHolidaysDataCheck(DataCheck):
"""Checks for personal note objects on holidays.
@@ -147,21 +152,21 @@ class PersonalNoteOnHolidaysDataCheck(DataCheck):
from .models import PersonalNote
holidays = list(Holiday.objects.all())
holidays = Holiday.objects.all()
personal_notes = PersonalNote.objects.filter(
~Q(remarks="") | Q(absent=True) | ~Q(late=0) | Q(extra_marks__isnull=False)
)
for note in personal_notes:
logging.info(f"Check personal note {note}")
day = week_weekday_to_date(note.calendar_week, note.lesson_period.period.weekday)
if len(list(filter(lambda h: h.date_start <= day <= h.date_end, holidays))) > 0:
logging.info(" ... on holidays")
).annotate(actual_date=weekday_to_date)
for holiday in holidays:
notes_filtered_by_date = personal_notes.filter(
actual_date__gte=holiday.date_start, actual_date__lte=holiday.date_end
)
for note in notes_filtered_by_date:
logging.info(f"Personal note {note} is on holidays")
cls.register_result(note)
@DATA_CHECK_REGISTRY.register
class ExcusesWithoutAbsences(DataCheck):
name = "excuses_without_absences"
verbose_name = _("Ensure that there are no excused personal notes without an absence")
Loading