mirror of
https://gitlab.com/megazordpobeda/DataRush.git
synced 2026-05-24 05:37:09 +00:00
Merge branch 'master' of gitlab.prodcontest.ru:team-15/project
This commit is contained in:
@@ -33,6 +33,7 @@ class TaskOutSchema(ModelSchema):
|
|||||||
"description",
|
"description",
|
||||||
"in_competition_position",
|
"in_competition_position",
|
||||||
"points",
|
"points",
|
||||||
|
"max_attempts"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ from api.v1.user.schemas import (
|
|||||||
TokenSchema,
|
TokenSchema,
|
||||||
UserSchema,
|
UserSchema,
|
||||||
)
|
)
|
||||||
from apps.task.models import CompetitionTaskSubmission
|
from apps.task.models import CompetitionTaskSubmission, CompetitionTask
|
||||||
from apps.user.models import User
|
from apps.user.models import User
|
||||||
|
|
||||||
router = Router(tags=["user"])
|
router = Router(tags=["user"])
|
||||||
@@ -104,9 +104,10 @@ def get_my_stat(request):
|
|||||||
success_attempts_cnt = 0
|
success_attempts_cnt = 0
|
||||||
|
|
||||||
for attempt in checked_attempts:
|
for attempt in checked_attempts:
|
||||||
|
if attempt.task.type == CompetitionTask.CompetitionTaskType.REVIEW:
|
||||||
|
is_correct = attempt.earned_points > 0
|
||||||
|
else:
|
||||||
is_correct = attempt.result.get("correct", None)
|
is_correct = attempt.result.get("correct", None)
|
||||||
if is_correct is None:
|
|
||||||
is_correct = attempt.result.get("total_points", 0) > 0
|
|
||||||
|
|
||||||
if is_correct:
|
if is_correct:
|
||||||
success_attempts_cnt += 1
|
success_attempts_cnt += 1
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 27 KiB |
@@ -30,3 +30,13 @@ class Command(BaseCommand):
|
|||||||
slug="welcome",
|
slug="welcome",
|
||||||
icon=welcome_icon,
|
icon=welcome_icon,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if not Achievement.objects.filter(slug="start_competition").exists():
|
||||||
|
with open(f"{icons_dir}/start_competition.png", "rb") as f:
|
||||||
|
start_competition = File(f, name="start_competition.png")
|
||||||
|
Achievement.objects.get_or_create(
|
||||||
|
name="Да начнётся битва!",
|
||||||
|
description="Начните соревнование",
|
||||||
|
slug="start_competition",
|
||||||
|
icon=start_competition,
|
||||||
|
)
|
||||||
|
|||||||
@@ -5,3 +5,6 @@ class CompetitionsConfig(AppConfig):
|
|||||||
name = "apps.competition"
|
name = "apps.competition"
|
||||||
label = "competition"
|
label = "competition"
|
||||||
verbose_name = "Соревнование"
|
verbose_name = "Соревнование"
|
||||||
|
|
||||||
|
def ready(self):
|
||||||
|
import apps.competition.signals
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
from django.db.models.signals import post_save
|
||||||
|
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")
|
||||||
|
UserAchievement.objects.create(
|
||||||
|
user=instance.user, achievement=start_competition_achievement
|
||||||
|
)
|
||||||
+11
-9
@@ -2,13 +2,14 @@ import React from 'react';
|
|||||||
import { Link } from 'react-router-dom';
|
import { Link } from 'react-router-dom';
|
||||||
import { Task } from '@/shared/types/task';
|
import { Task } from '@/shared/types/task';
|
||||||
import { ArrowLeft } from 'lucide-react';
|
import { ArrowLeft } from 'lucide-react';
|
||||||
|
import { useNavigate } from 'react-router-dom';
|
||||||
|
|
||||||
interface CompetitionHeaderProps {
|
interface CompetitionHeaderProps {
|
||||||
title: string;
|
title: string;
|
||||||
tasks: Task[];
|
tasks: Task[];
|
||||||
competitionId: string;
|
competitionId: string;
|
||||||
setAnswer: (value: string) => void;
|
setAnswer: (value: string) => void;
|
||||||
setSelectedFile: (file: File | null) => void; // заглушка
|
setSelectedFile: (file: File | null) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const CompetitionHeader: React.FC<CompetitionHeaderProps> = ({
|
const CompetitionHeader: React.FC<CompetitionHeaderProps> = ({
|
||||||
@@ -18,11 +19,13 @@ const CompetitionHeader: React.FC<CompetitionHeaderProps> = ({
|
|||||||
setAnswer,
|
setAnswer,
|
||||||
setSelectedFile
|
setSelectedFile
|
||||||
}) => {
|
}) => {
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
const handleTaskSelect = () => {
|
const handleTaskSelect = (taskId: string) => {
|
||||||
setAnswer("")
|
setAnswer("");
|
||||||
setSelectedFile(null)
|
setSelectedFile(null);
|
||||||
console.log("STOP IT")
|
|
||||||
|
navigate(`/competition/${competitionId}/tasks/${taskId}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -32,7 +35,6 @@ const CompetitionHeader: React.FC<CompetitionHeaderProps> = ({
|
|||||||
<Link
|
<Link
|
||||||
to={`/competition/${competitionId}`}
|
to={`/competition/${competitionId}`}
|
||||||
className="flex items-center text-gray-600 hover:text-gray-900 transition-colors font-hse-sans text-sm"
|
className="flex items-center text-gray-600 hover:text-gray-900 transition-colors font-hse-sans text-sm"
|
||||||
onClick={handleTaskSelect}
|
|
||||||
>
|
>
|
||||||
<ArrowLeft className="h-4 w-4 mr-1" />
|
<ArrowLeft className="h-4 w-4 mr-1" />
|
||||||
</Link>
|
</Link>
|
||||||
@@ -46,16 +48,16 @@ const CompetitionHeader: React.FC<CompetitionHeaderProps> = ({
|
|||||||
|
|
||||||
<div className="flex items-center justify-center gap-4 pb-4 overflow-x-auto no-scrollbar">
|
<div className="flex items-center justify-center gap-4 pb-4 overflow-x-auto no-scrollbar">
|
||||||
{tasks.map((task) => (
|
{tasks.map((task) => (
|
||||||
<Link
|
<button
|
||||||
key={task.id}
|
key={task.id}
|
||||||
to={`/competition/${competitionId}/tasks/${task.id}`}
|
|
||||||
className={`text-[var(--color-task-text-uncleared)] bg-[var(--color-task-uncleared)]
|
className={`text-[var(--color-task-text-uncleared)] bg-[var(--color-task-uncleared)]
|
||||||
rounded-lg px-3 py-1.5 font-medium text-sm font-hse-sans cursor-pointer
|
rounded-lg px-3 py-1.5 font-medium text-sm font-hse-sans cursor-pointer
|
||||||
transition-all hover:brightness-95 flex-shrink-0
|
transition-all hover:brightness-95 flex-shrink-0
|
||||||
`}
|
`}
|
||||||
|
onClick={() => handleTaskSelect(task.id)}
|
||||||
>
|
>
|
||||||
{task.in_competition_position}
|
{task.in_competition_position}
|
||||||
</Link>
|
</button>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
+4
-5
@@ -8,6 +8,7 @@ interface FileSolutionProps {
|
|||||||
fileInputRef: React.RefObject<HTMLInputElement>;
|
fileInputRef: React.RefObject<HTMLInputElement>;
|
||||||
existingFileUrl?: string | null;
|
existingFileUrl?: string | null;
|
||||||
onClearExistingFile?: () => void; // New prop to clear existing file URL
|
onClearExistingFile?: () => void; // New prop to clear existing file URL
|
||||||
|
firstSolution: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
const FileSolution: React.FC<FileSolutionProps> = ({
|
const FileSolution: React.FC<FileSolutionProps> = ({
|
||||||
@@ -15,7 +16,8 @@ const FileSolution: React.FC<FileSolutionProps> = ({
|
|||||||
setSelectedFile,
|
setSelectedFile,
|
||||||
fileInputRef,
|
fileInputRef,
|
||||||
existingFileUrl = null,
|
existingFileUrl = null,
|
||||||
onClearExistingFile
|
onClearExistingFile,
|
||||||
|
firstSolution
|
||||||
}) => {
|
}) => {
|
||||||
const handleFileChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
const handleFileChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
if (event.target.files && event.target.files[0]) {
|
if (event.target.files && event.target.files[0]) {
|
||||||
@@ -59,9 +61,6 @@ const FileSolution: React.FC<FileSolutionProps> = ({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSelectNewFile = () => {
|
|
||||||
fileInputRef.current?.click();
|
|
||||||
};
|
|
||||||
|
|
||||||
const fileName = selectedFile
|
const fileName = selectedFile
|
||||||
? selectedFile.name
|
? selectedFile.name
|
||||||
@@ -69,7 +68,7 @@ const FileSolution: React.FC<FileSolutionProps> = ({
|
|||||||
? existingFileUrl.split('/').pop() || 'file'
|
? existingFileUrl.split('/').pop() || 'file'
|
||||||
: '';
|
: '';
|
||||||
|
|
||||||
const hasFile = !!selectedFile || !!existingFileUrl;
|
const hasFile = !!selectedFile || (!!existingFileUrl && !firstSolution);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|||||||
@@ -1,32 +1,32 @@
|
|||||||
import React, { useState, useRef, useEffect } from 'react';
|
import React, { useState, useRef, useEffect } from 'react';
|
||||||
import { useParams } from 'react-router-dom';
|
import { useParams } from 'react-router-dom';
|
||||||
import { Task, TaskType, Solution } from '@/shared/types/task';
|
import { Task, TaskType, Solution } from '@/shared/types/task';
|
||||||
import { useQuery } from '@tanstack/react-query';
|
import { useQuery } from '@tanstack/react-query';
|
||||||
import { getTaskSolutionHistory } from '@/shared/api/session';
|
import { getTaskSolutionHistory } from '@/shared/api/session';
|
||||||
import SolutionStatus from './components/SolutionStatus';
|
import SolutionStatus from './components/SolutionStatus';
|
||||||
import InputSolution from './components/InputSolution';
|
import InputSolution from './components/InputSolution';
|
||||||
import FileSolution from './components/FileSolution';
|
import FileSolution from './components/FileSolution';
|
||||||
import CodeSolution from './components/CodeSolution';
|
import CodeSolution from './components/CodeSolution';
|
||||||
import ActionButtons from './components/ActionButtons';
|
import ActionButtons from './components/ActionButtons';
|
||||||
import SolutionHistorySheet from './components/SolutionHistorySheet';
|
import SolutionHistorySheet from './components/SolutionHistorySheet';
|
||||||
|
|
||||||
interface TaskSolutionProps {
|
interface TaskSolutionProps {
|
||||||
task: Task;
|
task: Task;
|
||||||
answer: string;
|
answer: string;
|
||||||
setAnswer: (value: string) => void;
|
setAnswer: (value: string) => void;
|
||||||
selectedFile: File | null;
|
selectedFile: File | null;
|
||||||
setSelectedFile: (file: File | null) => void;
|
setSelectedFile: (file: File | null) => void;
|
||||||
onSubmit: () => void;
|
onSubmit: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const TaskSolution: React.FC<TaskSolutionProps> = ({
|
const TaskSolution: React.FC<TaskSolutionProps> = ({
|
||||||
task,
|
task,
|
||||||
answer,
|
answer,
|
||||||
setAnswer,
|
setAnswer,
|
||||||
selectedFile,
|
selectedFile,
|
||||||
setSelectedFile,
|
setSelectedFile,
|
||||||
onSubmit,
|
onSubmit,
|
||||||
}) => {
|
}) => {
|
||||||
const fileInputRef = useRef<HTMLInputElement>(null);
|
const fileInputRef = useRef<HTMLInputElement>(null);
|
||||||
const [isHistoryOpen, setIsHistoryOpen] = useState(false);
|
const [isHistoryOpen, setIsHistoryOpen] = useState(false);
|
||||||
const [selectedSolutionUrl, setSelectedSolutionUrl] = useState<string | null>(null);
|
const [selectedSolutionUrl, setSelectedSolutionUrl] = useState<string | null>(null);
|
||||||
@@ -54,7 +54,6 @@ const TaskSolution: React.FC<TaskSolutionProps> = ({
|
|||||||
setDisplayedSolution(null);
|
setDisplayedSolution(null);
|
||||||
setSelectedSolutionUrl(null);
|
setSelectedSolutionUrl(null);
|
||||||
|
|
||||||
// If solutions are already loaded for the new task, set the latest one
|
|
||||||
if (solutionHistory.length > 0) {
|
if (solutionHistory.length > 0) {
|
||||||
const latestSolution = solutionHistory[solutionHistory.length - 1];
|
const latestSolution = solutionHistory[solutionHistory.length - 1];
|
||||||
setDisplayedSolution(latestSolution);
|
setDisplayedSolution(latestSolution);
|
||||||
@@ -64,13 +63,10 @@ const TaskSolution: React.FC<TaskSolutionProps> = ({
|
|||||||
}
|
}
|
||||||
}, [task.id, solutionHistory]);
|
}, [task.id, solutionHistory]);
|
||||||
|
|
||||||
// Check if a new solution was submitted (latest solution ID changed)
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (solutionHistory.length > 0 && displayedSolution) {
|
if (solutionHistory.length > 0 && displayedSolution) {
|
||||||
const latestSolution = solutionHistory[solutionHistory.length - 1];
|
const latestSolution = solutionHistory[solutionHistory.length - 1];
|
||||||
|
|
||||||
// If the latest solution ID is different from the displayed one,
|
|
||||||
// a new solution was submitted - update to show the latest
|
|
||||||
if (latestSolution.id !== displayedSolution.id) {
|
if (latestSolution.id !== displayedSolution.id) {
|
||||||
setDisplayedSolution(latestSolution);
|
setDisplayedSolution(latestSolution);
|
||||||
}
|
}
|
||||||
@@ -108,7 +104,6 @@ const TaskSolution: React.FC<TaskSolutionProps> = ({
|
|||||||
|
|
||||||
const handleSolutionSelect = (solution: Solution) => {
|
const handleSolutionSelect = (solution: Solution) => {
|
||||||
setDisplayedSolution(solution);
|
setDisplayedSolution(solution);
|
||||||
console.log(displayedSolution)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleClearExistingFile = () => {
|
const handleClearExistingFile = () => {
|
||||||
@@ -118,7 +113,13 @@ const TaskSolution: React.FC<TaskSolutionProps> = ({
|
|||||||
return (
|
return (
|
||||||
<div className="md:w-[500px] flex flex-col gap-4">
|
<div className="md:w-[500px] flex flex-col gap-4">
|
||||||
{displayedSolution ? (
|
{displayedSolution ? (
|
||||||
|
<>
|
||||||
|
<div className="bg-gray-100 rounded-lg p-4 text-gray-600 font-hse-sans">
|
||||||
|
Последнее решение
|
||||||
|
</div>
|
||||||
<SolutionStatus solution={displayedSolution} maxPoints={task.points}/>
|
<SolutionStatus solution={displayedSolution} maxPoints={task.points}/>
|
||||||
|
</>
|
||||||
|
|
||||||
) : (
|
) : (
|
||||||
<div className="bg-gray-100 rounded-lg p-4 text-gray-600 font-hse-sans">
|
<div className="bg-gray-100 rounded-lg p-4 text-gray-600 font-hse-sans">
|
||||||
Решение еще не отправлено
|
Решение еще не отправлено
|
||||||
@@ -139,6 +140,7 @@ const TaskSolution: React.FC<TaskSolutionProps> = ({
|
|||||||
fileInputRef={fileInputRef}
|
fileInputRef={fileInputRef}
|
||||||
existingFileUrl={selectedSolutionUrl}
|
existingFileUrl={selectedSolutionUrl}
|
||||||
onClearExistingFile={handleClearExistingFile}
|
onClearExistingFile={handleClearExistingFile}
|
||||||
|
firstSolution={solutionHistory.length > 0}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
@@ -163,6 +165,6 @@ const TaskSolution: React.FC<TaskSolutionProps> = ({
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default TaskSolution;
|
export default TaskSolution;
|
||||||
Reference in New Issue
Block a user