add lastYear_or_1000games
This commit is contained in:
parent
7232a8d304
commit
3226d4c162
3 changed files with 92 additions and 1 deletions
|
|
@ -169,3 +169,64 @@ class StatsFormatter:
|
|||
result += t('no_activity', lang)
|
||||
|
||||
return result.rstrip()
|
||||
|
||||
@staticmethod
|
||||
def format_last_year_or_1000(data: Dict[str, Any], username: str, lang: str = 'en') -> str:
|
||||
"""
|
||||
Format response for last year or last 1000 games.
|
||||
Expects GamesOfPeriodResponse-like payload.
|
||||
"""
|
||||
if not data:
|
||||
return "📭 No data"
|
||||
games_count = data.get('games_count', 0)
|
||||
period_start = data.get('period_start')
|
||||
period_end = data.get('period_end')
|
||||
stats = (data.get('data') or {})
|
||||
# Title and subheader
|
||||
if games_count >= 1000:
|
||||
header = f"📈 {username}: last 1000 rated games"
|
||||
# Use period_start as earliest known bound (server does not expose earliest game timestamp)
|
||||
if isinstance(period_start, int):
|
||||
earliest = datetime.fromtimestamp(period_start).strftime("%d.%m.%Y")
|
||||
header += f"\nНачало этих 1000 партий: {earliest}"
|
||||
else:
|
||||
header = f"📈 {username}: last year (rated), games: {games_count}"
|
||||
if isinstance(period_start, int) and isinstance(period_end, int):
|
||||
start_str = datetime.fromtimestamp(period_start).strftime("%d.%m.%Y")
|
||||
end_str = datetime.fromtimestamp(period_end).strftime("%d.%m.%Y")
|
||||
header += f"\nПериод: {start_str}–{end_str}"
|
||||
# Body per mode
|
||||
lines = []
|
||||
for mode in ["bullet", "blitz", "rapid", "classical", "correspondence"]:
|
||||
mode_stats = stats.get(mode)
|
||||
if not mode_stats:
|
||||
continue
|
||||
games_played = mode_stats.get('games_played', 0)
|
||||
if games_played == 0:
|
||||
continue
|
||||
emoji = StatsFormatter._get_game_type_emoji(mode)
|
||||
wins = mode_stats.get('wins', 0)
|
||||
losses = mode_stats.get('losses', 0)
|
||||
draws = mode_stats.get('draws', 0)
|
||||
rating_change = mode_stats.get('rating_change', 0)
|
||||
rating_change_str = StatsFormatter._format_rating_change(rating_change)
|
||||
rating = mode_stats.get('rating')
|
||||
rating_str = rating if rating is not None else "—"
|
||||
lines.append(
|
||||
f"{emoji} {mode.title()}: {games_played} Δ {rating_change_str} R {rating_str} (+{wins} -{losses} ={draws})"
|
||||
)
|
||||
# Total
|
||||
total = stats.get('total') or {}
|
||||
total_line = ""
|
||||
if total:
|
||||
tg = total.get('games_played', 0)
|
||||
tw = total.get('wins', 0)
|
||||
tl = total.get('losses', 0)
|
||||
td = total.get('draws', 0)
|
||||
trc = total.get('rating_change', 0)
|
||||
trc_str = StatsFormatter._format_rating_change(trc)
|
||||
tr = total.get('rating')
|
||||
tr_str = tr if tr is not None else "—"
|
||||
total_line = f"\nИтого: {tg} Δ {trc_str} R {tr_str} (+{tw} -{tl} ={td})"
|
||||
body = "\n".join(lines) + total_line
|
||||
return f"{header}\n{body}".rstrip()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue