testingwebapp fixes, weeek tasks 2948-2958

This commit is contained in:
Константин Лебединский
2026-05-04 21:29:23 +05:00
parent 0229bc250b
commit 1ea83aa6b4
9 changed files with 1035 additions and 214 deletions
+64
View File
@@ -446,6 +446,70 @@ def generate_missing_hints_for_test(session_or_eng, author_id: str, test_id: str
return {'generated': generated, 'failed': failed, 'skipped': skipped, 'total': len(missing_qs)}
def generate_next_missing_hint_for_test(session_or_eng, author_id: str, test_id: str) -> dict:
"""Генерирует одну недостающую подсказку (для отображения прогресса в UI)."""
from .ai_editor import generate_question_hint
session = get_session()
tid = _to_uuid(test_id)
test = session.get(Test, tid)
if not test:
raise HttpError(404, 'Тест не найден.')
if not is_test_author(test.created_by, author_id) and not is_test_edit_open():
raise HttpError(403, 'Доступ запрещён.')
active_version = (
session.query(TestVersion)
.filter(TestVersion.test_id == tid, TestVersion.is_active.is_(True))
.first()
)
if not active_version:
return {'generated': 0, 'remaining': 0, 'done': True, 'totalMissing': 0}
before = count_missing_hints(None, test_id).get('missing') or 0
missing_qs = (
session.query(Question)
.options(selectinload(Question.options))
.filter(
Question.test_version_id == active_version.id,
(Question.ai_hint == None) | (Question.ai_hint == ''), # noqa: E711
)
.order_by(Question.question_order)
.all()
)
for q in missing_qs:
if not (q.text or '').strip():
continue
valid_opts = [o for o in q.options if (o.text or '').strip()]
if len(valid_opts) < 2:
continue
opt_payload = [{'text': o.text, 'isCorrect': bool(o.is_correct)} for o in q.options]
hint = generate_question_hint(question_text=q.text, options=opt_payload)
if hint:
q.ai_hint = hint
session.commit()
after = count_missing_hints(None, test_id).get('missing') or 0
return {
'generated': 1,
'remaining': after,
'done': after == 0,
'totalMissing': before,
'failed': 0,
}
after = count_missing_hints(None, test_id).get('missing') or 0
return {
'generated': 0,
'remaining': after,
'done': after == 0,
'totalMissing': before,
'failed': 0,
}
def check_question_for_attempt(session_or_eng, user_id: str, test_id: str, attempt_id: str,
question_id: str, selected_option_ids: list[str]) -> dict:
session = get_session()