From a2831bd3047080a23eb9ee2f7d162d2c97bdd5a9 Mon Sep 17 00:00:00 2001 From: francis Date: Mon, 20 May 2024 11:07:10 +0200 Subject: [PATCH 1/3] chore: no extra checks fix --- backend/api/serializers/project_serializer.py | 35 +++++++++++++------ 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/backend/api/serializers/project_serializer.py b/backend/api/serializers/project_serializer.py index b4493229..2cd65ffa 100644 --- a/backend/api/serializers/project_serializer.py +++ b/backend/api/serializers/project_serializer.py @@ -2,6 +2,7 @@ from api.models.group import Group from api.models.project import Project from api.models.submission import Submission, ExtraCheckResult, StructureCheckResult, StateEnum +from api.models.checks import ExtraCheck, StructureCheck from api.serializers.course_serializer import CourseSerializer from django.core.files.uploadedfile import InMemoryUploadedFile from django.utils import timezone @@ -33,6 +34,24 @@ def to_representation(self, instance: Project): if (groups_submitted > non_empty_groups): non_empty_groups = groups_submitted + extra_checks_count = ExtraCheck.objects.filter( + project=instance + ).count() + + if extra_checks_count: + passed_extra_checks_submission_ids = ExtraCheckResult.objects.filter( + submission__group__project=instance, + submission__is_valid=True, + result=StateEnum.SUCCESS + ).values_list('submission__id', flat=True) + + passed_extra_checks_group_ids = Submission.objects.filter( + id__in=passed_extra_checks_submission_ids + ).values_list('group_id', flat=True) + + unique_groups = set(passed_extra_checks_group_ids) + extra_checks_passed = len(unique_groups) + passed_structure_checks_submission_ids = StructureCheckResult.objects.filter( submission__group__project=instance, submission__is_valid=True, @@ -46,18 +65,12 @@ def to_representation(self, instance: Project): unique_groups = set(passed_structure_checks_group_ids) structure_checks_passed = len(unique_groups) - passed_extra_checks_submission_ids = ExtraCheckResult.objects.filter( - submission__group__project=instance, - submission__is_valid=True, - result=StateEnum.SUCCESS - ).values_list('submission__id', flat=True) - - passed_extra_checks_group_ids = Submission.objects.filter( - id__in=passed_extra_checks_submission_ids - ).values_list('group_id', flat=True) + # If there are no extra checks, we can set extra_checks_passed equal to structure_checks_passed + if not extra_checks_count: + extra_checks_passed = structure_checks_passed - unique_groups = set(passed_extra_checks_group_ids) - extra_checks_passed = len(unique_groups) + # If the extra checks succeed, the structure checks also succeed + structure_checks_passed -= extra_checks_passed # The total number of passed extra checks combined with the number of passed structure checks # can never exceed the total number of submissions (the seeder does not account for this restriction) From b634db6bd7ea285280c3dc29cee46923792ae2ee Mon Sep 17 00:00:00 2001 From: francis Date: Tue, 21 May 2024 10:03:47 +0200 Subject: [PATCH 2/3] chore: simplify extra checks count --- backend/api/serializers/project_serializer.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/backend/api/serializers/project_serializer.py b/backend/api/serializers/project_serializer.py index 2cd65ffa..0e150b7e 100644 --- a/backend/api/serializers/project_serializer.py +++ b/backend/api/serializers/project_serializer.py @@ -34,10 +34,8 @@ def to_representation(self, instance: Project): if (groups_submitted > non_empty_groups): non_empty_groups = groups_submitted - extra_checks_count = ExtraCheck.objects.filter( - project=instance - ).count() - + extra_checks_count = instance.extra_checks.count() + if extra_checks_count: passed_extra_checks_submission_ids = ExtraCheckResult.objects.filter( submission__group__project=instance, From 150dd5f3a3bcd447dcf645b2fae175479e92ba77 Mon Sep 17 00:00:00 2001 From: francis Date: Tue, 21 May 2024 10:08:48 +0200 Subject: [PATCH 3/3] fix: linting errors --- backend/api/serializers/project_serializer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/api/serializers/project_serializer.py b/backend/api/serializers/project_serializer.py index 0e150b7e..caa2cec9 100644 --- a/backend/api/serializers/project_serializer.py +++ b/backend/api/serializers/project_serializer.py @@ -35,7 +35,7 @@ def to_representation(self, instance: Project): non_empty_groups = groups_submitted extra_checks_count = instance.extra_checks.count() - + if extra_checks_count: passed_extra_checks_submission_ids = ExtraCheckResult.objects.filter( submission__group__project=instance,