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

thêm tính năng hiển thị độ khó cho từng problem #25 #34

Open
wants to merge 2 commits into
base: master
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
6 changes: 3 additions & 3 deletions judge/admin/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,11 @@ def has_permission_full_markup(self, request, obj=None):
class ProblemAdmin(NoBatchDeleteMixin, VersionAdmin):
fieldsets = (
(None, {
'fields': (
'fields': (0
'code', 'name', 'suggester', 'is_public', 'is_manually_managed', 'date', 'authors',
'curators', 'testers', 'is_organization_private', 'organizations', 'submission_source_visibility_mode',
'testcase_visibility_mode', 'testcase_result_visibility_mode', 'allow_view_feedback',
'is_full_markup', 'pdf_url', 'source', 'description', 'license',
'is_full_markup', 'pdf_url', 'source', 'description', 'license', 'difficulty',
),
}),
(_('Social Media'), {'classes': ('collapse',), 'fields': ('og_image', 'summary')}),
Expand All @@ -138,7 +138,7 @@ class ProblemAdmin(NoBatchDeleteMixin, VersionAdmin):
(_('Justice'), {'fields': ('banned_users',)}),
(_('History'), {'fields': ('change_message',)}),
)
list_display = ['code', 'name', 'show_authors', 'points', 'is_public', 'show_public']
list_display = ['code', 'name', 'show_authors', 'points', 'difficulty', 'is_public', 'show_public']
ordering = ['code']
search_fields = ('code', 'name', 'authors__user__username', 'curators__user__username')
inlines = [LanguageLimitInline, ProblemClarificationInline, ProblemSolutionInline, ProblemTranslationInline]
Expand Down
12 changes: 10 additions & 2 deletions judge/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def clean_statement_file(self):
content = self.files.get('statement_file', None)
if content is not None:
if content.size > settings.PDF_STATEMENT_MAX_FILE_SIZE:
raise forms.ValidationError(_('File size is too big! Maximum file size is %s') %
raise forms.ValidationError(_('File size is too big! Maximum file size is %s') %
filesizeformat(settings.PDF_STATEMENT_MAX_FILE_SIZE),
'big_file_size')
if self.user and not self.user.has_perm('judge.upload_file_statement'):
Expand All @@ -222,10 +222,16 @@ def clean_time_limit(self):
% settings.VNOJ_PROBLEM_TIMELIMIT_LIMIT,
'problem_timelimit_too_long')
return self.cleaned_data['time_limit']

# def clean_difficulty(self):
# difficulty = self.cleaned_data.get('difficulty')
# if difficulty and difficulty not in ['easy', 'medium', 'hard']:
# raise forms.ValidationError(_('Invalid difficulty level. Please choose from Easy, Medium, or Hard.'))
# return difficulty

class Meta:
model = Problem
fields = ['is_public', 'code', 'name', 'time_limit', 'memory_limit', 'points', 'partial',
fields = ['is_public', 'code', 'name', 'time_limit', 'memory_limit', 'points', 'difficulty', 'partial',
'statement_file', 'source', 'types', 'group', 'submission_source_visibility_mode',
'testcase_visibility_mode', 'description', 'testers']
widgets = {
Expand All @@ -250,6 +256,7 @@ class Meta:
'points': _('Points awarded for problem completion. From 0 to 2. '
'You can approximate: 0.5 is as hard as Problem 1 of VOI; 1 = Problem 2 of VOI; '
'1.5 = Problem 3 of VOI.'),
'difficulty': _('Difficulty level of the problem: Easy, Medium, or Hard.')
}
error_messages = {
'code': {
Expand All @@ -258,6 +265,7 @@ class Meta:
}



class ProblemImportPolygonForm(Form):
code = CharField(max_length=32, validators=[RegexValidator('^[a-z0-9_]+$', _('Problem code must be ^[a-z0-9_]+$'))])
package = forms.FileField(
Expand Down
7 changes: 7 additions & 0 deletions judge/models/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,13 @@ class Problem(models.Model):
name = models.CharField(max_length=100, verbose_name=_('problem name'), db_index=True,
help_text=_('The full name of the problem, as shown in the problem list.'),
validators=[disallowed_characters_validator])
difficulty = models.CharField(
max_length=20,
choices=[('easy', 'Easy'), ('medium', 'Medium'), ('hard', 'Hard')],
default='easy',
verbose_name=_('Difficulty'),
help_text=_('Difficulty level of the problem: Easy, Medium, or Hard.')
)
pdf_url = models.CharField(max_length=200, verbose_name=_('PDF statement URL'), blank=True,
help_text=_('URL to PDF statement. The PDF file must be embeddable (Mobile web browsers'
'may not support embedding). Fallback included.'))
Expand Down
19 changes: 19 additions & 0 deletions templates/problem/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@
#problem-table th {
padding: 0;
}
.rectangle {
display: inline-block;
padding: 2px 15px;
border: 0px solid #000;
border-radius: 20px;
background-color: #87ee00;
color: #87c500;
float: right;
}
</style>
{% endblock %}

Expand Down Expand Up @@ -224,6 +233,16 @@ <h3>{{ _('Hot problems') }} <i class="fa fa-fire"></i></h3>
</td>
<td class="problem-name">
<a href="{{ url('problem_detail', problem.code) }}">{{ problem.i18n_name or problem.name }}</a>
<div class="rectangle"
{% if problem.difficulty == 'easy' %}
style="background-color: #00ff6a5d; color: #00ff00;"
{% elif problem.difficulty == 'medium' %}
style="background-color: #2700945d; color: #0011ff;"
{% elif problem.difficulty == 'hard' %}
style="background-color: #ff00005d; color: #f10000;"
{% endif %}>
{{ problem.difficulty|capfirst }}
</div>
</td>
<td class="category">{{ problem.group.full_name }}</td>
{% if show_types %}
Expand Down
5 changes: 5 additions & 0 deletions templates/problem/problem.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
{% endblock %}

{% block title_row %}

<div class="problem-title">
{% if request.user.is_authenticated %}
{% if problem.id in completed_problem_ids %}
Expand Down Expand Up @@ -213,6 +214,10 @@ <h2 style="display: inline-block">{{ title }}</h2>
{% endif %}
</span>
</div>
<div class="problem-info-entry">
<i class="fa fa-signal fa-fw"></i><span class="pi-name">{{ _('Difficulty:') }}</span>
<span class="pi-value">{{ problem.difficulty|capfirst }}</span>
</div>
<div class="problem-info-entry">
<i class="fa fa-clock-o fa-fw"></i><span class="pi-name">{{ _('Time limit:') }}</span>
<span class="pi-value">{{ problem.time_limit }}s</span>
Expand Down
15 changes: 15 additions & 0 deletions templates/stats/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{% extends "base.html" %}

{% block js_media %}
{% compress js %}
{% include "stats/media-js.html" %}
{% endcompress %}
{% endblock %}

{% block content_title %}{% endblock %}
{% block title_ruler %}{% endblock %}

{% block body %}
{% include "stats/tab.html" %}
{% block chart_body %}{% endblock %}
{% endblock %}
45 changes: 45 additions & 0 deletions templates/stats/language.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{% extends "stats/base.html" %}
{% block media %}
<style>
.chart {
margin: 10px 0;
}
</style>
{% endblock %}

{% block chart_body %}
<h3>{{ _('Submission Statistics') }}</h3>
<div id="status-counts" class="chart">
<canvas width="400" height="300"></canvas>
</div>

<h3>{{ _('Submissions by Language') }}</h3>
<div id="lang-all" class="chart">
<canvas width="400" height="300"></canvas>
</div>

<h3>{{ _('AC Submissions by Language') }}</h3>
<div id="lang-ac" class="chart">
<canvas width="400" height="300"></canvas>
</div>

<h3>{{ _('Language AC Rate') }}</h3>
<div id="ac-rate" class="chart">
<canvas><canvas>
</div>
{% endblock %}

{% block bodyend %}
<script type="text/javascript">
$(function () {
Chart.defaults.global.scaleFontFamily =
Chart.defaults.global.tooltipFontFamily =
Chart.defaults.global.tooltipTitleFontFamily =
$('body').css('font-family');
draw_pie_chart({{ data_all }}, $('#lang-all'));
draw_pie_chart({{ lang_ac }}, $('#lang-ac'));
draw_pie_chart({{ status_counts }}, $('#status-counts'));
draw_bar_chart({{ ac_rate }}, $('#ac-rate'));
});
</script>
{% endblock %}
Loading
Loading