LU 1 nonsam
This commit is contained in:
1 parent
ec5a1a197a
commit
aa4c5f3681
5 files changed
+28
-25
No files matched your search
+11
-7
@@ -74,9 +74,12 @@ def _extra_kittens(value: str) -> tuple[tuple[str, int, str], ...]:
|
||||
return tuple(result)
|
||||
|
||||
|
||||
def _validate_uniform_independence(primary: str, extras: tuple[tuple[str, int, str], ...] | list[tuple[str, int, str]]) -> None:
|
||||
if any(independence != primary for _, _, independence in extras):
|
||||
raise ValueError("Все котята в одном отчёте должны быть либо самостоятельными, либо несамостоятельными")
|
||||
def _validate_independence(skill: str, primary: str, extras: tuple[tuple[str, int, str], ...] | list[tuple[str, int, str]]) -> None:
|
||||
statuses = (primary,) + tuple(independence for _, _, independence in extras)
|
||||
if skill == "ЗУ" and len(set(statuses)) > 1:
|
||||
raise ValueError("Для ЗУ все котята в одном отчёте должны иметь одинаковый статус")
|
||||
if skill == "ЛУ" and sum(status == "несамостоятельно" for status in statuses) > 1:
|
||||
raise ValueError("Для ЛУ допускается только один несамостоятельный котёнок")
|
||||
|
||||
|
||||
def _kitten_entry(value: str) -> tuple[str, int, str | None]:
|
||||
@@ -120,7 +123,7 @@ def parse_text_command(text: str) -> dict[str, Any]:
|
||||
extras.extend(_extra_kittens(extra_part))
|
||||
primary_independence = ("несамостоятельно" if status_part.lower().startswith("несам") else "самостоятельно") if status_is_valid else (primary_status or "самостоятельно")
|
||||
extras = [(name, kitten_id, status or primary_independence) for name, kitten_id, status in extras]
|
||||
_validate_uniform_independence(primary_independence, extras)
|
||||
_validate_independence("ЛУ", primary_independence, extras)
|
||||
return {
|
||||
"mode": "coaching", "date": date, "skill": "ЛУ", "start": start, "end": end,
|
||||
"escort_name": escort_name, "escort_id": escort_id,
|
||||
@@ -131,6 +134,7 @@ def parse_text_command(text: str) -> dict[str, Any]:
|
||||
}
|
||||
if command in ("/зу", "/зоркость"):
|
||||
parsed = parse_text_command("/лу " + body)
|
||||
_validate_independence("ЗУ", parsed["kitten_independence"], parsed.get("extra_kittens", ()))
|
||||
parsed["skill"] = "ЗУ"
|
||||
return parsed
|
||||
if command in ("/урок", "/тренировка"):
|
||||
@@ -445,7 +449,7 @@ class BelkiDialog:
|
||||
("start", "Укажите время начала в формате HH:MM."),
|
||||
("end", "Укажите время конца (конец захода) в формате HH:MM."),
|
||||
("escort", "Укажите сопровождающего в формате Имя [ID]."),
|
||||
("kitten", "Укажите имя котёнка или котят через запятую в формате Имя [ID].\nНапример: Беззубик [1566767], Малыш [123456].\nДля нескольких котят укажите один общий статус: все самостоятельные или все несамостоятельные."),
|
||||
("kitten", "Укажите имя котёнка или котят через запятую в формате Имя [ID].\nНапример: Беззубик [1566767], Малыш [123456].\nДля ЛУ допускается максимум один несамостоятельный котёнок; для ЗУ статусы всех котят должны совпадать."),
|
||||
("independence", "Котёнок самостоятельный или несамостоятельный?"),
|
||||
),
|
||||
"training": (
|
||||
@@ -769,7 +773,7 @@ class BelkiDialog:
|
||||
if state.get("mode") == "coaching" and len(kittens) > 1:
|
||||
primary = primary_status or state.get("kitten_independence") or "самостоятельно"
|
||||
extras = [(name, kitten_id, status or primary) for name, kitten_id, status in kittens[1:]]
|
||||
_validate_uniform_independence(primary, extras)
|
||||
_validate_independence(state.get("skill", "ЛУ"), primary, extras)
|
||||
state["extra_kittens"] = extras
|
||||
except ValueError as exc:
|
||||
return str(exc)
|
||||
@@ -886,7 +890,7 @@ class BelkiDialog:
|
||||
primary = state.get("kitten_independence", "самостоятельно")
|
||||
additions = [(name, kitten_id, status or primary) for name, kitten_id, status in additions]
|
||||
try:
|
||||
_validate_uniform_independence(primary, state["extra_kittens"] + additions)
|
||||
_validate_independence(state.get("skill", "ЛУ"), primary, state["extra_kittens"] + additions)
|
||||
except ValueError as exc:
|
||||
return str(exc)
|
||||
state["extra_kittens"].extend(additions)
|
||||
|
||||
Reference in new issue
Block a user