-
Notifications
You must be signed in to change notification settings - Fork 376
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
86ac77e
commit 0ebbd6d
Showing
9 changed files
with
295 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Generated by Django 2.1.12 on 2019-10-17 20:52 | ||
|
||
import django.db.models.deletion | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('judge', '0092_contest_clone'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='ContestMoss', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('language', models.CharField(max_length=10)), | ||
('submission_count', models.PositiveIntegerField(default=0)), | ||
('url', models.URLField(blank=True, null=True)), | ||
], | ||
options={ | ||
'verbose_name': 'contest moss result', | ||
'verbose_name_plural': 'contest moss results', | ||
}, | ||
), | ||
migrations.AlterModelOptions( | ||
name='contest', | ||
options={'permissions': (('see_private_contest', 'See private contests'), ('edit_own_contest', 'Edit own contests'), ('edit_all_contest', 'Edit all contests'), ('clone_contest', 'Clone contest'), ('moss_contest', 'MOSS contest'), ('contest_rating', 'Rate contests'), ('contest_access_code', 'Contest access codes'), ('create_private_contest', 'Create private contests')), 'verbose_name': 'contest', 'verbose_name_plural': 'contests'}, | ||
), | ||
migrations.AddField( | ||
model_name='contestmoss', | ||
name='contest', | ||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='moss', to='judge.Contest', verbose_name='contest'), | ||
), | ||
migrations.AddField( | ||
model_name='contestmoss', | ||
name='problem', | ||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='moss', to='judge.Problem', verbose_name='problem'), | ||
), | ||
migrations.AlterUniqueTogether( | ||
name='contestmoss', | ||
unique_together={('contest', 'problem', 'language')}, | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
from judge.tasks.demo import * | ||
from judge.tasks.moss import * | ||
from judge.tasks.submission import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
from celery import shared_task | ||
from django.conf import settings | ||
from django.core.exceptions import ImproperlyConfigured | ||
from django.utils.translation import gettext as _ | ||
from moss import MOSS | ||
|
||
from judge.models import Contest, ContestMoss, ContestParticipation, Submission | ||
from judge.utils.celery import Progress | ||
|
||
__all__ = ('run_moss',) | ||
|
||
|
||
@shared_task(bind=True) | ||
def run_moss(self, contest_key): | ||
moss_api_key = settings.MOSS_API_KEY | ||
if moss_api_key is None: | ||
raise ImproperlyConfigured('No MOSS API Key supplied') | ||
|
||
contest = Contest.objects.get(key=contest_key) | ||
ContestMoss.objects.filter(contest=contest).delete() | ||
|
||
length = len(ContestMoss.LANG_MAPPING) * contest.problems.count() | ||
moss_results = [] | ||
|
||
with Progress(self, length, stage=_('Running MOSS')) as p: | ||
for problem in contest.problems.all(): | ||
for dmoj_lang, moss_lang in ContestMoss.LANG_MAPPING: | ||
result = ContestMoss(contest=contest, problem=problem, language=dmoj_lang) | ||
|
||
subs = Submission.objects.filter( | ||
contest__participation__virtual__in=(ContestParticipation.LIVE, ContestParticipation.SPECTATE), | ||
contest_object=contest, | ||
problem=problem, | ||
language__common_name=dmoj_lang, | ||
).order_by('-points').values_list('user__user__username', 'source__source') | ||
|
||
if subs.exists(): | ||
moss_call = MOSS(moss_api_key, language=moss_lang, matching_file_limit=100, | ||
comment='%s - %s' % (contest.key, problem.code)) | ||
|
||
users = set() | ||
|
||
for username, source in subs: | ||
if username in users: | ||
continue | ||
users.add(username) | ||
moss_call.add_file_from_memory(username, source.encode('utf-8')) | ||
|
||
result.url = moss_call.process() | ||
result.submission_count = len(users) | ||
|
||
moss_results.append(result) | ||
p.did(1) | ||
|
||
ContestMoss.objects.bulk_create(moss_results) | ||
|
||
return len(moss_results) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.