Skip to content

Commit

Permalink
Merge pull request #439 from SELab-2/status-fix
Browse files Browse the repository at this point in the history
chore: no extra checks fix
  • Loading branch information
francisvaut authored May 21, 2024
2 parents 2119595 + 9552a46 commit 5dff24e
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions backend/api/serializers/project_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -33,6 +34,22 @@ def to_representation(self, instance: Project):
if (groups_submitted > non_empty_groups):
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,
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,
Expand All @@ -46,18 +63,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)
Expand Down

0 comments on commit 5dff24e

Please sign in to comment.