From 6a57d1dad74052fc064273a16ecad1f88159fc2d Mon Sep 17 00:00:00 2001 From: jnywong Date: Tue, 26 Nov 2024 12:23:49 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20configurable=20metadata=20dis?= =?UTF-8?q?play=20in=20leaderboard?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frx_challenges/web/templates/results.html | 12 ++++----- frx_challenges/web/views/default.py | 30 +++++++++++++++++++++-- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/frx_challenges/web/templates/results.html b/frx_challenges/web/templates/results.html index cb515d2..ed43651 100644 --- a/frx_challenges/web/templates/results.html +++ b/frx_challenges/web/templates/results.html @@ -29,9 +29,9 @@

Leaderboard

ID - Name - Description Date created + Submission Name + {% for md in metadata_display %}{{ md }}{% endfor %} {% for dc in evaluation_display_config %}{{ dc.display_name }}{% endfor %} @@ -39,11 +39,11 @@

Leaderboard

{% for result in results %} {{ result.submission.id }} + {{ result.submission.created_at|date:"c" }} {{ result.submission.name }} - {{ result.submission.description }} - {{ result.submission.created_at|date:"c" }} + {% for m in result.metadata %}{{ m }}{% endfor %} {% for r in result.best_version.latest_evaluation.ordered_results %} {% if r %}{{ r }}{% endif %} @@ -62,11 +62,11 @@

Leaderboard

const resultsTable = new DataTable("#results", { order: [ // Apply reverse chronological ordering by default - [3, "desc"] + [1, "desc"] ], columnDefs: [ { - targets: 3, + targets: 1, render: (data) => { return dayjs(data).fromNow(); } diff --git a/frx_challenges/web/views/default.py b/frx_challenges/web/views/default.py index bc192d9..ae0db5d 100644 --- a/frx_challenges/web/views/default.py +++ b/frx_challenges/web/views/default.py @@ -22,11 +22,25 @@ def leaderboard(request: HttpRequest) -> HttpResponse: results = [] all_submissions = Submission.objects.all() for sub in all_submissions: + # Get best scoring version bv = sub.best_version if not bv: # Only display submissions with at least one 'best version' continue - results.append({"submission": sub, "best_version": bv}) + # Get submission metadata + metadata = [] + for k, v in settings.SITE_SUBMISSION_FORM_SCHEMA["properties"].items(): + if v.get("leaderboard_display"): + metadata.append( + sub.metadata.get(k), + ) + results.append( + { + "submission": sub, + "best_version": bv, + "metadata": metadata, + } + ) def sort_key_func(r): bv: Version = r["best_version"] @@ -44,6 +58,18 @@ def sort_key_func(r): return sort_key results = sorted(results, key=sort_key_func) + + metadata_display = [] + for k, v in settings.SITE_SUBMISSION_FORM_SCHEMA["properties"].items(): + if v.get("leaderboard_display"): + metadata_display.append(v.get("title")) + return render( - request, "results.html", {"results": results, "description": description} + request, + "results.html", + { + "results": results, + "description": description, + "metadata_display": metadata_display, + }, )