d5f6abb5ad
Backend:
- Models: TestAttempt, AttemptAnswer (migration 002)
- POST /api/attempts: start attempt, shuffle questions/answers,
hide is_correct, expose is_multiple for UI hints
- POST /api/attempts/{id}/submit: save answers, calculate score,
strict matching (selected == correct), return full result
- GET /api/attempts/{id}/result: fetch saved result
- Register attempts router in main.py
Frontend:
- api/attempts.ts: types + API functions
- TestTake page: one question at a time, progress bar, timer
with auto-submit, back navigation controlled by test setting,
radio/checkbox based on is_multiple
- AttemptResult page: score, pass/fail, per-question breakdown
with correct/selected/missed answer highlighting
- App.tsx: add /tests/:testId/take and /attempts/:id/result routes
- TestDetail: add "Пройти тест" button
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
54 lines
1.7 KiB
Python
54 lines
1.7 KiB
Python
"""attempts
|
|
|
|
Revision ID: 002
|
|
Revises: 001
|
|
Create Date: 2026-03-21
|
|
|
|
"""
|
|
from typing import Sequence, Union
|
|
|
|
import sqlalchemy as sa
|
|
from alembic import op
|
|
|
|
revision: str = "002"
|
|
down_revision: Union[str, None] = "001"
|
|
branch_labels: Union[str, Sequence[str], None] = None
|
|
depends_on: Union[str, Sequence[str], None] = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
op.create_table(
|
|
"test_attempts",
|
|
sa.Column("id", sa.Integer(), nullable=False),
|
|
sa.Column("test_id", sa.Integer(), sa.ForeignKey("tests.id"), nullable=False),
|
|
sa.Column(
|
|
"started_at",
|
|
sa.DateTime(timezone=True),
|
|
server_default=sa.text("now()"),
|
|
nullable=False,
|
|
),
|
|
sa.Column("finished_at", sa.DateTime(timezone=True), nullable=True),
|
|
sa.Column("score", sa.Float(), nullable=True),
|
|
sa.Column("passed", sa.Boolean(), nullable=True),
|
|
sa.Column("correct_count", sa.Integer(), nullable=True),
|
|
sa.Column("total_count", sa.Integer(), nullable=True),
|
|
sa.Column("status", sa.String(20), nullable=False, server_default="in_progress"),
|
|
sa.PrimaryKeyConstraint("id"),
|
|
)
|
|
|
|
op.create_table(
|
|
"attempt_answers",
|
|
sa.Column("id", sa.Integer(), nullable=False),
|
|
sa.Column(
|
|
"attempt_id", sa.Integer(), sa.ForeignKey("test_attempts.id"), nullable=False
|
|
),
|
|
sa.Column("question_id", sa.Integer(), sa.ForeignKey("questions.id"), nullable=False),
|
|
sa.Column("answer_id", sa.Integer(), sa.ForeignKey("answers.id"), nullable=False),
|
|
sa.PrimaryKeyConstraint("id"),
|
|
)
|
|
|
|
|
|
def downgrade() -> None:
|
|
op.drop_table("attempt_answers")
|
|
op.drop_table("test_attempts")
|