QuizSession records the complete state of an in-progress quiz run over a Deck. Sessions are persisted to quiz_sessions.json so a learner can close the app and resume exactly where they left off. Smart Merge sync uses updated_at to resolve multi-device conflicts.
Fields
Unique identifier for this session. Auto-generated as a UUID v4 on creation.
Shuffled list of card indices (0-based positions into
deck.cards). The order is fixed at session creation and does not change during the session, ensuring consistent resume behavior.The position within
question_order that the learner is currently on. Advances by one after each answer is submitted. When current_index >= len(question_order) the session is complete.A mapping of
card_id → list of chosen answer strings, recording what the learner selected for each card. Keys are present only for cards that have been answered.Running total of questions answered correctly in this session.
Running total of questions answered incorrectly in this session.
ISO 8601 timestamp of when the session was created, e.g.
"2024-03-15T10:30:00.123456".ISO 8601 timestamp of the last state change. Updated after every answer submission. Used by Smart Merge to resolve conflicts — the session with the newer
updated_at wins.Computed properties
is_complete → bool
Returns True when current_index >= len(question_order), meaning all questions have been presented. A complete session is not automatically deleted — it can still be inspected for its final score.
progress_frac → float
Returns current_index / len(question_order) as a float between 0.0 and 1.0. Returns 0.0 if question_order is empty.
Class methods
new_for_deck(deck) → QuizSession
Creates a fresh QuizSession for the given Deck. The card indices (0 to len(deck.cards) - 1) are shuffled randomly and stored in question_order. current_index, correct_count, and wrong_count all start at 0.
to_dict() → dict
Serializes the session to a JSON-serializable dictionary.
UUID string.
UUID string referencing the parent deck.
Shuffled card index list.
Current position in
question_order.Map of
card_id → string[] recording submitted answers.Number of correct answers so far.
Number of wrong answers so far.
ISO 8601 session creation timestamp.
ISO 8601 last-update timestamp.
from_dict(data) → QuizSession
Deserializes a QuizSession from a dictionary. Missing fields fall back to defaults (new UUID for session_id, empty lists/dicts, zero counts, and current time for timestamps).
JSON example
current_index: 3), and is_complete would be False. progress_frac would be 0.6.
Only answered cards appear as keys in
answers. Cards not yet reached are absent from the map.See also
Deck
The deck a QuizSession runs against.
Flashcard
The individual card data model tracked within a session.