59 lines
1.9 KiB
Python
59 lines
1.9 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:
|
||
hashtag = "#лазание" if session.skill == "ЛУ" else "#зоркость"
|
||
lines = [
|
||
hashtag,
|
||
f"{session.escort_name} [{session.escort_id}], помог(-ла) {session.kitten_name} [{session.kitten_id}] "
|
||
f"прокачать {session.skill}.",
|
||
f"Время: {format_clock(parse_clock(session.start))} – "
|
||
f"{format_clock(parse_clock(session.end))} [{result.minutes} минут].",
|
||
f"Баллы белки: {_number(result.escort_points)} баллы.",
|
||
f"Баллы бельчонка: {_number(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) -> 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"{('+' if amount > 0 else '-')}{abs(amount)} {name}."
|
||
for name, amount in report.resources
|
||
if amount
|
||
)
|
||
else:
|
||
lines.append("0")
|
||
return "\n".join(lines)
|