add submission statistics
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
from django.conf.urls import url
|
||||
|
||||
from ..views.admin import SubmissionRejudgeAPI
|
||||
from ..views.admin import SubmissionRejudgeAPI, SubmissionStatisticsAPI
|
||||
|
||||
urlpatterns = [
|
||||
url(r"^submission/rejudge?$", SubmissionRejudgeAPI.as_view(), name="submission_rejudge_api"),
|
||||
url(r"^submission/statistics?$", SubmissionStatisticsAPI.as_view(), name="submission_statistics_api"),
|
||||
]
|
||||
|
||||
@@ -2,7 +2,8 @@ from account.decorators import super_admin_required
|
||||
from judge.tasks import judge_task
|
||||
# from judge.dispatcher import JudgeDispatcher
|
||||
from utils.api import APIView
|
||||
from ..models import Submission
|
||||
from ..models import Submission, JudgeStatus
|
||||
from problem.models import Problem
|
||||
|
||||
|
||||
class SubmissionRejudgeAPI(APIView):
|
||||
@@ -20,3 +21,45 @@ class SubmissionRejudgeAPI(APIView):
|
||||
|
||||
judge_task.send(submission.id, submission.problem.id)
|
||||
return self.success()
|
||||
|
||||
class SubmissionStatisticsAPI(APIView):
|
||||
@super_admin_required
|
||||
def get(self, request):
|
||||
start = request.GET.get("start")
|
||||
end = request.GET.get("end")
|
||||
|
||||
if not start or not end:
|
||||
return self.error("start and end is required")
|
||||
|
||||
submissions = Submission.objects.filter(contest_id__isnull=True,
|
||||
create_time__gte=start,
|
||||
create_time__lte=end).select_related("problem__created_by")
|
||||
|
||||
problem_id = request.GET.get("problem_id")
|
||||
|
||||
if problem_id:
|
||||
try:
|
||||
problem = Problem.objects.get(_id=problem_id, contest_id__isnull=True, visible=True)
|
||||
except Problem.DoesNotExist:
|
||||
return self.error("Problem doesn't exist")
|
||||
submissions = submissions.filter(problem=problem)
|
||||
|
||||
username = request.GET.get("username")
|
||||
|
||||
if username:
|
||||
submissions = submissions.filter(username__icontains=username)
|
||||
|
||||
total_count = submissions.count()
|
||||
accepted_count = submissions.filter(result=JudgeStatus.ACCEPTED).count()
|
||||
|
||||
try:
|
||||
correct_rate = round(accepted_count/total_count*100, 2)
|
||||
except ZeroDivisionError:
|
||||
correct_rate = 0
|
||||
|
||||
return self.success({
|
||||
"submission_count": total_count,
|
||||
"accepted_count": accepted_count,
|
||||
"correct_rate": f"{correct_rate}%",
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user