-
Notifications
You must be signed in to change notification settings - Fork 96
Feature: last submission status #606
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
Changes from 5 commits
ca5a416
05a8d71
4f31d3f
82061c0
d68b141
1bb825b
3185609
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -154,28 +154,51 @@ def problems_list_view(request): | |
| # 6) submissions_limit | ||
| # 7) can_submit | ||
| # Sorted by (start_date, end_date, round name, problem name) | ||
| # Preload user-related data to avoid N+1 queries | ||
| pi_ids = [pi.id for pi in problem_instances] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we need this array? i believe it creates a sql query |
||
| results_map = {} | ||
| last_submission_map = {} | ||
| if request.user.is_authenticated: | ||
| # Bulk fetch UserResultForProblem objects. We only keep those for which | ||
| # the user can see the submission score. | ||
| user_results_qs = ( | ||
| UserResultForProblem.objects.filter(user__id=request.user.id, problem_instance_id__in=pi_ids) | ||
| .select_related("submission_report__submission") | ||
| ) | ||
| for r in user_results_qs: | ||
| # Some controllers may hide score even if UserResultForProblem exists | ||
| if r and r.submission_report and controller.can_see_submission_score(request, r.submission_report.submission): | ||
| results_map[r.problem_instance_id] = r | ||
|
|
||
| # Bulk fetch user's submissions for the problem instances and build a map | ||
| # of latest submission per problem instance. Submissions are ordered by | ||
| # date descending, so the first occurrence for a given problem_instance | ||
| # is the latest one. | ||
| submissions_qs = ( | ||
| Submission.objects.filter( | ||
| user__id=request.user.id, | ||
| problem_instance_id__in=pi_ids, | ||
| kind="NORMAL" # ignore ignored submissions | ||
| ) | ||
| .order_by("-date") | ||
| ) | ||
| for s in submissions_qs: | ||
| pid = s.problem_instance_id | ||
| if pid not in last_submission_map: | ||
| last_submission_map[pid] = s | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it shouldn't always fetch last submission, for example in some contests max submission counts as the score (OI, OIJ). In this PR #405 there are functions implemented that return scored submission effectively. Maybe you can copy them here.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As for me this looks safe, the column is clearly marked as "the last submission" and the link is pointing to a a submission that have been used
m4teuk marked this conversation as resolved.
Outdated
m4teuk marked this conversation as resolved.
Outdated
|
||
|
|
||
| problems_statements = sorted( | ||
| [ | ||
| ( | ||
| pi, | ||
| controller.can_see_statement(request, pi), | ||
| controller.get_round_times(request, pi.round), | ||
| problems_limits.get(pi.pk, None), | ||
| # Because this view can be accessed by an anynomous user we can't | ||
| # use `user=request.user` (it would cause TypeError). Surprisingly | ||
| # using request.user.id is ok since for AnynomousUser id is set | ||
| # to None. | ||
| next( | ||
| ( | ||
| r | ||
| for r in UserResultForProblem.objects.filter(user__id=request.user.id, problem_instance=pi) | ||
| if r and r.submission_report and controller.can_see_submission_score(request, r.submission_report.submission) | ||
| ), | ||
| None, | ||
| ), | ||
| results_map.get(pi.id), | ||
| pi.controller.get_submissions_left(request, pi), | ||
| pi.controller.get_submissions_limit(request, pi), | ||
| controller.can_submit(request, pi) and not is_contest_archived(request), | ||
| submission_template_context(request, last_submission_map[pi.id]) if pi.id in last_submission_map else None, | ||
| ) | ||
| for pi in problem_instances | ||
| ], | ||
|
|
@@ -185,6 +208,7 @@ def problems_list_view(request): | |
| show_submissions_limit = any(p[6] for p in problems_statements) | ||
| show_submit_button = any(p[7] for p in problems_statements) | ||
| show_rounds = len(frozenset(pi.round_id for pi in problem_instances)) > 1 | ||
| show_status = request.user.is_authenticated # Always show status for authenticated users | ||
| table_columns = 3 + int(show_problems_limits) + int(show_submissions_limit) + int(show_submit_button) | ||
|
|
||
| return TemplateResponse( | ||
|
|
@@ -196,6 +220,7 @@ def problems_list_view(request): | |
| "show_rounds": show_rounds, | ||
| "show_scores": request.user.is_authenticated, | ||
| "show_submissions_limit": show_submissions_limit, | ||
| "show_status": show_status, | ||
| "show_submit_button": show_submit_button, | ||
| "table_columns": table_columns, | ||
| "problems_on_page": getattr(settings, "PROBLEMS_ON_PAGE", 100), | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.