67 lines
2.4 KiB
Python
67 lines
2.4 KiB
Python
from __future__ import annotations
|
||
|
||
from .domain import (
|
||
CoachingResult,
|
||
CoachingSession,
|
||
InspectionReport,
|
||
TrainingSession,
|
||
TrainingResult,
|
||
format_clock,
|
||
parse_clock,
|
||
)
|
||
|
||
|
||
def _number(value: float | int) -> str:
|
||
return str(value).rstrip("0").rstrip(".") if isinstance(value, float) else str(value)
|
||
|
||
|
||
def render_coaching(session: CoachingSession, result: CoachingResult) -> str:
|
||
reminder = (
|
||
"Не забудьте приложить скриншот истории с подтверждением махинации."
|
||
if session.kitten_independence == "несамостоятельно"
|
||
else ""
|
||
)
|
||
lines = [
|
||
f"{session.date} [{session.skill}]",
|
||
f"Время: {format_clock(parse_clock(session.start))}–"
|
||
f"{format_clock(parse_clock(session.end))} [{result.minutes} минут]",
|
||
f"Сопровождающий: {session.escort_name} [{session.escort_id}]",
|
||
f"Котёнок: {session.kitten_name} [{session.kitten_id}]",
|
||
f"Баллы белки: {_number(result.escort_points)}",
|
||
f"Баллы бельчонка: {_number(result.kitten_points)}",
|
||
"Не забудьте приложить скриншот Игровой с временем и датой начала и конца.",
|
||
]
|
||
if reminder:
|
||
lines.append(reminder)
|
||
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}].\n"
|
||
f"Баллы: {result.points}"
|
||
)
|
||
|
||
|
||
def render_inspection(report: InspectionReport) -> str:
|
||
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"{('+' + str(abs(amount))) if amount > 0 else ('- ' + str(abs(amount)))} {name}"
|
||
for name, amount in report.resources
|
||
if amount
|
||
)
|
||
else:
|
||
lines.append("0")
|
||
lines.append("Не забудьте приложить скриншот истории и рта.")
|
||
return "\n".join(lines)
|