Skip to content

fix: Simplify attempts #2449

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

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ jobs:
run: |
pip install pipenv
pipenv install --dev --system
pip install -U git+https://github.com/ocadotechnology/rapid-router@simpify_attempts
yarn --frozen-lockfile
- name: Collect static
run: python manage.py collectstatic --noinput --settings example_project.portal_test_settings
Expand Down
20 changes: 7 additions & 13 deletions portal/views/student/play.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,30 +110,24 @@ def _compute_scores(
"""
num_completed = num_top_scores = total_available_score = 0
total_score = 0.0
# Get a QuerySet of best attempts for each level
best_attempts = Attempt.objects.filter(
level__in=levels, student=student, is_best_attempt=True
).select_related("level")
# Get a QuerySet of attempts for each level
attempts = Attempt.objects.filter(level__in=levels, student=student)

for level in levels:
total_available_score += _get_max_score_for_level(level)

# For each level, compare best attempt's score with level's max score and
# increment variables as needed
if best_attempts:
attempts_dict = {
best_attempt.level.id: best_attempt
for best_attempt in best_attempts
}
if attempts:
for level in levels:
attempt = attempts_dict.get(level.id)
attempt = attempts.filter(level=level.id)

if attempt and attempt.score:
if attempt.exists():
num_completed += 1
if attempt.score == _get_max_score_for_level(level):
if attempt[0].score == _get_max_score_for_level(level):
num_top_scores += 1

total_score += attempt.score
total_score += attempt[0].score

return {
"num_completed": num_completed,
Expand Down