mirror of
https://gitlab.com/megazordpobeda/DataRush.git
synced 2026-05-22 22:07:10 +00:00
refactor
This commit is contained in:
@@ -33,7 +33,7 @@ class TaskOutSchema(ModelSchema):
|
||||
"description",
|
||||
"in_competition_position",
|
||||
"points",
|
||||
"max_attempts"
|
||||
"max_attempts",
|
||||
]
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from http import HTTPStatus as status
|
||||
from uuid import UUID
|
||||
|
||||
from django.shortcuts import get_object_or_404, get_list_or_404
|
||||
from django.shortcuts import get_list_or_404, get_object_or_404
|
||||
from ninja import File, Router, UploadedFile
|
||||
|
||||
from api.v1.ping.schemas import PingOut
|
||||
@@ -10,8 +10,8 @@ from api.v1.task.schemas import (
|
||||
HistorySubmissionOut,
|
||||
TaskAttachmentSchema,
|
||||
TaskOutSchema,
|
||||
TaskSubmissionOut,
|
||||
TaskStatusSchema,
|
||||
TaskSubmissionOut,
|
||||
)
|
||||
from apps.achievement.models import Achievement, UserAchievement
|
||||
from apps.competition.models import State
|
||||
@@ -125,10 +125,8 @@ def submit_task(
|
||||
task=task,
|
||||
status=CompetitionTaskSubmission.StatusChoices.CHECKED,
|
||||
content=content,
|
||||
result={
|
||||
"correct": verdict
|
||||
},
|
||||
earned_points=task.points if verdict else 0
|
||||
result={"correct": verdict},
|
||||
earned_points=task.points if verdict else 0,
|
||||
)
|
||||
if task.type == CompetitionTask.CompetitionTaskType.REVIEW:
|
||||
submission = CompetitionTaskSubmission.objects.create(
|
||||
@@ -184,7 +182,7 @@ def get_task_attachments(request, competition_id: UUID, task_id: UUID):
|
||||
"competitions/{competition_id}/results",
|
||||
response={
|
||||
status.OK: list[TaskStatusSchema],
|
||||
status.UNAUTHORIZED: UnauthorizedError
|
||||
status.UNAUTHORIZED: UnauthorizedError,
|
||||
},
|
||||
)
|
||||
def get_competition_results(request, competition_id: UUID):
|
||||
@@ -193,9 +191,14 @@ def get_competition_results(request, competition_id: UUID):
|
||||
data = []
|
||||
|
||||
for task in tasks:
|
||||
submissions = CompetitionTaskSubmission.objects.filter(
|
||||
submissions = (
|
||||
CompetitionTaskSubmission.objects.filter(
|
||||
user=request.auth, task=task
|
||||
).filter(status="checked").order_by("-earned_points").all()
|
||||
)
|
||||
.filter(status="checked")
|
||||
.order_by("-earned_points")
|
||||
.all()
|
||||
)
|
||||
if not submissions:
|
||||
all_submissions_count = CompetitionTaskSubmission.objects.filter(
|
||||
user=request.auth, task=task
|
||||
@@ -206,11 +209,13 @@ def get_competition_results(request, competition_id: UUID):
|
||||
result = -1
|
||||
else:
|
||||
result = submissions[0].earned_points
|
||||
data.append(TaskStatusSchema(
|
||||
data.append(
|
||||
TaskStatusSchema(
|
||||
task_name=task.title,
|
||||
result=result,
|
||||
max_points=task.points,
|
||||
position=task.in_competition_position
|
||||
))
|
||||
position=task.in_competition_position,
|
||||
)
|
||||
)
|
||||
|
||||
return status.OK, data
|
||||
|
||||
@@ -3,7 +3,6 @@ from uuid import UUID
|
||||
from django.shortcuts import get_object_or_404
|
||||
from ninja import Router
|
||||
|
||||
from api.v1.schemas import BadRequestError, NotFoundError, UnauthorizedError
|
||||
from api.v1.team.schemas import CreateTeamSchema, TeamSchemaOut
|
||||
from apps.team.models import Team
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ from api.v1.user.schemas import (
|
||||
TokenSchema,
|
||||
UserSchema,
|
||||
)
|
||||
from apps.task.models import CompetitionTaskSubmission, CompetitionTask
|
||||
from apps.task.models import CompetitionTask, CompetitionTaskSubmission
|
||||
from apps.user.models import User
|
||||
|
||||
router = Router(tags=["user"])
|
||||
|
||||
@@ -7,4 +7,4 @@ class CompetitionsConfig(AppConfig):
|
||||
verbose_name = "Соревнование"
|
||||
|
||||
def ready(self):
|
||||
import apps.competition.signals
|
||||
pass
|
||||
|
||||
@@ -3,15 +3,23 @@ from django.dispatch import receiver
|
||||
|
||||
from apps.achievement.models import Achievement, UserAchievement
|
||||
from apps.competition.models import State
|
||||
from apps.user.models import User
|
||||
|
||||
|
||||
@receiver(post_save, sender=State)
|
||||
def assign_start_competition_achievement(sender, instance, created, **kwargs):
|
||||
if created:
|
||||
if State.objects.filter(user=instance.user, state=State.StateChoices.STARTED.value).count() == 1 \
|
||||
and not State.objects.filter(user=instance.user, state=State.StateChoices.FINISHED.value).exists():
|
||||
start_competition_achievement = Achievement.objects.get(slug="start_competition")
|
||||
if (
|
||||
State.objects.filter(
|
||||
user=instance.user, state=State.StateChoices.STARTED.value
|
||||
).count()
|
||||
== 1
|
||||
and not State.objects.filter(
|
||||
user=instance.user, state=State.StateChoices.FINISHED.value
|
||||
).exists()
|
||||
):
|
||||
start_competition_achievement = Achievement.objects.get(
|
||||
slug="start_competition"
|
||||
)
|
||||
UserAchievement.objects.create(
|
||||
user=instance.user, achievement=start_competition_achievement
|
||||
)
|
||||
|
||||
@@ -19,6 +19,7 @@ from apps.user.models import User, UserRole
|
||||
|
||||
faker = Faker("ru_RU")
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = "Generate sample data for Users, Competitions, Tasks, Submissions, and States."
|
||||
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import random
|
||||
import uuid
|
||||
from datetime import timedelta, datetime
|
||||
from datetime import timedelta
|
||||
|
||||
from PIL.Image import Image
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.hashers import make_password
|
||||
from django.core.files.base import ContentFile, File
|
||||
@@ -13,9 +12,9 @@ from apps.competition.models import Competition, State
|
||||
from apps.review.models import Reviewer
|
||||
from apps.task.models import (
|
||||
CompetitionTask,
|
||||
CompetitionTaskAttachment,
|
||||
CompetitionTaskCriteria,
|
||||
CompetitionTaskSubmission,
|
||||
CompetitionTaskAttachment,
|
||||
)
|
||||
from apps.user.models import User, UserRole
|
||||
|
||||
@@ -47,11 +46,11 @@ dataset2 = ContentFile(
|
||||
|
||||
correct_answer_file = ContentFile(
|
||||
b"42",
|
||||
name=f"answer.txt",
|
||||
name="answer.txt",
|
||||
)
|
||||
correct2_answer_file = ContentFile(
|
||||
b"it is a dataset",
|
||||
name=f"answer.txt",
|
||||
name="answer.txt",
|
||||
)
|
||||
|
||||
now = timezone.now()
|
||||
@@ -666,7 +665,7 @@ class Command(BaseCommand):
|
||||
type=competition["type"],
|
||||
participation_type=competition["participation_type"],
|
||||
)
|
||||
except Exception as e:
|
||||
except Exception:
|
||||
print(competition)
|
||||
|
||||
if competition.get("image"):
|
||||
@@ -697,13 +696,18 @@ class Command(BaseCommand):
|
||||
points=task["points"],
|
||||
submission_reviewers_count=task[
|
||||
"submission_reviewers_count"
|
||||
] if task["type"] == CompetitionTask.CompetitionTaskType.REVIEW.value else None,
|
||||
correct_answer_file=task["correct_answer_file"] if task["type"] != CompetitionTask.CompetitionTaskType.REVIEW.value else None,
|
||||
]
|
||||
if task["type"]
|
||||
== CompetitionTask.CompetitionTaskType.REVIEW.value
|
||||
else None,
|
||||
correct_answer_file=task["correct_answer_file"]
|
||||
if task["type"]
|
||||
!= CompetitionTask.CompetitionTaskType.REVIEW.value
|
||||
else None,
|
||||
max_attempts=task.get("max_attempts"),
|
||||
)
|
||||
competitions[i]["tasks"][j]["obj"] = task_obj
|
||||
|
||||
|
||||
if task.get("attachment"):
|
||||
CompetitionTaskAttachment.objects.create(
|
||||
task=task_obj,
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
from sys import stdout
|
||||
from uuid import uuid4
|
||||
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.core.validators import RegexValidator
|
||||
from django.db import models
|
||||
from django.db.models import Count, Q
|
||||
from django.core.validators import RegexValidator
|
||||
from django.core.exceptions import ValidationError
|
||||
from mdeditor.fields import MDTextField
|
||||
|
||||
from apps.competition.models import Competition
|
||||
@@ -88,23 +87,27 @@ class CompetitionTask(BaseModel):
|
||||
# "type": "Если загружен файл правильного ответа, то тип проверки не может быть ручным"
|
||||
# })
|
||||
if not self.correct_answer_file and self.type != "review":
|
||||
raise ValidationError({
|
||||
"correct_answer_file": "Загрузите правильный ответ"
|
||||
})
|
||||
raise ValidationError(
|
||||
{"correct_answer_file": "Загрузите правильный ответ"}
|
||||
)
|
||||
|
||||
# if self.answer_file_path and not self.type == "checker":
|
||||
# raise ValidationError({
|
||||
# "type": "Укажите другой тип задания: этот не совместим с путем правильного ответа"
|
||||
# })
|
||||
if not self.answer_file_path and self.type == "checker":
|
||||
raise ValidationError({
|
||||
raise ValidationError(
|
||||
{
|
||||
"answer_file_path": "Введите путь правильного ответа - это нужно для корректной работы чекера"
|
||||
})
|
||||
}
|
||||
)
|
||||
|
||||
if not self.reviewers and self.type == "review":
|
||||
raise ValidationError({
|
||||
raise ValidationError(
|
||||
{
|
||||
"reviewers": "Загрузите ревьюверов - кто будет проверять задания, если не они?"
|
||||
})
|
||||
}
|
||||
)
|
||||
# elif self.reviewers and not self.type == "review":
|
||||
# raise ValidationError({
|
||||
# "type": "Проверьте тип - вы ввели ревьюверов, но задание не является ручным"
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import base64
|
||||
import hashlib
|
||||
from urllib.parse import urlparse
|
||||
|
||||
import httpx
|
||||
from celery import shared_task
|
||||
from django.conf import settings
|
||||
from django.core.files.base import ContentFile
|
||||
from urllib.parse import urlparse
|
||||
import base64
|
||||
|
||||
from apps.task.models import CompetitionTaskSubmission
|
||||
|
||||
|
||||
@@ -7,4 +7,4 @@ class UsersConfig(AppConfig):
|
||||
verbose_name = "контестанты"
|
||||
|
||||
def ready(self):
|
||||
import apps.user.signals
|
||||
pass
|
||||
|
||||
@@ -88,9 +88,7 @@ async def download_file(
|
||||
session: aiohttp.ClientSession, url: str, dest_path: str
|
||||
) -> None:
|
||||
try:
|
||||
async with session.get(
|
||||
url, timeout=aiohttp.ClientTimeout(total=30)
|
||||
) as resp:
|
||||
async with session.get(url, timeout=aiohttp.ClientTimeout(total=30)) as resp:
|
||||
if resp.status != 200:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
@@ -271,9 +269,7 @@ async def execute_code(request: ExecutionRequest) -> ExecutionResponse:
|
||||
response = ExecutionResponse(
|
||||
success=success,
|
||||
hash_match=(
|
||||
result_hash == request.expected_hash
|
||||
if request.expected_hash
|
||||
else None
|
||||
result_hash == request.expected_hash if request.expected_hash else None
|
||||
),
|
||||
output=output[:5000],
|
||||
result_hash=result_hash,
|
||||
|
||||
Reference in New Issue
Block a user