mirror of
https://github.com/QingdaoU/OnlineJudge.git
synced 2025-01-07 13:02:02 +00:00
增加初始化用户排名的命令脚本
This commit is contained in:
parent
203ed3b35e
commit
a5a313d2fe
19
utils/management/commands/inituserrank.py
Normal file
19
utils/management/commands/inituserrank.py
Normal file
@ -0,0 +1,19 @@
|
||||
# coding=utf-8
|
||||
from django.core.management.base import BaseCommand
|
||||
from account.models import UserProfile
|
||||
from submission.models import Submission
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
def handle(self, *args, **options):
|
||||
self.stdout.write(self.style.SUCCESS("Please wait a minute"))
|
||||
for profile in UserProfile.objects.all():
|
||||
submissions = Submission.objects.filter(user_id=profile.user.id)
|
||||
profile.submission_number = submissions.count()
|
||||
accepted_problem_number = len(set(Submission.objects.filter(user_id=profile.user.id, contest_id__isnull=True)\
|
||||
.values_list("problem_id", flat=True)))
|
||||
accepted_contest_problem_number = len(set(Submission.objects.filter(user_id=profile.user.id, contest_id__isnull=False)\
|
||||
.values_list("problem_id", flat=True)))
|
||||
profile.accepted_problem_number = accepted_problem_number + accepted_contest_problem_number
|
||||
profile.save()
|
||||
self.stdout.write(self.style.SUCCESS("Succeeded"))
|
Loading…
Reference in New Issue
Block a user