Skip to content
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

Autorefresh and time ranged scoreboards #33

Open
wants to merge 5 commits into
base: update-everything
Choose a base branch
from
Open
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: 1 addition & 1 deletion testovac/menu/templatetags/menu_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def static_menu_items(request):
{
"url_regex": r"^/results",
"text": _("Results"),
"link": "%s?group=ls_2022_zaciatocnici" % reverse("results_index"),
"link": "%s" % reverse("results_index"),
},
{
"url_regex": r"^/achievements",
Expand Down
15 changes: 15 additions & 0 deletions testovac/results/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,26 @@ def get_user_task_points(self):
for receiver in task.submit_receivers.all():
tasks_for_receiver[receiver.pk].append(task)

pk_to_task = {task.pk: task for task in self.task_list}

def is_inside_time_range(time, task):
start_time = getattr(task, "start_time", None)
end_time = getattr(task, "end_time", None)
if start_time is not None and time < start_time:
return False
if end_time is not None and time > end_time:
return False
return True

user_task_receiver_reviews = defaultdict(
lambda: defaultdict(lambda: defaultdict(list))
)
for review in reviews:
for task in tasks_for_receiver[review.submit.receiver.pk]:
# we do this, because we received modified task object in class constructor
timed_task = pk_to_task[task.pk]
if not is_inside_time_range(review.submit.time, timed_task):
continue
user_task_receiver_reviews[review.submit.user.pk][task.pk][
review.submit.receiver.pk
].append(review)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 5.0.7 on 2024-07-18 14:30

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('results', '0005_auto_20180705_1333'),
]

operations = [
migrations.AddField(
model_name='customresultstable',
name='end_time',
field=models.DateTimeField(blank=True, null=True),
),
migrations.AddField(
model_name='customresultstable',
name='honor_contest_timeranges',
field=models.BooleanField(default=False, help_text='When we want to make a results table for a collection of time restricted contests'),
),
migrations.AddField(
model_name='customresultstable',
name='start_time',
field=models.DateTimeField(blank=True, null=True),
),
]
20 changes: 16 additions & 4 deletions testovac/results/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from itertools import chain

from django.db import models
from django.utils.translation import gettext_lazy as _
from sortedm2m.fields import SortedManyToManyField
Expand All @@ -16,6 +14,9 @@ class CustomResultsTable(models.Model):
name = models.CharField(max_length=128)
number = models.IntegerField()
contests = SortedManyToManyField(Contest)
honor_contest_timeranges = models.BooleanField(default=False)
start_time = models.DateTimeField(blank=True, null=True)
end_time = models.DateTimeField(blank=True, null=True)

class Meta:
verbose_name = _("custom results table")
Expand All @@ -28,5 +29,16 @@ def task_list(self, user):
tasks = []
for contest in self.contests.all():
if contest.tasks_visible_for_user(user):
tasks.append(contest.task_set.all())
return list(chain(*tasks))
for task in contest.task_set.all():
task.start_time = min(
self.start_time,
contest.start_time if self.honor_contest_timeranges else None,
key=lambda x: (x is None, x),
)
task.end_time = max(
self.end_time,
contest.end_time if self.honor_contest_timeranges else None,
key=lambda x: (x is not None, x),
)
tasks.append(task)
return tasks
7 changes: 6 additions & 1 deletion testovac/results/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,17 @@ def contest_results(request, contest_slug, group=None):
if not contest.tasks_visible_for_user(request.user):
raise Http404

tasks = list(contest.task_set.all())
for task in tasks:
task.start_time = contest.start_time
task.end_time = contest.end_time

return render(
request,
"results/contest_results_table.html",
{
"contest": contest,
"task_list": [task for task in contest.task_set.all()],
"task_list": tasks,
"group": group,
},
)
4 changes: 4 additions & 0 deletions testovac/submit/templates/submit/protocol.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{% load i18n %}
{% load submit_parts %}

{% if protocol and not protocol.ready %}
<meta http-equiv="refresh" content="5">
{% endif %}

{% if not protocol or not protocol.ready %}
<div class="alert alert-info">
<span class="glyphicon glyphicon-refresh glyphicon-animate-rotate"></span>
Expand Down