add submission statistics
This commit is contained in:
@@ -2,7 +2,7 @@ FROM python:3.12-alpine
|
||||
ARG TARGETARCH
|
||||
ARG TARGETVARIANT
|
||||
|
||||
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories
|
||||
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories
|
||||
|
||||
ENV OJ_ENV production
|
||||
WORKDIR /app
|
||||
@@ -14,7 +14,7 @@ RUN --mount=type=cache,target=/etc/apk/cache,id=apk-cahce-$TARGETARCH$TARGETVARI
|
||||
--mount=type=cache,target=/root/.cache/pip,id=pip-cahce-$TARGETARCH$TARGETVARIANT-final \
|
||||
<<EOS
|
||||
set -ex
|
||||
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
|
||||
pip config set global.index-url https://mirrors.ustc.edu.cn/pypi/web/simple
|
||||
apk add gcc libc-dev python3-dev libpq libpq-dev libjpeg-turbo libjpeg-turbo-dev zlib zlib-dev freetype freetype-dev supervisor openssl nginx curl unzip
|
||||
pip install -r /app/deploy/requirements.txt
|
||||
apk del gcc libc-dev python3-dev libpq-dev libjpeg-turbo-dev zlib-dev freetype-dev
|
||||
|
||||
@@ -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