feat: background tasks manager and book sentence mining for CEFR tests

This commit is contained in:
Antigravity committed 2026-10-06 16:36:39 +03:00
1 parent 332286b641
commit c9da5bd351
11 files changed
+1377 -16

No files matched your search

+16 -7
View File
@@ -1968,7 +1968,8 @@ def get_cefr_quiz_batch(
if mode == "mistakes":
rows = conn.execute(
"""
SELECT q.id, q.level, q.sentence, q.translation, q.pos, q.options_json
SELECT q.id, q.level, q.sentence, q.translation, q.pos, q.options_json,
q.source_book_id, q.source_book_title, q.source_chapter_title
FROM cefr_questions q
JOIN cefr_progress p ON q.id = p.question_id
WHERE p.user_id = ? AND q.level = ? AND p.is_mastered = 0 AND p.mistakes > 0
@@ -1981,13 +1982,14 @@ def get_cefr_quiz_batch(
# 1. Unattempted questions
rows = conn.execute(
"""
SELECT q.id, q.level, q.sentence, q.translation, q.pos, q.options_json
SELECT q.id, q.level, q.sentence, q.translation, q.pos, q.options_json,
q.source_book_id, q.source_book_title, q.source_chapter_title
FROM cefr_questions q
LEFT JOIN cefr_progress p ON q.id = p.question_id AND p.user_id = ?
WHERE q.level = ? AND (p.question_id IS NULL OR p.is_mastered = 0)
ORDER BY CASE WHEN p.question_id IS NULL THEN 0 ELSE 1 END,
p.last_tested_at ASC,
q.id ASC
q.id DESC
LIMIT ?
""",
(user_id, clean_level, count),
@@ -2000,10 +2002,11 @@ def get_cefr_quiz_batch(
placeholders = ",".join(["?"] * len(existing_ids)) if existing_ids else "-1"
extra = conn.execute(
f"""
SELECT q.id, q.level, q.sentence, q.translation, q.pos, q.options_json
SELECT q.id, q.level, q.sentence, q.translation, q.pos, q.options_json,
q.source_book_id, q.source_book_title, q.source_chapter_title
FROM cefr_questions q
WHERE q.level = ? AND q.id NOT IN ({placeholders})
ORDER BY q.id ASC
ORDER BY q.id DESC
LIMIT ?
""",
[clean_level] + existing_ids + [needed],
@@ -2020,14 +2023,18 @@ def get_cefr_quiz_batch(
shuffled_options = list(options)
random.shuffle(shuffled_options)
quiz_items.append({
item = {
"id": r["id"],
"level": r["level"],
"sentence": r["sentence"],
"clue": r["translation"],
"pos": r["pos"] or "",
"options": shuffled_options,
})
}
if "source_book_title" in r.keys() and r["source_book_title"]:
item["source_book_title"] = r["source_book_title"]
item["source_chapter_title"] = r["source_chapter_title"] or ""
quiz_items.append(item)
return quiz_items
@@ -2212,6 +2219,8 @@ def process_cefr_answer(
"selected_card_id": selected_card_info["card_id"] if selected_card_info else None,
"selected_card_term": selected_clean if not is_correct else None,
"selected_translation": selected_card_info["translation"] if selected_card_info else None,
"source_book_title": q_row["source_book_title"] if "source_book_title" in q_row.keys() else None,
"source_chapter_title": q_row["source_chapter_title"] if "source_chapter_title" in q_row.keys() else None,
"options_breakdown": options_breakdown,
}