2828questions : list [str ] = list (set (p ["question" ] for p in pairs ))
2929configs : list [str ] = list (set (p ["config" ] for p in pairs ))
3030
31- # prepare all unique pairs of configs for each question and insert into db if not already there
3231def prepare_pairs ():
32+ """Prepare and insert unique configuration pairs for A/B testing.
33+
34+ For each question, generates all unique pairs of configurations and inserts
35+ them into the ab_pairs table if they don't already exist.
36+ """
3337 conn = get_db_connection ()
3438 cur = conn .cursor ()
3539 # insert unique pairs of configs for each question into the ab_pairs table (if they don't already exist)
@@ -53,8 +57,13 @@ def prepare_pairs():
5357 conn .close ()
5458
5559
56- # get the next unanswered pair from the db, along with the corresponding answers, and randomize left/right
5760def get_next_pair () -> tuple [int , str , dict , dict ] | None :
61+ """Retrieve the next unanswered A/B testing pair with randomized positioning.
62+
63+ Fetches an unanswered comparison pair from the database along with their
64+ corresponding answers. Randomly assigns configs to left/right positions
65+ to avoid position bias.
66+ """
5867 conn = get_db_connection ()
5968 cur = conn .cursor ()
6069
@@ -95,6 +104,11 @@ def get_next_pair() -> tuple[int, str, dict, dict] | None:
95104
96105@app .route ("/" )
97106def index ():
107+ """Render the A/B evaluation interface with the next comparison pair.
108+
109+ Fetches the next unanswered pair and renders the evaluation template.
110+ Returns a completion message when all pairs have been evaluated.
111+ """
98112 pair = get_next_pair ()
99113
100114 if not pair :
@@ -113,6 +127,12 @@ def index():
113127
114128@app .route ("/vote" , methods = ["POST" ])
115129def vote ():
130+ """Process and save a user's vote for an A/B comparison pair.
131+
132+ Extracts the pair_id and winner choice from the form submission, records
133+ the vote in ab_results, marks the pair as answered, and redirects to the
134+ next evaluation.
135+ """
116136 pair_id = request .form ["pair_id" ]
117137 winner = request .form ["winner" ]
118138
0 commit comments