diff --git a/CREDENTIALS.md b/CREDENTIALS.md new file mode 100644 index 0000000..5426f6d --- /dev/null +++ b/CREDENTIALS.md @@ -0,0 +1,79 @@ +# Креды для DATARUSH + +Найдите номер набора на вашей карточке(слева вверху) +#### Администратор + - Логин: `admin` + - Пароль: `prooooooood` + - Ссылка: https://clck.ru/3GkMoo +### Набор 1 +#### Участник +- Почта: germanivanov1984@gmail.com +- Пароль: `password123!` +#### Ревьювер +Ссылка: https://clck.ru/3Gjrtg +### Набор 2 +#### Участник +- Почта: dreamonovich@gmail.com +- Пароль: `password123!` +#### Ревьювер +Ссылка: https://clck.ru/3Gjs9y +### Набор 3 +#### Участник +- Почта: alisa.kuznetsova@gmail.com +- Пароль: `password123!` +#### Ревьювер +Ссылка: https://clck.ru/3GjsDq +### Набор 4 +#### Участник +- Почта: ivan.petrov@gmail.com +- Пароль: `password123!` +#### Ревьювер +Ссылка: https://clck.ru/3GjsK3 +### Набор 5 +#### Участник +- Почта: olga.sidorova@gmail.com +- Пароль: `password123!` +#### Ревьювер +Ссылка: https://clck.ru/3Gjrtg +### Набор 6 +#### Участник +- Почта: karim@gmail.com +- Пароль: `password123!` +#### Ревьювер +Ссылка: https://clck.ru/3Gjsa3 +### Набор 7 +#### Участник +- Почта: noble@gmail.com +- Пароль: `password123!` +#### Ревьювер +Ссылка: https://clck.ru/3Gjsq2 +### Набор 8 +#### Участник +- Почта: koller@gmail.com +- Пароль: `password123!` +#### Ревьювер +Ссылка: https://clck.ru/3Gjt7n +### Набор 9 +#### Участник +- Почта: gold_checker@gmail.com +- Пароль: `password123!` +#### Ревьювер +Ссылка: https://clck.ru/3GjtBp +### Набор 10 +#### Участник +- Почта: looka@gmail.com +- Пароль: `password123!` +#### Ревьювер +Ссылка: https://clck.ru/3GjtLv +### Набор 11 +#### Участник +- Почта: danil_malikov@gmail.com +- Пароль: `password123!` +#### Ревьювер +Ссылка: https://clck.ru/3GjtMh +### Набор 12 +#### Участник +- Почта: marina-looks@gmail.com +- Пароль: `password123!` +#### Ревьювер +Ссылка: https://clck.ru/3GjtNP \ No newline at end of file diff --git a/README.md b/README.md index d3c0007..ae7d05a 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,6 @@ Инновационный сервис для проведения соревнований по анализу данных - ## Запуск Склонируйте репозиторий и пропишите. @@ -24,10 +23,49 @@ docker compose up * `admin` - логин * `proooooood` - пароль +## Как устроен проект + +В проекте используются 3 основных модуля: backend, frontend и checker + +1. `backend` представляет собой приложение, написанное на Django с применением [Django Ninja](https://django-ninja.dev/), который позволяет быстро и легко создавать Restful API. + + Сам бекенд состоит из 2-х основных компонентов: приложений (где хранятся модели, тесты и настройки админ-панели) и основных колбеков (где хранятся схемы OpenAPI и сами ручки) + + Решения на проверку отсылаются через `celery` для асинхронного взаимодействия, так как его ожидание может занять довольно длительное время. + +2. `frontend` является React приложением, которое запускается через Vite. В нем также используется TypeScript для более строгой типизации. Структура приложения является стандартной для подобного вида проектов: есть отдельная папка для компонентов, страниц, стилей, работы с API. + +3. `checker` - микросервис на FastAPI, созданный для безопасного асинхронного запуска посылок пользователей. + + Данные в этот сервис отсылаются по специальной ручке `/execute`, которая является приватной (ее нет в документации) + + Проверка заданий осуществляется через запуск кода пользователя через специально создаваемый Docker контейнер, на который выдаются следующие ресурсы: + +* 1 ядро CPU +* 1 ГБ ОЗУ + + Для приближения к условиям работы аналитиков в интерпритаторе Python есть следующие библиотеки: + + ```python + pandas==2.2.3 + numpy==2.2.3 + matplotlib==3.10.1 + scipy==1.15.2 + scikit-learn==1.6.1 + seaborn==0.13.2 + statsmodels==0.14.4 + ``` + + Контейнеру дается 1 минута на выполнение кода, потом - контейнер удаляется + ## Тесты Написаны unit-тесты (на базе Django TestCase) и E2E (Postman коллекция). Они покрывают flow регистрации, просмотра и участия в соревновании. +Unit-тесты находятся в соответствующих приложениях, которые располагаются по пути `services/backend/apps` + +JSON коллекция, в которой хранятся E2E тесты, находится по пути `img/postman_e2e.json`. Ее можно импортировать в постман, нажав на соответсвующую кнопку в интерфейсе Postman + ![Postman data](img/postman.gif) Ниже можно увидеть Coverage тестами бекенда данного приложения diff --git a/services/backend/api/v1/task/schemas.py b/services/backend/api/v1/task/schemas.py index 95f2fb4..789bcb1 100644 --- a/services/backend/api/v1/task/schemas.py +++ b/services/backend/api/v1/task/schemas.py @@ -33,7 +33,7 @@ class TaskOutSchema(ModelSchema): "description", "in_competition_position", "points", - "max_attempts" + "max_attempts", ] @@ -68,3 +68,4 @@ class TaskStatusSchema(Schema): task_name: str result: int max_points: int + position: int diff --git a/services/backend/api/v1/task/views.py b/services/backend/api/v1/task/views.py index a0ce64c..67f3be4 100644 --- a/services/backend/api/v1/task/views.py +++ b/services/backend/api/v1/task/views.py @@ -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( - user=request.auth, task=task - ).filter(status="checked").order_by("-earned_points").all() + submissions = ( + CompetitionTaskSubmission.objects.filter( + user=request.auth, task=task + ) + .filter(status="checked") + .order_by("-earned_points") + .all() + ) if not submissions: all_submissions_count = CompetitionTaskSubmission.objects.filter( user=request.auth, task=task @@ -206,10 +209,13 @@ def get_competition_results(request, competition_id: UUID): result = -1 else: result = submissions[0].earned_points - data.append(TaskStatusSchema( - task_name=task.title, - result=result, - max_points=task.points, - )) + data.append( + TaskStatusSchema( + task_name=task.title, + result=result, + max_points=task.points, + position=task.in_competition_position, + ) + ) return status.OK, data diff --git a/services/backend/api/v1/team/views.py b/services/backend/api/v1/team/views.py index ab727d6..dd98c06 100644 --- a/services/backend/api/v1/team/views.py +++ b/services/backend/api/v1/team/views.py @@ -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 diff --git a/services/backend/api/v1/user/views.py b/services/backend/api/v1/user/views.py index 11d2481..0570f29 100644 --- a/services/backend/api/v1/user/views.py +++ b/services/backend/api/v1/user/views.py @@ -23,7 +23,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"]) diff --git a/services/backend/apps/competition/apps.py b/services/backend/apps/competition/apps.py index f10ee38..8aba210 100644 --- a/services/backend/apps/competition/apps.py +++ b/services/backend/apps/competition/apps.py @@ -7,4 +7,4 @@ class CompetitionsConfig(AppConfig): verbose_name = "Соревнование" def ready(self): - import apps.competition.signals + pass diff --git a/services/backend/apps/competition/signals.py b/services/backend/apps/competition/signals.py index 9a832bd..20bb7be 100644 --- a/services/backend/apps/competition/signals.py +++ b/services/backend/apps/competition/signals.py @@ -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 ) diff --git a/services/backend/apps/core/management/commands/generate_data.py b/services/backend/apps/core/management/commands/generate_data.py index 855b4d3..b325625 100644 --- a/services/backend/apps/core/management/commands/generate_data.py +++ b/services/backend/apps/core/management/commands/generate_data.py @@ -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." diff --git a/services/backend/apps/core/management/commands/generate_pretty_data.py b/services/backend/apps/core/management/commands/generate_pretty_data.py index 1de2cb5..0a0778e 100644 --- a/services/backend/apps/core/management/commands/generate_pretty_data.py +++ b/services/backend/apps/core/management/commands/generate_pretty_data.py @@ -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, diff --git a/services/backend/apps/task/migrations/0004_alter_competitiontaskattachment_bind_at.py b/services/backend/apps/task/migrations/0004_alter_competitiontaskattachment_bind_at.py new file mode 100644 index 0000000..70dea88 --- /dev/null +++ b/services/backend/apps/task/migrations/0004_alter_competitiontaskattachment_bind_at.py @@ -0,0 +1,19 @@ +# Generated by Django 5.1.6 on 2025-03-03 23:02 + +import django.core.validators +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('task', '0003_alter_competitiontaskattachment_task'), + ] + + operations = [ + migrations.AlterField( + model_name='competitiontaskattachment', + name='bind_at', + field=models.CharField(max_length=255, validators=[django.core.validators.RegexValidator('^(?:[a-zA-Z]:\\\\(?:[^<>:\\"\\/\\\\|?*]*\\\\)*|/(?:[^<>:\\"\\/\\\\|?*]+/?)*)$', message='Введите абсолютный путь до папки')], verbose_name='путь сохранения'), + ), + ] diff --git a/services/backend/apps/task/models.py b/services/backend/apps/task/models.py index 3752c34..57028eb 100644 --- a/services/backend/apps/task/models.py +++ b/services/backend/apps/task/models.py @@ -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({ - "answer_file_path": "Введите путь правильного ответа - это нужно для корректной работы чекера" - }) + raise ValidationError( + { + "answer_file_path": "Введите путь правильного ответа - это нужно для корректной работы чекера" + } + ) if not self.reviewers and self.type == "review": - raise ValidationError({ - "reviewers": "Загрузите ревьюверов - кто будет проверять задания, если не они?" - }) + raise ValidationError( + { + "reviewers": "Загрузите ревьюверов - кто будет проверять задания, если не они?" + } + ) # elif self.reviewers and not self.type == "review": # raise ValidationError({ # "type": "Проверьте тип - вы ввели ревьюверов, но задание не является ручным" diff --git a/services/backend/apps/task/tasks.py b/services/backend/apps/task/tasks.py index 98d3842..4a66982 100644 --- a/services/backend/apps/task/tasks.py +++ b/services/backend/apps/task/tasks.py @@ -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 @@ -35,23 +34,27 @@ def analyze_data_task(self, submission_id): "code": base64.b64encode(code).decode("utf-8"), "answer_file_path": submission.task.answer_file_path, "expected_hash": hashlib.sha256( - submission.task.correct_answer_file.read().decode("utf-8") + submission.task.correct_answer_file.read() ).hexdigest(), }, timeout=30, ) response.raise_for_status() result = response.json() - print(result, response.request) + print(result) - submission.stdout.save("output.txt", ContentFile(result["output"])) + # submission.stdout = ContentFile( + # bytes(result["output"]), + # "output.txt", + # ) + # submission.stdout.save() submission.result = { - "correct": result["correct"], + "correct": result["hash_match"], "hash_match": result["hash_match"], "error": result.get("error"), } submission.earned_points = ( - submission.task.points if result["correct"] else 0 + submission.task.points if result["hash_match"] else 0 ) submission.status = CompetitionTaskSubmission.StatusChoices.CHECKED diff --git a/services/backend/apps/user/apps.py b/services/backend/apps/user/apps.py index 5a1c14f..5674400 100644 --- a/services/backend/apps/user/apps.py +++ b/services/backend/apps/user/apps.py @@ -7,4 +7,4 @@ class UsersConfig(AppConfig): verbose_name = "контестанты" def ready(self): - import apps.user.signals + pass diff --git a/services/backend/scripts/initdb b/services/backend/scripts/initdb index 146732a..7714b7c 100755 --- a/services/backend/scripts/initdb +++ b/services/backend/scripts/initdb @@ -10,4 +10,4 @@ if [ "$DJANGO_CREATE_SUPERUSER" = "True" ]; then python manage.py createsuperuser --noinput --username "$DJANGO_SUPERUSER_USERNAME" --email "$DJANGO_SUPERUSER_EMAIL" || true fi -python manage.py init_achievments \ No newline at end of file +python manage.py init_achievments diff --git a/services/checker/main.py b/services/checker/main.py index e77f7f5..483bfdd 100644 --- a/services/checker/main.py +++ b/services/checker/main.py @@ -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, diff --git a/services/frontend/public/lottie.png b/services/frontend/public/lottie.png new file mode 100644 index 0000000..e2f59b6 Binary files /dev/null and b/services/frontend/public/lottie.png differ diff --git a/services/frontend/src/components/layout/header.tsx b/services/frontend/src/components/layout/header.tsx index 3bc9470..fd6d5af 100644 --- a/services/frontend/src/components/layout/header.tsx +++ b/services/frontend/src/components/layout/header.tsx @@ -30,13 +30,14 @@ export const Header = () => {
- Материалы - + @@ -53,7 +54,7 @@ export const Header = () => {
- + Материалы diff --git a/services/frontend/src/pages/Competition/components/CompetitionResultModal/index.tsx b/services/frontend/src/pages/Competition/components/CompetitionResultModal/index.tsx index b691e77..080d9d6 100644 --- a/services/frontend/src/pages/Competition/components/CompetitionResultModal/index.tsx +++ b/services/frontend/src/pages/Competition/components/CompetitionResultModal/index.tsx @@ -1,4 +1,3 @@ -// src/components/competition/CompetitionResultsModal.tsx import React from 'react'; import { Dialog, @@ -12,7 +11,8 @@ import { Loader2 } from 'lucide-react'; export interface CompetitionResult { task_name: string; result: number; - max_points: number + max_points: number; + position: number; } interface CompetitionResultsModalProps { @@ -111,17 +111,19 @@ export const CompetitionResultsModal: React.FC = ( Произошла ошибка при загрузке результатов
) : results && results.length > 0 ? ( - results.map((result, index) => ( -
-
{result.task_name}
-
- {renderResultValue(result.result, result.max_points)} + [...results] + .sort((a, b) => a.position - b.position) + .map((result, index) => ( +
+
{result.task_name}
+
+ {renderResultValue(result.result, result.max_points)} +
-
- )) + )) ) : (
Нет доступных результатов diff --git a/services/frontend/src/pages/CompetitionSession/components/TaskContent/index.tsx b/services/frontend/src/pages/CompetitionSession/components/TaskContent/index.tsx index 7909578..bd68954 100644 --- a/services/frontend/src/pages/CompetitionSession/components/TaskContent/index.tsx +++ b/services/frontend/src/pages/CompetitionSession/components/TaskContent/index.tsx @@ -74,7 +74,11 @@ const TaskContent: React.FC = ({ task }) => { const getFileNameFromUrl = (url: string): string => { try { const parts = url.split('/'); - return parts[parts.length - 1]; + const fullFileName = parts[parts.length - 1] + const fileName = fullFileName.length > 20 + ? fullFileName.substring(0, 20) + '...' + : fullFileName; + return fileName; } catch (e) { return 'Файл'; } diff --git a/services/frontend/src/pages/CompetitionSession/index.tsx b/services/frontend/src/pages/CompetitionSession/index.tsx index 15cf56f..9ee626f 100644 --- a/services/frontend/src/pages/CompetitionSession/index.tsx +++ b/services/frontend/src/pages/CompetitionSession/index.tsx @@ -150,16 +150,16 @@ const CompetitionSession = () => { onSubmit={handleSubmit} isSubmitting={isSubmitting} /> - {isReloading && ( -
-
- -

- Решение отправлено! Пожалуйста, подождите... -

-
+ {isReloading && ( +
+
+ +

+ Решение отправлено! Пожалуйста, подождите... +

- )} +
+ )}
) : (
diff --git a/services/frontend/src/pages/CompetitionSession/modules/TaskSolution/components/ActionButtons/index.tsx b/services/frontend/src/pages/CompetitionSession/modules/TaskSolution/components/ActionButtons/index.tsx index 03eda32..eb0d280 100644 --- a/services/frontend/src/pages/CompetitionSession/modules/TaskSolution/components/ActionButtons/index.tsx +++ b/services/frontend/src/pages/CompetitionSession/modules/TaskSolution/components/ActionButtons/index.tsx @@ -35,7 +35,7 @@ const ActionButtons: React.FC = ({ > Задача сдана! - ) : hasSubmissionsLeft ? ( + ) : hasSubmissionsLeft? (