Skip to content
Snippets Groups Projects
Verified Commit 765fc1bc authored by Jonathan Weth's avatar Jonathan Weth :keyboard:
Browse files

Improve statistic queries, fix some bugs, include tardiness

parent 667648fc
No related branches found
No related tags found
1 merge request!361Resolve "Add statistics page for absences"
Pipeline #192773 failed
......@@ -10,7 +10,6 @@
:show-select="false"
@items="items = $event"
>
<!-- <template #header.person="header">-->
<!-- Hello world-->
<!-- {{ header }}-->
......@@ -83,7 +82,7 @@ import AbsenceReasonChip from "aleksis.apps.kolego/components/AbsenceReasonChip.
import ExtraMarkChip from "aleksis.apps.alsijil/components/extra_marks/ExtraMarkChip.vue";
import { statisticsByGroup } from "./statistics.graphql";
import { absenceReasons } from "aleksis.apps.kolego/components/absenceReasons.graphql";
import { absenceReasons } from "../absences/absenceReasons.graphql";
import { extraMarks } from "../../extra_marks/extra_marks.graphql";
export default {
......
......@@ -520,12 +520,12 @@ def annotate_person_statistics(
filter=Q(filtered_participation_statuses__absence_reason__count_as_absent=True),
distinct=True,
),
# tardiness=Sum("filtered_participation_statuses__tardiness"),
# tardiness_count=Count(
# "filtered_personal_notes",
# filter=Q(filtered_personal_notes__tardiness__gt=0),
# distinct=True,
# ),
tardiness_sum=Sum("filtered_participation_statuses__tardiness"),
tardiness_count=Count(
"filtered_participation_statuses",
filter=Q(filtered_participation_statuses__tardiness__gt=0),
distinct=True,
),
)
persons = persons.order_by("last_name", "first_name")
......@@ -557,16 +557,16 @@ def annotate_person_statistics(
def annotate_person_statistics_for_school_term(
persons: QuerySet[Person], school_term: SchoolTerm
persons: QuerySet[Person], school_term: SchoolTerm, group: Group | None = None
) -> QuerySet[Person]:
"""Annotate a queryset of persons with class register statistics for a school term."""
documentations = Documentation.objects.filter(
participations__person__in=persons,
datetime_start__date__gte=school_term.date_start,
datetime_end__date__lte=school_term.date_end,
)
if group:
documentations.filter(Q(course__groups=group) | Q(course__groups__parent_groups=group))
docs = list(documentations.values_list("pk", flat=True))
return annotate_person_statistics(
persons,
Q(participations__related_documentation__in=docs),
......
......@@ -272,7 +272,7 @@ class Query(graphene.ObjectType):
)
members = Group.objects.get(id=group).members.all()
return annotate_person_statistics_for_school_term(members, school_term)
return annotate_person_statistics_for_school_term(members, school_term, group=group)
class Mutation(graphene.ObjectType):
......
......@@ -49,14 +49,14 @@ class StatisticsByPersonType(graphene.ObjectType):
def resolve_absence_reasons(root, info):
return [
dict(absence_reason=reason, count=getattr(root, reason.count_label))
for reason in AbsenceReason.objects.all()
for reason in AbsenceReason.objects.filter(tags__short_name="class_register")
]
def resolve_tardiness_sum(root, info):
return 17
return root.tardiness_sum
def resolve_tardiness_count(root, info):
return 5
return root.tardiness_count
def resolve_extra_marks(root, info):
return [
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment