新增活跃度排名

This commit is contained in:
yuetsh
2024-08-14 00:24:46 +08:00
parent 0a6417ef91
commit 749612002a
2 changed files with 14 additions and 1 deletions

View File

@@ -4,7 +4,7 @@ from ..views.oj import (ApplyResetPasswordAPI, ResetPasswordAPI,
UserChangePasswordAPI, UserRegisterAPI, UserChangeEmailAPI, UserChangePasswordAPI, UserRegisterAPI, UserChangeEmailAPI,
UserLoginAPI, UserLogoutAPI, UsernameOrEmailCheck, UserLoginAPI, UserLogoutAPI, UsernameOrEmailCheck,
AvatarUploadAPI, TwoFactorAuthAPI, UserProfileAPI, AvatarUploadAPI, TwoFactorAuthAPI, UserProfileAPI,
UserRankAPI, CheckTFARequiredAPI, SessionManagementAPI, UserRankAPI, UserActivityRankAPI, CheckTFARequiredAPI, SessionManagementAPI,
ProfileProblemDisplayIDRefreshAPI, OpenAPIAppkeyAPI, SSOAPI) ProfileProblemDisplayIDRefreshAPI, OpenAPIAppkeyAPI, SSOAPI)
from utils.captcha.views import CaptchaAPIView from utils.captcha.views import CaptchaAPIView
@@ -25,6 +25,7 @@ urlpatterns = [
path("tfa_required", CheckTFARequiredAPI.as_view()), path("tfa_required", CheckTFARequiredAPI.as_view()),
path("two_factor_auth", TwoFactorAuthAPI.as_view(),), path("two_factor_auth", TwoFactorAuthAPI.as_view(),),
path("user_rank", UserRankAPI.as_view()), path("user_rank", UserRankAPI.as_view()),
path("user_activity_rank", UserActivityRankAPI.as_view()),
path("sessions", SessionManagementAPI.as_view()), path("sessions", SessionManagementAPI.as_view()),
path("open_api_appkey", OpenAPIAppkeyAPI.as_view(),), path("open_api_appkey", OpenAPIAppkeyAPI.as_view(),),
path("sso", SSOAPI.as_view()) path("sso", SSOAPI.as_view())

View File

@@ -9,9 +9,11 @@ from django.template.loader import render_to_string
from django.utils.decorators import method_decorator from django.utils.decorators import method_decorator
from django.utils.timezone import now from django.utils.timezone import now
from django.views.decorators.csrf import ensure_csrf_cookie, csrf_exempt from django.views.decorators.csrf import ensure_csrf_cookie, csrf_exempt
from django.db.models import Count
from otpauth import OtpAuth from otpauth import OtpAuth
from problem.models import Problem from problem.models import Problem
from submission.models import Submission
from utils.constants import ContestRuleType from utils.constants import ContestRuleType
from options.options import SysOptions from options.options import SysOptions
from utils.api import APIView, validate_serializer, CSRFExemptAPIView from utils.api import APIView, validate_serializer, CSRFExemptAPIView
@@ -394,6 +396,16 @@ class UserRankAPI(APIView):
return self.success(self.paginate_data(request, profiles, RankInfoSerializer)) return self.success(self.paginate_data(request, profiles, RankInfoSerializer))
class UserActivityRankAPI(APIView):
def get(self, request):
start = request.GET.get("start")
if not start:
return self.error("start time is required")
submissions = Submission.objects.filter(contest_id__isnull=True, create_time__gte=start)
counts = submissions.values("username").annotate(count=Count("id")).order_by("-count")
return self.success(list(counts)[:10])
class ProfileProblemDisplayIDRefreshAPI(APIView): class ProfileProblemDisplayIDRefreshAPI(APIView):
@login_required @login_required
def get(self, request): def get(self, request):