New math fixes, again

This commit is contained in:
nyan404 committed 2026-08-16 23:40:15 +03:00
1 parent 92605e7a4d
commit ec5a1a197a
5 files changed
+130 -62

No files matched your search

+10 -10
View File
@@ -73,6 +73,8 @@ class CoachingSession:
_positive_id(kitten_id, "ID дополнительного котёнка")
if independence not in ("самостоятельно", "несамостоятельно"):
raise ValueError("Некорректный статус самостоятельности")
if any(independence != self.kitten_independence for _, _, independence in self.extra_kittens):
raise ValueError("Все котята в одном отчёте должны быть либо самостоятельными, либо несамостоятельными")
@staticmethod
def duration_minutes(start: str, end: str) -> int:
@@ -95,26 +97,24 @@ def calculate_coaching(session: CoachingSession) -> CoachingResult:
if minutes <= 0:
raise ValueError("Продолжительность захода должна быть больше нуля")
# The multiplier belongs to the escort (Krylan/Belka), not to the kitten.
# ZU is always treated as independent according to the calculator rules.
independence_multiplier = (
1.5
if session.skill == "ЛУ" and session.kitten_independence == "несамостоятельно"
else 1.0
)
kitten_count = 1 + len(session.extra_kittens)
# Several wards share one report: the second ward pays 1.5x, and each
# following ward adds a further 1.15x multiplier instead of another full
# base payout.
ward_multiplier = 1.0 if kitten_count == 1 else 1.5 * (1.15 ** (kitten_count - 2))
escort_multiplier = independence_multiplier * ward_multiplier
# The independence bonus applies to every skill, including зоркость (ЗУ),
# and is calculated separately for each non-independent kitten.
nonself_count = (session.kitten_independence == "несамостоятельно") + sum(
independence == "несамостоятельно" for _, _, independence in session.extra_kittens
)
nonself_bonus = minutes * 0.5 * nonself_count / 5
return CoachingResult(
minutes=minutes,
escort_points=_points(minutes * escort_multiplier / 5),
escort_points=_points(minutes * ward_multiplier / 5 + nonself_bonus),
kitten_points=_points(minutes / 5),
kitten_count=kitten_count,
escort_multiplier=round(escort_multiplier, 4),
escort_multiplier=round(ward_multiplier, 4),
)