86 lines
2.9 KiB
Python
86 lines
2.9 KiB
Python
from __future__ import annotations
|
||
|
||
from .domain import (
|
||
CoachingResult,
|
||
CoachingSession,
|
||
InspectionReport,
|
||
InspectionResult,
|
||
TrainingSession,
|
||
TrainingResult,
|
||
calculate_inspection,
|
||
format_clock,
|
||
parse_clock,
|
||
)
|
||
|
||
|
||
def _number(value: float | int) -> str:
|
||
return str(value).rstrip("0").rstrip(".") if isinstance(value, float) else str(value)
|
||
|
||
|
||
def _points_phrase(value: float | int) -> str:
|
||
"""Return a number with the natural Russian form of «балл»."""
|
||
number = _number(value)
|
||
if isinstance(value, float) and not value.is_integer():
|
||
word = "балла"
|
||
else:
|
||
integer = abs(int(value))
|
||
last_two = integer % 100
|
||
last = integer % 10
|
||
if 11 <= last_two <= 14:
|
||
word = "баллов"
|
||
elif last == 1:
|
||
word = "балл"
|
||
elif last in (2, 3, 4):
|
||
word = "балла"
|
||
else:
|
||
word = "баллов"
|
||
return f"{number} {word}"
|
||
|
||
|
||
def render_coaching(session: CoachingSession, result: CoachingResult) -> str:
|
||
hashtag = "#лазание" if session.skill == "ЛУ" else "#зоркость"
|
||
kitten_text = f"{session.kitten_name} [{session.kitten_id}]"
|
||
if session.extra_kittens:
|
||
kitten_text += ", " + ", ".join(f"{name} [{kitten_id}]" for name, kitten_id, _ in session.extra_kittens)
|
||
lines = [
|
||
hashtag,
|
||
f"{session.escort_name} [{session.escort_id}], помог(-ла) {kitten_text} "
|
||
f"прокачать {session.skill}.",
|
||
f"Время: {format_clock(parse_clock(session.start))} – "
|
||
f"{format_clock(parse_clock(session.end))} [{result.minutes} минут].",
|
||
f"Баллы белки: {_points_phrase(result.escort_points)}.",
|
||
f"Баллы бельчонка: {_points_phrase(result.kitten_points)}.",
|
||
]
|
||
return "\n".join(lines)
|
||
|
||
|
||
def render_training(session: TrainingSession, result: TrainingResult | None = None) -> str:
|
||
result = result or TrainingResult()
|
||
return (
|
||
"#урок\n"
|
||
f"{session.escort_name} [{session.escort_id}], провел(-ла) урок "
|
||
f"{session.kitten_name} [{session.kitten_id}]."
|
||
)
|
||
|
||
|
||
def render_inspection(report: InspectionReport, result: InspectionResult | None = None) -> str:
|
||
result = result or calculate_inspection(report)
|
||
if report.inspections == 1:
|
||
word = "раз"
|
||
else:
|
||
word = "раз"
|
||
lines = [
|
||
"#осмотр",
|
||
f"{report.character_name} [{report.character_id}] осмотрел(-а) {report.place} {report.inspections} {word}."
|
||
]
|
||
if report.resources:
|
||
lines.extend(
|
||
f"{('+' if amount > 0 else '-')}{abs(amount)} {name}."
|
||
for name, amount in report.resources
|
||
if amount
|
||
)
|
||
else:
|
||
lines.append("0")
|
||
lines.append(f"Баллы осмотра: {_points_phrase(result.points)}.")
|
||
return "\n".join(lines)
|