From a1a656551e474183ac0a4325ab93bf41a965101c Mon Sep 17 00:00:00 2001 From: Michael Bauer <michael-bauer@posteo.de> Date: Wed, 8 May 2024 18:58:08 +0200 Subject: [PATCH] Implement statistics query resolvers --- aleksis/apps/alsijil/schema/__init__.py | 10 ++++++++ aleksis/apps/alsijil/schema/statistics.py | 29 +++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/aleksis/apps/alsijil/schema/__init__.py b/aleksis/apps/alsijil/schema/__init__.py index 6ac95c44e..0c7c299f0 100644 --- a/aleksis/apps/alsijil/schema/__init__.py +++ b/aleksis/apps/alsijil/schema/__init__.py @@ -174,6 +174,16 @@ class Query(graphene.ObjectType): return lessons_for_person + @staticmethod + def resolve_statistics_by_person(root, info, person_id, term_id): + # TODO: Annotate person with necessary information for term_id. + return Person.objects.get(id=person_id) + + @staticmethod + def resolve_statistics_by_group(root, info, group_id, term_id): + # TODO: Annotate persons with necessary information for term_id. + return Group.objects.get(id=group_id).members.all() + class Mutation(graphene.ObjectType): create_or_update_documentations = DocumentationBatchCreateOrUpdateMutation.Field() diff --git a/aleksis/apps/alsijil/schema/statistics.py b/aleksis/apps/alsijil/schema/statistics.py index ed9fff17b..37b893784 100644 --- a/aleksis/apps/alsijil/schema/statistics.py +++ b/aleksis/apps/alsijil/schema/statistics.py @@ -1,15 +1,23 @@ import graphene +from aleksis.apps.kolego.models.absence import AbsenceReason from aleksis.apps.kolego.schema.absence import AbsenceReasonType +from ..models import ExtraMark from .personal_note import ExtraMarkType class AbsenceReasonWithCountType(graphene.ObjectType): absence_reason = graphene.Field(AbsenceReasonType) count = graphene.Int() + def resolve_count(root, info): + return 6 + class ExtraMarkWithCountType(graphene.ObjectType): extra_mark = graphene.Field(ExtraMarkType) count = graphene.Int() + def resolve_count(root, info): + return 7 + class StatisticsByPersonType(graphene.ObjectType): participation_count = graphene.Int() absence_count = graphene.Int() @@ -17,3 +25,24 @@ class StatisticsByPersonType(graphene.ObjectType): tardiness_sum = graphene.Int() tardiness_count = graphene.Int() extra_marks = graphene.List(ExtraMarkWithCountType) + + def resolve_participation_count(root, info): + return 3 + + def resolve_absence_count(root, info): + return 1 + + def resolve_absence_reasons(root, info): + # TODO: Return actual AbsenceReasons + # Needed by resolve_absence_count as well. + return AbsenceReason.objects.all() + + def resolve_tardiness_sum(root, info): + return 17 + + def resolve_tardiness_count(root, info): + return 5 + + def resolve_extra_marks(root, info): + # TODO: Return actual ExtraMarks + return ExtraMark.objects.all() -- GitLab