Opening a tip before answering is a nudge. The answer that follows is still right — it is counted as right, and the percentage is not docked — but it is not the same as right, so it keeps its own arc on the donut and its own line in the legend: "3 correct after a tip". attempt_answers.used_hint records it. The player reports which questions had a tip opened before the answer went in; a tip read afterwards is revision and does not count, which is the difference two of the tests turn on. Both endings agree about it — an explicit submit carries the list, and an exam that runs out takes it from the saved progress, so a tab closing cannot launder a score. Found while wiring this: RichText declared its component overrides inline in the render, so every one was a fresh component type and React remounted the whole rendered tree on each render. An open tip closed itself every time the exam clock ticked. The map is memoised now. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TqXevQJhxFrM7jJg82cgZN
45 lines
2.1 KiB
Python
45 lines
2.1 KiB
Python
from datetime import datetime
|
|
|
|
from sqlalchemy import Column, Integer, Boolean, String, DateTime, ForeignKey, JSON
|
|
from sqlalchemy.orm import relationship
|
|
|
|
from app.database import Base
|
|
|
|
|
|
class QuizAttempt(Base):
|
|
__tablename__ = "quiz_attempts"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
quiz_id = Column(Integer, ForeignKey("quizzes.id", ondelete="CASCADE"), nullable=False)
|
|
user_id = Column(Integer, ForeignKey("users.id", ondelete="CASCADE"), nullable=False)
|
|
mode = Column(String(10), nullable=True) # legacy NULL resumes without exposing answers
|
|
score = Column(Integer, default=0)
|
|
total_questions = Column(Integer, default=0)
|
|
started_at = Column(DateTime, default=datetime.utcnow)
|
|
completed_at = Column(DateTime, nullable=True)
|
|
selected_question_ids = Column(JSON, nullable=True) # for question pool: which questions this attempt uses
|
|
expired = Column(Integer, default=0) # 1 = auto-submitted due to timer expiry (abandoned), excluded from history
|
|
|
|
quiz = relationship("Quiz", back_populates="attempts")
|
|
user = relationship("User", back_populates="attempts")
|
|
answers = relationship("AttemptAnswer", back_populates="attempt", cascade="all, delete-orphan")
|
|
|
|
|
|
class AttemptAnswer(Base):
|
|
__tablename__ = "attempt_answers"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
attempt_id = Column(Integer, ForeignKey("quiz_attempts.id", ondelete="CASCADE"), nullable=False)
|
|
question_id = Column(Integer, ForeignKey("questions.id", ondelete="CASCADE"), nullable=False)
|
|
user_answer = Column(String, nullable=False)
|
|
# Seconds on this question. Null means an answer from before this was
|
|
# measured, which is not the same claim as zero.
|
|
seconds_spent = Column(Integer, nullable=True)
|
|
is_correct = Column(Boolean, default=False)
|
|
# Whether a tip was opened on this question before it was answered. Rows
|
|
# written before tips existed carry 0, which is not a guess: there was
|
|
# nothing to open.
|
|
used_hint = Column(Boolean, nullable=False, default=False, server_default="0")
|
|
|
|
attempt = relationship("QuizAttempt", back_populates="answers")
|
|
question = relationship("Question")
|