feat: add emojis to statistics tables and use formatted markdown durations for activity times
CI/CD Pipeline / Lint & Check (push) Successful in 11s
CI/CD Pipeline / Publish to PyPI (push) Has been skipped
CI/CD Pipeline / Build & Push Docker Image (push) Successful in 1m33s

This commit is contained in:
2026-05-30 11:56:08 +02:00
parent b8c697fed3
commit 39b182a87a
+15 -14
View File
@@ -2,7 +2,7 @@ import json
from mcp.server.fastmcp import FastMCP, Context
from mcp.types import TextContent, Annotations, EmbeddedResource, TextResourceContents
from strava_mcp_server.strava_client import StravaClient
from strava_mcp_server.utils import format_date_human
from strava_mcp_server.utils import format_date_human, format_duration_markdown
def register(mcp: FastMCP, strava: StravaClient) -> None:
@@ -135,36 +135,37 @@ def register(mcp: FastMCP, strava: StravaClient) -> None:
return {
"count": s.get("count", 0),
"distance": f"{s.get('distance', 0) / 1000:.1f} km",
"moving_time": f"{s.get('moving_time', 0) / 3600:.1f} h",
"moving_time_raw": s.get("moving_time", 0),
"elevation_gain": f"{s.get('elevation_gain', 0):.0f} m",
}
# Prepare structured data for Markdown
all_time = {
"Laufen": fmt_sport(stats.get("all_run_totals", {})),
"Radfahren": fmt_sport(stats.get("all_ride_totals", {})),
"Schwimmen": fmt_sport(stats.get("all_swim_totals", {})),
"🏃 Laufen": fmt_sport(stats.get("all_run_totals", {})),
"🚴 Radfahren": fmt_sport(stats.get("all_ride_totals", {})),
"🏊 Schwimmen": fmt_sport(stats.get("all_swim_totals", {})),
}
ytd = {
"Laufen": fmt_sport(stats.get("ytd_run_totals", {})),
"Radfahren": fmt_sport(stats.get("ytd_ride_totals", {})),
"Schwimmen": fmt_sport(stats.get("ytd_swim_totals", {})),
"🏃 Laufen": fmt_sport(stats.get("ytd_run_totals", {})),
"🚴 Radfahren": fmt_sport(stats.get("ytd_ride_totals", {})),
"🏊 Schwimmen": fmt_sport(stats.get("ytd_swim_totals", {})),
}
recent = {
"Laufen": fmt_sport(stats.get("recent_run_totals", {})),
"Radfahren": fmt_sport(stats.get("recent_ride_totals", {})),
"Schwimmen": fmt_sport(stats.get("recent_swim_totals", {})),
"🏃 Laufen": fmt_sport(stats.get("recent_run_totals", {})),
"🚴 Radfahren": fmt_sport(stats.get("recent_ride_totals", {})),
"🏊 Schwimmen": fmt_sport(stats.get("recent_swim_totals", {})),
}
markdown_summary = "### 📈 Trainingsstatistiken\n\n"
def create_table(title: str, data: dict):
tbl = f"#### {title}\n"
tbl += "| Sport | Aktivitäten | Distanz | Zeit | Höhenmeter |\n"
tbl += "|-------|-------------|---------|------|------------|\n"
tbl += "| 🏃 Sport | 🔢 Aktivitäten | 📐 Distanz | ⏱️ Zeit | 🏔️ Höhenmeter |\n"
tbl += "|----------|----------------|-----------|--------|--------------|\n"
for sport, s in data.items():
if s["count"] > 0:
tbl += f"| {sport} | {s['count']} | {s['distance']} | {s['moving_time']} | {s['elevation_gain']} |\n"
time_md = format_duration_markdown(s["moving_time_raw"])
tbl += f"| {sport} | {s['count']} | {s['distance']} | {time_md} | {s['elevation_gain']} |\n"
return tbl + "\n"
markdown_summary += create_table("Letzte 4 Wochen", recent)