This commit is contained in:
Константин Лебединский
2026-04-30 14:11:15 +05:00
parent ebb58d4b5a
commit db9851eeda
8 changed files with 527 additions and 24 deletions
+22 -5
View File
@@ -364,9 +364,18 @@ def count_missing_hints(session_or_eng, test_id: str) -> dict:
if not active_version:
return {'total': 0, 'missing': 0}
all_qs = session.query(Question).filter(Question.test_version_id == active_version.id).all()
total = len(all_qs)
missing = sum(1 for q in all_qs if not q.ai_hint)
all_qs = session.query(Question).options(selectinload(Question.options)).filter(
Question.test_version_id == active_version.id
).all()
filled_qs = []
for q in all_qs:
if not (q.text or '').strip():
continue
if len([o for o in q.options if (o.text or '').strip()]) < 2:
continue
filled_qs.append(q)
total = len(filled_qs)
missing = sum(1 for q in filled_qs if not q.ai_hint)
return {'total': total, 'missing': missing}
@@ -400,8 +409,16 @@ def generate_missing_hints_for_test(session_or_eng, author_id: str, test_id: str
.all()
)
generated = failed = 0
generated = failed = skipped = 0
for q in missing_qs:
# Подсказку строим только по заполненному вопросу (есть текст и >=2 непустых варианта).
if not (q.text or '').strip():
skipped += 1
continue
valid_opts = [o for o in q.options if (o.text or '').strip()]
if len(valid_opts) < 2:
skipped += 1
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:
@@ -410,7 +427,7 @@ def generate_missing_hints_for_test(session_or_eng, author_id: str, test_id: str
else:
failed += 1
session.commit()
return {'generated': generated, 'failed': failed, 'total': len(missing_qs)}
return {'generated': generated, 'failed': failed, 'skipped': skipped, 'total': len(missing_qs)}
def check_question_for_attempt(session_or_eng, user_id: str, test_id: str, attempt_id: str,