From 9d8d41bfd5969d6815793458768d6e3ef5122d82 Mon Sep 17 00:00:00 2001 From: Witold Date: Wed, 20 Nov 2024 12:26:32 +0100 Subject: [PATCH] feat: adjust analyzed object stats to take in consideration object detail --- lab/schema.py | 15 ++++++++++----- lab/tests/test_schema.py | 4 ++-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/lab/schema.py b/lab/schema.py index fab9e6944..e83817ae9 100644 --- a/lab/schema.py +++ b/lab/schema.py @@ -6,7 +6,7 @@ from django.db.models import F, Sum from django.utils import timezone -from .models import ObjectGroup, Project, Run +from .models import Object, ObjectGroup, Project, Run StatPeriodLiteral = Literal["all", "year"] @@ -39,11 +39,16 @@ def get_total_projects(period: StatPeriodLiteral): return qs.count() @staticmethod - def get_total_object_groups(period: StatPeriodLiteral): + def get_total_analyzed_objects(period: StatPeriodLiteral): run_qs = Run.objects.filter(end_date__lte=timezone.now()) if period == "year": run_qs = run_qs.filter(start_date__gte=THIS_YEAR_START_DT) - return ObjectGroup.objects.filter(runs__in=run_qs).count() + object_group_qs = ObjectGroup.objects.filter(runs__in=run_qs) + object_qs = Object.objects.filter(group__in=object_group_qs) + object_group_count = object_group_qs.count() + object_count = object_qs.count() + distinct_object_group_count = object_qs.values("group").distinct().count() + return object_group_count + object_count - distinct_object_group_count @staticmethod def get_total_hours(period: StatPeriodLiteral): @@ -64,12 +69,12 @@ def resolve_stats(self, info): return { "all": LabStatType( total_projects=LabStatsType.get_total_projects("all"), - total_object_groups=LabStatsType.get_total_object_groups("all"), + total_object_groups=LabStatsType.get_total_analyzed_objects("all"), total_hours=LabStatsType.get_total_hours("all"), ), "year": LabStatType( total_projects=LabStatsType.get_total_projects("year"), - total_object_groups=LabStatsType.get_total_object_groups("year"), + total_object_groups=LabStatsType.get_total_analyzed_objects("year"), total_hours=LabStatsType.get_total_hours("year"), ), } diff --git a/lab/tests/test_schema.py b/lab/tests/test_schema.py index 5bdbf0100..b0e2b1391 100644 --- a/lab/tests/test_schema.py +++ b/lab/tests/test_schema.py @@ -59,8 +59,8 @@ def test_resolve_stats(client): assert executed == { "data": { "stats": { - "all": {"totalProjects": 3, "totalObjectGroups": 3, "totalHours": 18}, - "year": {"totalProjects": 2, "totalObjectGroups": 2, "totalHours": 12}, + "all": {"totalProjects": 3, "totalObjectGroups": 9, "totalHours": 18}, + "year": {"totalProjects": 2, "totalObjectGroups": 6, "totalHours": 12}, } } }