liveBook · Manning

Session

As explained in Coding with AI

A session is a recorded instance of a student's practice test that tracks its questions, answers, and result counts.

A session is the durable record for one student’s practice test. It gives that attempt a unique ID, starts correct and incorrect counts at zero, and links the selected questions to the same test so progress can be tracked instead of treating every page load as a new attempt. section 5.3.8 section 5.3.10

A session supports the test workflow by storing and connecting:

  • A unique session ID, created as the primary key for the session record. section 5.3.8
  • Correct and incorrect answer counts, both initialized to zero before the student answers questions. section 5.3.8
  • Thirty-five randomly selected questions, inserted into question_sets with the session ID. section 5.3.9
  • A browser-visible identifier that can be stored in a cookie to recover the same session after a browser closes. section 6.2.1

Create and verify a test attempt

Create a Session, save its generated ID, and insert a question set tied to that ID. Then inspect the database: a new session should have no answers counted yet, while question_sets should contain 35 rows associated with its session_id. If an AI-generated revision causes an import or object-lifecycle error, correct and test it rather than copying it blindly. section 5.3.9 section 5.3.10 section 6.2.1

Figure 5.31 The relationship between sessions and questions sets in our database
A black background with white text

Description automatically generated

Use the relationship diagram to see how a session ID connects one test attempt to its selected question records. section 5.3.8

How Coding with AI covers it

How deep it goes
Works through record creation, question-set insertion, database verification, and cookie-based persistence, while deferring the complete interactive interface.
Examples
Uses a 35-question Ham Radio practice test, session-table inspection, question_sets rows, a displayed session ID, and a cookie prompt.
What it assumes
Assumes an existing question database, question-selection method, database connection, and Flask application.
What you can do after
Build it from scratch as a session record that creates a question set and can persist the selected test across browser visits.
How it connects
Connects SQLite database records, question_sets, Flask templates, cookies, and browser state.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Coding with AI. The section links point to the parts of the book it draws on.