Skip to content

Commit

Permalink
✨ Add configurable metadata display in leaderboard
Browse files Browse the repository at this point in the history
  • Loading branch information
jnywong committed Nov 26, 2024
1 parent d6cb65c commit 6a57d1d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
12 changes: 6 additions & 6 deletions frx_challenges/web/templates/results.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,21 @@ <h1>Leaderboard</h1>
<thead>
<tr>
<th scope="col">ID</th>
<th scope="col">Name</th>
<th scope="col">Description</th>
<th scope="col">Date created</th>
<th scope="col">Submission Name</th>
{% for md in metadata_display %}<th scope="col">{{ md }}</th>{% endfor %}
{% for dc in evaluation_display_config %}<th scope="col">{{ dc.display_name }}</th>{% endfor %}
</tr>
</thead>
<tbody>
{% for result in results %}
<tr>
<td>{{ result.submission.id }}</td>
<td>{{ result.submission.created_at|date:"c" }}</td>
<td>
<a href='{% url "submissions-detail" result.submission.id %}'>{{ result.submission.name }}</a>
</td>
<td>{{ result.submission.description }}</td>
<td>{{ result.submission.created_at|date:"c" }}</td>
{% for m in result.metadata %}<td>{{ m }}</td>{% endfor %}
{% for r in result.best_version.latest_evaluation.ordered_results %}
<td scope="col">
{% if r %}{{ r }}{% endif %}
Expand All @@ -62,11 +62,11 @@ <h1>Leaderboard</h1>
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();
}
Expand Down
30 changes: 28 additions & 2 deletions frx_challenges/web/views/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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,
},
)

0 comments on commit 6a57d1d

Please sign in to comment.