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

Rankings filter by eligibility ANDed #911

Merged
merged 2 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
21 changes: 19 additions & 2 deletions backend/siarnaq/api/teams/filters.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import structlog
from django.db.models import Count
from rest_framework import filters

logger = structlog.get_logger(__name__)


class TeamOrderingFilter(filters.OrderingFilter):
FIELD_TRANSFORMS = {
Expand Down Expand Up @@ -37,6 +41,19 @@ class TeamEligibilityFilter(filters.BaseFilterBackend):
def filter_queryset(self, request, queryset, view):
if "eligible_for" not in request.query_params:
return queryset
return queryset.filter(
profile__eligible_for__in=request.query_params.getlist("eligible_for")

eligible_for_list = request.query_params.getlist("eligible_for")

# Filter teams that have all the specified eligible_for values
# tricky query, this results in a join becasue eligible_for is a many to many
filtered_teams = (
queryset.filter(profile__eligible_for__in=eligible_for_list)
.annotate(eligible_count=Count("profile__eligible_for"))
.filter(eligible_count=len(eligible_for_list))
)
logger.info(
"TeamEligibilityFilter",
message="TeamEligibilityFilter Query Plan:",
queryPlan=str(filtered_teams.query),
)
return filtered_teams
16 changes: 7 additions & 9 deletions frontend/src/views/Rankings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,13 @@ const Rankings: React.FC = () => {
</div>
</div>

<div className="flex min-h-0 flex-1">
<RankingsTable
data={rankingsData.data}
eligibleFor={queryParams.eligibleFor}
loading={rankingsData.isLoading}
page={queryParams.page}
handlePage={handlePage}
/>
</div>
<RankingsTable
data={rankingsData.data}
eligibleFor={queryParams.eligibleFor}
loading={rankingsData.isLoading}
page={queryParams.page}
handlePage={handlePage}
/>
</div>
);
};
Expand Down
Loading