Natural form fixes
This commit is contained in:
1 parent
2fe36d513a
commit
92605e7a4d
3 files changed
+28
-8
No files matched your search
+23
-3
@@ -17,6 +17,26 @@ 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}]"
|
||||
@@ -28,8 +48,8 @@ def render_coaching(session: CoachingSession, result: CoachingResult) -> str:
|
||||
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)} баллы.",
|
||||
f"Баллы белки: {_points_phrase(result.escort_points)}.",
|
||||
f"Баллы бельчонка: {_points_phrase(result.kitten_points)}.",
|
||||
]
|
||||
return "\n".join(lines)
|
||||
|
||||
@@ -61,5 +81,5 @@ def render_inspection(report: InspectionReport, result: InspectionResult | None
|
||||
)
|
||||
else:
|
||||
lines.append("0")
|
||||
lines.append(f"Баллы осмотра: {result.points} баллы.")
|
||||
lines.append(f"Баллы осмотра: {_points_phrase(result.points)}.")
|
||||
return "\n".join(lines)
|
||||
Reference in new issue
Block a user