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

Create contest monitoring page #359

Open
wants to merge 41 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
2942a79
Fix adding new tags from problem admin (#304)
Jan 10, 2024
91928e1
Merge branch 'master' of https://github.com/zggf-zggf/oioioi
Feb 28, 2024
6a07b6a
Merge branch 'master' of https://github.com/zggf-zggf/oioioi
Mar 9, 2024
f82adf0
Create monitoring site for contests
Mar 9, 2024
9e9b399
Add monitoring template
Mar 9, 2024
5d23a7e
Implement round times monitoring
Mar 9, 2024
c7bd8de
Add contest permissions info to monitoring page
Mar 10, 2024
effe9b1
Added General info tab.
SZonkil Mar 14, 2024
bf686f6
Add relative start/end times to monitoring
Mar 20, 2024
ffcfaec
Merge branch 'contest-monitoring' of https://github.com/zggf-zggf/oio…
Mar 20, 2024
215fbb3
Cleanup
Mar 20, 2024
b08adc3
Change monitoring template
Mar 20, 2024
76a41f4
Added count of unanswered questions and date of oldest unanswered que…
SZonkil Apr 3, 2024
3b7cbac
Add attachments info to monitoring page
Apr 3, 2024
5117a42
Merge branch 'contest-monitoring' of https://github.com/zggf-zggf/oio…
Apr 3, 2024
6077a74
Quickfix
Apr 3, 2024
979449f
Add submissions info to monitoring page
Apr 7, 2024
d501172
Added count of submissions with system errors
SZonkil Apr 17, 2024
71e422f
Add info about test limits to contest monitoring
Apr 17, 2024
33a5b9f
Merge branch 'contest-monitoring' of https://github.com/zggf-zggf/oio…
Apr 17, 2024
2ebbf0a
Extend problems info in monitoring page
Apr 24, 2024
a04c578
Refactor contest monitoring view
May 7, 2024
6977291
Added round extensions
SZonkil May 8, 2024
1b665d7
Added bool, that shows if someone solved a problem
SZonkil May 15, 2024
2ef9ff9
Bugfix: Changed round to round-name
SZonkil May 19, 2024
beca5c8
Bugfix: Added contest filter to SE detection
SZonkil May 22, 2024
1354ab6
Create tests_monitoring file
May 22, 2024
0741edd
Add tests round times
May 22, 2024
6f9562a
Bugfix: changed pub-date to date
SZonkil May 29, 2024
227503a
Added tests for general info
SZonkil May 29, 2024
b909df4
WIP
May 29, 2024
b1593c0
Changed fixture and fixed system error counter
SZonkil May 29, 2024
448fa8a
WIP
May 29, 2024
c540047
Merge branch 'contest-monitoring' of https://github.com/zggf-zggf/oio…
May 29, 2024
3e2f07e
WIP
May 29, 2024
36faf0e
Add attachments tests
Jun 5, 2024
29970c2
Changed fixture
SZonkil Jun 5, 2024
324c65e
Moved monitoring tests from tests_monitoring.py to tests.py
SZonkil Jun 5, 2024
3875af1
Added fixture to monitoring tests
SZonkil Jun 5, 2024
36b4f1a
Changed colspan
SZonkil Jun 5, 2024
c259d1c
Use humanize module
Jul 4, 2024
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
24 changes: 24 additions & 0 deletions oioioi/statistics/templates/statistics/_attachments_info.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{% load i18n pagination_tags %}
<div class="table-responsive-md">
<h4> {% trans "Attachments" %} </h4>
<table class="table table-sm table-bordered">
<thead>
<tr>
<th> {% trans "Description" %} </th>
<th> {% trans "Round" %} </th>
<th> {% trans "Publication date" %} </th>
<th> {% trans "Time left to publication" %} </th>
</tr>
</thead>
<tbody>
{% for attachment in attachments %}
<tr>
<td>{{ attachment.description }}</td>
<td>{{ attachment.round }}</td>
<td>{{ attachment.pub_date }}</td>
<td>{{ attachment.pub_date_relative }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
32 changes: 32 additions & 0 deletions oioioi/statistics/templates/statistics/_general_info.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{% load i18n pagination_tags %}
{% if rounds_times %}
<div class="table-responsive-md">
<h4> {% trans "General info" %} </h4>
<table class="table table-sm table-bordered">
<thead>
<tr>
<th> {% trans "Name" %} </th>
<th> {% trans "Value" %} </th>
</tr>
</thead>
<tbody>
<tr>
<td>Queued jobs in this contest</td>
<td>{{ q_size }}</td>
</tr>
<tr>
<td>Queued jobs on this server</td>
<td>{{ q_size_global }}</td>
</tr>
<tr>
<td>Unanswered questions</td>
<td>{{ unanswered_questions }}</td>
</tr>
<tr>
<td>Oldest unanswered question</td>
<td>{{ oldest_unanswered_question }}</td>
</tr>
</tbody>
</table>
</div>
{% endif %}
20 changes: 20 additions & 0 deletions oioioi/statistics/templates/statistics/_permissions_info.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{% load i18n pagination_tags %}
<div class="table-responsive-md">
<h4> {% trans "Permissions" %} </h4>
<table class="table table-sm table-bordered">
<thead>
<tr>
<th> {% trans "Permission" %} </th>
<th> {% trans "Count" %} </th>
</tr>
</thead>
<tbody>
{% for permission, count in permissions_count.items %}
<tr>
<td>{{ permission }}</td>
<td>{{ count }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
28 changes: 28 additions & 0 deletions oioioi/statistics/templates/statistics/_rounds_info.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{% load i18n pagination_tags %}
{% if rounds_times %}
<div class="table-responsive-md">
<h4> {% trans "Rounds" %} </h4>
<table class="table table-sm table-bordered">
<thead>
<tr>
<th> {% trans "Round" %} </th>
<th> {% trans "Start time" %} </th>
<th> {% trans "Time left to start" %} </th>
<th> {% trans "End time" %} </th>
<th> {% trans "Time left to end" %} </th>
</tr>
</thead>
<tbody>
{% for round_info in rounds_times%}
<tr>
<td>{{ round_info.name }}</td>
<td>{{ round_info.start }}</td>
<td>{{ round_info.start_relative }}</td>
<td>{{ round_info.end }}</td>
<td>{{ round_info.end_relative }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endif %}
22 changes: 22 additions & 0 deletions oioioi/statistics/templates/statistics/_submissions_info.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{% load i18n pagination_tags %}
{% if rounds_times %}
<div class="table-responsive-md">
<h4> {% trans "Submission types" %} </h4>
<table class="table table-sm table-bordered">
<thead>
<tr>
<th> {% trans "Kind" %} </th>
<th> {% trans "Count" %} </th>
</tr>
</thead>
<tbody>
{% for submission_info in submissions_info %}
<tr>
<td>{{ submission_info.kind }}</td>
<td>{{ submission_info.total }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endif %}
28 changes: 28 additions & 0 deletions oioioi/statistics/templates/statistics/monitoring.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{% extends "base-with-menu.html" %}
{% load i18n pagination_tags %}

{% block title %}{% trans "Monitoring" %}{% endblock %}

{% block main-content %}
{{ head|safe }}

<div class="row">
<div class="col col-sm">
{% include "statistics/_general_info.html" %}
</div>
<div class="col col-sm">
{% include "statistics/_submissions_info.html" %}
</div>
<div class="col col-sm">
{% include "statistics/_attachments_info.html" %}
</div>
</div>
<div class="row">
<div class="col col-sm">
{% include "statistics/_permissions_info.html" %}
</div>
<div class="col col-8">
{% include "statistics/_rounds_info.html" %}
</div>
</div>
{% endblock %}
1 change: 1 addition & 0 deletions oioioi/statistics/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@
name='statistics_view_without_object',
),
re_path(r'^stat/$', views.statistics_view, name='statistics_main'),
re_path(r'^monitoring/$', views.monitoring_view, name='monitoring'),
]
86 changes: 84 additions & 2 deletions oioioi/statistics/views.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
from datetime import datetime
from pprint import pprint

from django.core.exceptions import PermissionDenied
from django.db.models import Count
from django.http import Http404
from django.template.response import TemplateResponse
from django.urls import reverse
from django.utils.translation import gettext_lazy as _
from pytz import UTC

from oioioi.base.menu import menu_registry
from oioioi.base.permissions import enforce_condition
from oioioi.contests.menu import contest_admin_menu_registry
from oioioi.contests.models import ProblemInstance
from oioioi.contests.models import ProblemInstance, ContestPermission, contest_permissions, ContestAttachment, \
Submission
from oioioi.contests.utils import (
can_enter_contest,
contest_exists,
is_contest_admin,
is_contest_observer,
is_contest_observer, rounds_times,
)
from oioioi.participants.models import Participant
from oioioi.questions.models import Message
from oioioi.statistics.controllers import statistics_categories
from oioioi.evalmgr.models import QueuedJob
from oioioi.statistics.utils import any_statistics_avaiable, can_see_stats, render_head


Expand Down Expand Up @@ -116,3 +125,76 @@ def statistics_view(
'links': links(request),
},
)


@contest_admin_menu_registry.register_decorator(
_("Monitoring"),
lambda request: reverse(
'monitoring', kwargs={'contest_id': request.contest.id}
),
condition=(is_contest_admin | is_contest_observer),
order=110,
)
@enforce_condition(
contest_exists & can_enter_contest & can_see_stats
)
def monitoring_view(request):
cur_time = UTC.localize(datetime.now())
twalen marked this conversation as resolved.
Show resolved Hide resolved
r_times = []
for round_, rt in rounds_times(request, request.contest).items():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks fishy, especially [:-7]
you could try using huminize module and naturaldelta/precisedelta
https://python-humanize.readthedocs.io/en/latest/time/#humanize.time.precisedelta

maybe this logic can be moved to template + extra tag that present timedelta between end & cur_time
(something similar to https://github.com/sio2project/oioioi/blob/master/oioioi/base/templatetags/format_data_range.py)

round_time_info = {'name': str(round_)}
round_time_info['start'] = rt.start or _("Not set")
if rt.start:
round_time_info['start_relative'] = str(rt.start - cur_time)[:-7] if rt.is_future(cur_time) else _("Started")
else:
round_time_info['start_relative'] = _("Not set")
round_time_info['end'] = rt.end or _("Not set")
if rt.end:
round_time_info['end_relative'] = str(rt.end - cur_time)[:-7] if not rt.is_past(cur_time) else _("Finished")
else:
round_time_info['end_relative'] = _("Not set")
r_times.append(round_time_info)

permissions_count = {
permission_name: (ContestPermission
.objects
.filter(contest_id=request.contest.id, permission=permission_cls)
.count())
for permission_cls, permission_name in contest_permissions
}
permissions_count['Participant'] = Participant.objects.filter(contest_id=request.contest.id).count()
q_size = (QueuedJob.objects
.filter(submission__problem_instance__contest=request.contest)
.count())
q_size_global = (QueuedJob.objects
.count())

attachments = ContestAttachment.objects.filter(contest_id=request.contest.id).order_by('id')
for attachment in attachments:
pub_date_relative = None
if attachment.pub_date:
pub_date_relative = str(attachment.pub_date - cur_time)[:-7] if attachment.pub_date > cur_time else _("Published")
setattr(attachment, 'pub_date_relative', pub_date_relative)
unanswered_questions = (Message.objects.filter(kind='QUESTION', message=None, contest=request.contest).count())
oldest_unanswered_question = (Message.objects.filter(kind='QUESTION', message=None, contest=request.contest)
.order_by('pub_date').first())
oldest_unanswered_question_date = oldest_unanswered_question.date if oldest_unanswered_question else None

submissions_info = Submission.objects.filter(problem_instance__contest=request.contest).values('kind').annotate(total=Count('kind')).order_by()

return TemplateResponse(
request,
'statistics/monitoring.html',
{
'title': _("Monitoring"),
'rounds_times': r_times,
'permissions_count': permissions_count,
'links': links(request),
'q_size': q_size,
'q_size_global': q_size_global,
'attachments': attachments,
'unanswered_questions': unanswered_questions,
'oldest_unanswered_question': oldest_unanswered_question_date,
'submissions_info': submissions_info
},
)
Loading