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
+28 -2
View File
@@ -33,7 +33,30 @@ def parse_and_validate_shape(s: Any) -> list[dict]:
raise HttpError(400, f'shape[{i}]: optionsCount от 2 до 12.')
if n < 2 or n > 12:
raise HttpError(400, f'shape[{i}]: optionsCount от 2 до 12.')
out.append({'optionsCount': n, 'hasMultipleAnswers': bool(row.get('hasMultipleAnswers'))})
has_multi = bool(row.get('hasMultipleAnswers'))
raw_min = row.get('minCorrect', 1)
raw_max = row.get('maxCorrect', n if has_multi else 1)
try:
min_c = int(float(raw_min))
max_c = int(float(raw_max))
except (TypeError, ValueError):
raise HttpError(400, f'shape[{i}]: minCorrect/maxCorrect должны быть числами.')
if not has_multi:
min_c = 1
max_c = 1
if min_c < 1 or max_c < 1 or min_c > max_c or max_c > n:
raise HttpError(
400,
f'shape[{i}]: корректный диапазон правильных ответов — от 1 до {n}, min<=max.',
)
out.append(
{
'optionsCount': n,
'hasMultipleAnswers': has_multi,
'minCorrect': min_c,
'maxCorrect': max_c,
}
)
return out
@@ -51,7 +74,10 @@ def generate_full_test_by_shape(test_title: str, test_description: str, shape: l
lines = []
for i, sh in enumerate(shape):
if sh['hasMultipleAnswers']:
tail = 'несколько вариантов помечены как верные (hasMultipleAnswers: true).'
tail = (
'несколько вариантов помечены как верные (hasMultipleAnswers: true), '
f'число правильных от {sh["minCorrect"]} до {sh["maxCorrect"]}.'
)
else:
tail = 'ровно один верный вариант (hasMultipleAnswers: false).'
lines.append(f'Вопрос {i + 1}: ровно {sh["optionsCount"]} вариантов ответа; {tail}')