feat: add standalone goal calculator

This commit is contained in:
nyan404 committed 2026-08-25 03:23:24 +03:00
1 parent 0041e683fe
commit b948331b72
3 files changed
+89

No files matched your search

+25
View File
@@ -15,6 +15,7 @@ from .domain import (
calculate_coaching,
calculate_inspection,
calculate_training,
calculate_goal,
)
from .reports import render_coaching, render_inspection, render_training
from .identity import IdentityDirectory
@@ -186,6 +187,30 @@ def calculate_payload(payload: dict[str, Any]) -> dict[str, Any]:
)
result = calculate_inspection(report)
return {"mode": mode, "result": asdict(result), "message": render_inspection(report, result)}
if mode == "goal":
def _number_value(key: str) -> float:
value = _required(payload, key)
try:
return float(value)
except (TypeError, ValueError) as exc:
raise ApiError(f"Поле {key} должно быть числом") from exc
minutes = _int(payload, "minutes_per_session")
result = calculate_goal(
current_points=_number_value("current_points"),
target_points=_number_value("target_points"),
minutes_per_session=minutes,
skill=str(payload.get("skill", "ЛУ")),
kitten_independence=str(payload.get("kitten_independence", "самостоятельно")),
kitten_count=_int(payload, "kitten_count"),
)
message = (
f"Осталось добрать: {result.remaining_points} баллов.\n"
f"За один заход ({result.minutes_per_session} мин): {result.points_per_session} баллов.\n"
f"Нужно заходов: {result.sessions}.\n"
f"Общее время: {result.total_minutes} минут ({result.total_hours} ч)."
)
return {"mode": mode, "result": asdict(result), "message": message}
except (KeyError, IndexError, TypeError, ValueError) as exc:
if isinstance(exc, ApiError):
raise