statistics.py 2.97 KiB
import graphene
from aleksis.apps.cursus.models import Subject
from aleksis.apps.cursus.schema import SubjectType
from aleksis.apps.kolego.models.absence import AbsenceReason
from aleksis.apps.kolego.schema.absence import AbsenceReasonType
from aleksis.core.models import Person
from aleksis.core.schema.person import PersonType
from ..models import ExtraMark
from .personal_note import ExtraMarkType
class AbsenceReasonWithCountType(graphene.ObjectType):
absence_reason = graphene.Field(AbsenceReasonType)
count = graphene.Int()
def resolve_absence_reason(root, info):
return root["absence_reason"]
def resolve_count(root, info):
return root["count"]
class ExtraMarkWithCountType(graphene.ObjectType):
extra_mark = graphene.Field(ExtraMarkType)
count = graphene.Int()
def resolve_extra_mark(root, info):
return root["extra_mark"]
def resolve_count(root, info):
return root["count"]
class StatisticsByPersonType(graphene.ObjectType):
person = graphene.Field(PersonType)
participation_count = graphene.Int()
absence_count = graphene.Int()
absence_reasons = graphene.List(AbsenceReasonWithCountType)
tardiness_sum = graphene.Int()
tardiness_count = graphene.Int()
extra_marks = graphene.List(ExtraMarkWithCountType)
@staticmethod
def resolve_person(root: Person, info):
return root
def resolve_absence_reasons(root, info):
return [
dict(absence_reason=reason, count=getattr(root, reason.count_label))
for reason in 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):
return [
dict(extra_mark=extra_mark, count=getattr(root, extra_mark.count_label))
for extra_mark in ExtraMark.objects.all()
]
class DocumentationByPersonType(graphene.ObjectType):
id = graphene.ID()
datetime_start = graphene.Date()
datetime_end = graphene.Date()
group_short_name = graphene.String()
teacher = graphene.Field(PersonType)
subject = graphene.Field(SubjectType)
absences = graphene.List(AbsenceReasonType)
extra_marks = graphene.List(ExtraMarkType)
personal_note = graphene.String()
def resolve_id(root, info):
return 1
def resolve_datetime_start(root, info):
return "2024-05-27T09:00:00+00:00"
def resolve_datetime_end(root, info):
return "2024-05-27T10:00:00+00:00"
def resolve_group_short_name(root, info):
return "11b"
def resolve_teacher(root, info):
return Person.objects.get(id=63)
def resolve_subject(root, info):
return Subject.objects.get(id=1)
def resolve_absences(root, info):
return AbsenceReason.objects.all()
def resolve_extra_marks(root, info):
return ExtraMark.objects.all()
def resolve_personal_note(root, info):
return "All is well:)"