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
2 changes: 2 additions & 0 deletions stade/core/models/challenge.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ def stats(self):
distinct=True,
),
num_successful_approaches=models.Count('approach', distinct=True),
first_submission=models.Min('approach__submission__created'),
last_submission=models.Max('approach__submission__created'),
)
.filter(challenge=self)
.order_by('name')
Expand Down
6 changes: 6 additions & 0 deletions stade/core/static/css/stade/dashboard.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
.submission-timespan {
font-size: 13px;
font-weight: normal;
margin-left: 0.5em;
}

.main-stats {
background: #454545;
color: #fff;
Expand Down
5 changes: 5 additions & 0 deletions stade/core/templates/partials/task-submission-timespan.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% if task.first_submission %}
<span class="submission-timespan">
({{ task.first_submission|date:"M Y" }} - {% if task.locked %}{{ task.last_submission|date:"M Y" }}{% else %}Present{% endif %})
</span>
{% endif %}
2 changes: 2 additions & 0 deletions stade/core/templates/stats.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ <h4>Success/Total</h4>
<li>
<a href="#">
<span>{{ task.name }}</span>
{% include "partials/task-submission-timespan.html" %}
</a>

<div class="is-flex is-align-items-center pr-4">
Expand Down Expand Up @@ -92,6 +93,7 @@ <h4>Success/Total</h4>
<li>
<a href="{% url 'task-landing' task.challenge.slug task.id %}">
<span>{{ task.name }}</span>
{% include "partials/task-submission-timespan.html" %}
</a>

<div class="is-flex is-align-items-center pr-4">
Expand Down
35 changes: 35 additions & 0 deletions stade/core/tests/test_stats.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from datetime import timedelta

from django.urls import reverse
from django.utils import timezone
from django.utils.dateformat import format as date_format
import pytest


@pytest.mark.django_db
def test_stats_task_submission_timespan(client, task_factory, submission_factory):
locked_task = task_factory(locked=True)
open_task = task_factory(locked=False)
empty_task = task_factory()

first = submission_factory(approach__task=locked_task)
first.created = timezone.now() - timedelta(days=400)
first.save()
last = submission_factory(approach__task=locked_task)
open_submission = submission_factory(approach__task=open_task)

stats = {t.id: t for t in locked_task.challenge.stats['tasks']}
assert stats[locked_task.id].first_submission == first.created
assert stats[locked_task.id].last_submission == last.created

def month(dt):
return date_format(timezone.localtime(dt), 'M Y')

resp = client.get(reverse('stats'))
assert resp.status_code == 200
content = resp.content.decode()

assert f'({month(first.created)} - {month(last.created)})' in content
assert f'({month(open_submission.created)} - Present)' in content
assert content.count('class="submission-timespan"') == 2
assert empty_task.name in content
Loading