Skip to content
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
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ markdown-it-py==3.0.0
mdurl==0.1.2
numpy==2.3.1
oauthlib==3.2.2
orjson==3.11.4
packaging==25.0
pandas==2.3.1
pillow==10.4.0
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
'djangorestframework',
'drf-yasg',
'isic-challenge-scoring>=5.8',
'orjson',
'requests',
'rules',
# See https://github.com/axnsan12/drf-yasg/issues/874
Expand Down
14 changes: 7 additions & 7 deletions stade/core/templates/leaderboards.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,25 +89,25 @@ <h1 class="m-0 text-2xl font-normal text-gray-800">{{ challenge.name }} Leaderbo
<tr class="cursor-pointer transition-colors duration-200 hover:bg-gray-100" @click="toggleDetails({{ submission.id }})" data-submission-id="{{ submission.id }}">
<td class="py-2 px-4 border-b border-gray-300">{{ forloop.counter }}</td>
<td class="py-2 px-4 border-b border-gray-300">
<div>{{ submission.approach.team.name }}</div>
{% if submission.approach.team.institution %}
<div>{{ submission.approach__team__name }}</div>
{% if submission.approach__team__institution %}
<div class="text-sm text-gray-600 mt-0.5">
{{ submission.approach.team.institution }}
{{ submission.approach__team__institution }}
</div>
{% endif %}
</td>
<td class="py-2 px-4 border-b border-gray-300">{{ submission.approach.name }}</td>
<td class="py-2 px-4 border-b border-gray-300">{{ submission.approach__name }}</td>
<td class="py-2 px-4 border-b border-gray-300">
{% if submission.approach.manuscript_url %}
<a href="{{ submission.approach.manuscript_url }}" target="_blank" title="View manuscript">
{% if submission.approach__manuscript_url %}
<a href="{{ submission.approach__manuscript_url }}" target="_blank" title="View manuscript">
<i class="material-icons text-green-600">description</i>
</a>
{% else %}
-
{% endif %}
</td>
<td class="py-2 px-4 border-b border-gray-300">
{% if submission.approach.uses_external_data %}
{% if submission.approach__uses_external_data %}
<div class="flex items-center gap-1">
<i class="material-icons text-orange-600">public</i>
<span>Yes</span>
Expand Down
42 changes: 21 additions & 21 deletions stade/core/tests/test_leaderboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,18 @@ def test_leaderboard_by_approach(task_with_submissions, client):
submissions = resp.context['submissions']
first, second, third, fourth = submissions[:4]

assert first.approach.team.name == 'team_0'
assert first.approach.name == 'approach_0'
assert first.overall_score == 0.95
assert second.approach.team.name == 'team_0'
assert second.approach.name == 'approach_1'
assert second.overall_score == 0.80
assert third.approach.team.name == 'team_1'
assert third.approach.name == 'approach_0'
assert third.overall_score == 0.78
assert fourth.approach.team.name == 'team_3'
assert fourth.approach.name == 'approach_1'
assert fourth.overall_score == 0.60
assert first['approach__team__name'] == 'team_0'
assert first['approach__name'] == 'approach_0'
assert first['overall_score'] == 0.95
assert second['approach__team__name'] == 'team_0'
assert second['approach__name'] == 'approach_1'
assert second['overall_score'] == 0.80
assert third['approach__team__name'] == 'team_1'
assert third['approach__name'] == 'approach_0'
assert third['overall_score'] == 0.78
assert fourth['approach__team__name'] == 'team_3'
assert fourth['approach__name'] == 'approach_1'
assert fourth['overall_score'] == 0.60


@pytest.mark.django_db
Expand All @@ -109,12 +109,12 @@ def test_leaderboard_by_team(task_with_submissions, client):
submissions = resp.context['submissions']
first, second, third = submissions[:3]

assert first.approach.team.name == 'team_5'
assert first.approach.name == 'approach_0'
assert first.overall_score == 0.95
assert second.approach.team.name == 'team_6'
assert second.approach.name == 'approach_0'
assert second.overall_score == 0.78
assert third.approach.team.name == 'team_8'
assert third.approach.name == 'approach_1'
assert third.overall_score == 0.60
assert first['approach__team__name'] == 'team_5'
assert first['approach__name'] == 'approach_0'
assert first['overall_score'] == 0.95
assert second['approach__team__name'] == 'team_6'
assert second['approach__name'] == 'approach_0'
assert second['overall_score'] == 0.78
assert third['approach__team__name'] == 'team_8'
assert third['approach__name'] == 'approach_1'
assert third['overall_score'] == 0.60
52 changes: 35 additions & 17 deletions stade/core/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from datetime import timedelta
import json
import logging

from django.conf import settings
Expand All @@ -13,8 +12,10 @@
from django.urls import reverse
from django.utils import timezone
from django.views.decorators.http import require_http_methods
import orjson
import requests
from rules.contrib.views import objectgetter, permission_required
from s3_file_field import S3FileField

from stade.core.forms import (
AcceptInvitationForm,
Expand Down Expand Up @@ -68,28 +69,45 @@ def leaderboard_page(request, challenge):
submission_ids = list(submissions_by_approach(active_task.id))

submissions = list(
Submission.objects.defer(None) # avoid n+1 queries on the normally deferred score field
.select_related('approach', 'approach__team', 'creator')
.filter(id__in=submission_ids)
.order_by('-overall_score', 'created')
)[
0:200
] # leaderboards only show the top 200 results
Submission.objects.filter(id__in=submission_ids)
.values(
'id',
'overall_score',
'score',
'created',
'approach__name',
'approach__team__name',
'approach__team__institution',
'approach__uses_external_data',
'approach__manuscript',
)
.order_by('-overall_score', 'created')[:200]
)

field = S3FileField()
for submission in submissions:
if submission.score and isinstance(submission.score, dict):
submission.score_json = json.dumps(submission.score)
score = submission['score']
if score:
if isinstance(score, str):
submission['score_json'] = score
elif isinstance(score, dict):
submission['score_json'] = orjson.dumps(score).decode('utf-8')
else:
submission['score_json'] = '{}'
else:
submission.score_json = '{}'
submission['score_json'] = '{}'

if submission['approach__manuscript']:
submission['approach__manuscript_url'] = field.storage.url(
submission['approach__manuscript']
)
else:
submission['approach__manuscript_url'] = None

stats = {
'total_submissions': len(submissions),
'unique_teams': len(
set(s.approach.team.name for s in submissions if s.approach and s.approach.team)
),
'used_external_data': sum(
1 for s in submissions if s.approach and s.approach.uses_external_data
),
'unique_teams': len(set(s['approach__team__name'] for s in submissions)),
'used_external_data': sum(1 for s in submissions if s['approach__uses_external_data']),
}

return render(
Expand Down
2 changes: 1 addition & 1 deletion stade/tracker/rest/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class ConflictException(APIException):
status_code = status.HTTP_500_INTERNAL_SERVER_ERROR
default_detail = 'A server error occurred.'

def __init__(self, detail, field, code):
def __init__(self, detail, field, code): # noqa: B042
if code is not None:
self.status_code = code
if detail is not None:
Expand Down