mirror of
https://gitlab.com/megazordpobeda/DataRush.git
synced 2026-05-23 02:47:10 +00:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -19,6 +19,7 @@ from apps.task.models import (
|
||||
CompetitionTaskAttachment,
|
||||
CompetitionTaskSubmission,
|
||||
)
|
||||
from apps.task.tasks import analyze_data_task
|
||||
|
||||
router = Router(tags=["competition"])
|
||||
|
||||
@@ -124,6 +125,7 @@ def submit_task(
|
||||
status=CompetitionTaskSubmission.StatusChoices.CHECKING,
|
||||
content=content,
|
||||
)
|
||||
analyze_data_task.delay(submission_id=submission.id)
|
||||
|
||||
return TaskSubmissionOut(submission_id=submission.id)
|
||||
|
||||
@@ -155,6 +157,4 @@ def get_submissions_history(request, competition_id: UUID, task_id: UUID):
|
||||
)
|
||||
def get_task_attachments(request, competition_id: UUID, task_id: UUID):
|
||||
task = get_object_or_404(CompetitionTask, id=task_id)
|
||||
return status.OK, CompetitionTaskAttachment.objects.filter(
|
||||
task=task
|
||||
).all()
|
||||
return status.OK, CompetitionTaskAttachment.objects.filter(task=task).all()
|
||||
|
||||
@@ -23,3 +23,8 @@ class UserSchema(ModelSchema):
|
||||
class Meta:
|
||||
model = User
|
||||
fields = ["id", "email", "username", "created_at", "achievements"]
|
||||
|
||||
|
||||
class StatSchema(Schema):
|
||||
total_attempts: int
|
||||
solved_tasks: int
|
||||
|
||||
@@ -11,15 +11,17 @@ from api.v1.schemas import (
|
||||
BadRequestError,
|
||||
ConflictError,
|
||||
ForbiddenError,
|
||||
NotFoundError,
|
||||
NotFoundError, UnauthorizedError,
|
||||
)
|
||||
from api.v1.user.schemas import (
|
||||
LoginSchema,
|
||||
RegisterSchema,
|
||||
TokenSchema,
|
||||
UserSchema,
|
||||
StatSchema
|
||||
)
|
||||
from apps.user.models import User
|
||||
from apps.task.models import CompetitionTaskSubmission, ReviewStatusChoices
|
||||
|
||||
router = Router(tags=["user"])
|
||||
|
||||
@@ -85,3 +87,31 @@ def get_me(request):
|
||||
def get_user(request, user_id: str):
|
||||
user = get_object_or_404(User, id=user_id)
|
||||
return status.OK, user
|
||||
|
||||
|
||||
@router.get(
|
||||
"/me/stat",
|
||||
response={
|
||||
status.OK: StatSchema,
|
||||
status.UNAUTHORIZED: UnauthorizedError
|
||||
},
|
||||
)
|
||||
def get_my_stat(request):
|
||||
user_submissions = CompetitionTaskSubmission.objects.filter(
|
||||
user=request.auth
|
||||
)
|
||||
checked_attempts = user_submissions.filter(status=CompetitionTaskSubmission.StatusChoices.CHECKED).all()
|
||||
success_attempts_cnt = 0
|
||||
|
||||
for attempt in checked_attempts:
|
||||
is_correct = attempt.result.get("correct", None)
|
||||
if is_correct is None:
|
||||
is_correct = attempt.result.get("total_points", 0) > 0
|
||||
|
||||
if is_correct:
|
||||
success_attempts_cnt += 1
|
||||
|
||||
return StatSchema(
|
||||
total_attempts=len(user_submissions),
|
||||
solved_tasks=success_attempts_cnt
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user