Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: no extra checks fix #439

Merged
merged 4 commits into from
May 21, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 24 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,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()
francisvaut marked this conversation as resolved.
Show resolved Hide resolved

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)
Comment on lines +39 to +51
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're bored, I'm fairly certain this can be optimized as in terms of the amount of db calls.
However I'm good to leave it like that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🌏


passed_structure_checks_submission_ids = StructureCheckResult.objects.filter(
submission__group__project=instance,
submission__is_valid=True,
Expand All @@ -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)
Expand Down