Reformat using black

This commit is contained in:
cuom1999 2022-05-14 12:57:27 -05:00
parent efee4ad081
commit a87fb49918
221 changed files with 19127 additions and 7310 deletions

View file

@ -7,7 +7,7 @@ from moss import MOSS
from judge.models import Contest, ContestMoss, ContestParticipation, Submission
from judge.utils.celery import Progress
__all__ = ('rescore_contest', 'run_moss')
__all__ = ("rescore_contest", "run_moss")
@shared_task(bind=True)
@ -16,7 +16,9 @@ def rescore_contest(self, contest_key):
participations = contest.users
rescored = 0
with Progress(self, participations.count(), stage=_('Recalculating contest scores')) as p:
with Progress(
self, participations.count(), stage=_("Recalculating contest scores")
) as p:
for participation in participations.iterator():
participation.recompute_results()
rescored += 1
@ -29,7 +31,7 @@ def rescore_contest(self, contest_key):
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')
raise ImproperlyConfigured("No MOSS API Key supplied")
contest = Contest.objects.get(key=contest_key)
ContestMoss.objects.filter(contest=contest).delete()
@ -37,21 +39,34 @@ def run_moss(self, contest_key):
length = len(ContestMoss.LANG_MAPPING) * contest.problems.count()
moss_results = []
with Progress(self, length, stage=_('Running MOSS')) as p:
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)
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')
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))
moss_call = MOSS(
moss_api_key,
language=moss_lang,
matching_file_limit=100,
comment="%s - %s" % (contest.key, problem.code),
)
users = set()
@ -59,7 +74,7 @@ def run_moss(self, contest_key):
if username in users:
continue
users.add(username)
moss_call.add_file_from_memory(username, source.encode('utf-8'))
moss_call.add_file_from_memory(username, source.encode("utf-8"))
result.url = moss_call.process()
result.submission_count = len(users)