feat: Enhance training parameters handling and documentation
- Introduced new fields for descriptions in training parameters, improving clarity for AI context in `training_sessions_recent_json`.
- Added a glossary placeholder `{{training_parameters_glossary_md}}` to provide a Markdown table of active training parameters, including names and descriptions.
- Updated the `placeholder_resolver.py` and `activity_metrics.py` to support the new glossary functionality.
- Enhanced the `AdminActivityAttributeProfilesPage` to allow input for descriptions in both German and English, ensuring better context for metrics.
- Revised tests to validate the inclusion of description fields in parameter schema merges and metrics handling.
This commit is contained in:
1 parent
c3be745efa
commit
bc8e9fb7fa
8 files changed
+262
-7
No files matched your search
@@ -35,6 +35,7 @@ from data_layer.activity_metrics import (
|
||||
get_training_frequency_by_type_data,
|
||||
get_training_inter_session_gap_data,
|
||||
get_training_sessions_recent_weeks_data,
|
||||
get_training_parameters_ki_glossary_data,
|
||||
)
|
||||
from data_layer.recovery_metrics import (
|
||||
get_sleep_duration_data,
|
||||
@@ -426,7 +427,8 @@ def get_activity_detail(profile_id: str, days: int = 14) -> str:
|
||||
k, v = m.get("key"), m.get("value")
|
||||
if k is None or v is None:
|
||||
continue
|
||||
eav_parts.append(f"{k}={v}")
|
||||
label = m.get("name_de") or m.get("name_en") or k
|
||||
eav_parts.append(f"{label} ({k})={v}")
|
||||
eav_str = f" | EAV: {'; '.join(eav_parts)}" if eav_parts else ""
|
||||
lines.append(
|
||||
f"{activity['date']}: {activity['activity_type']} "
|
||||
@@ -456,6 +458,45 @@ def get_trainingstyp_verteilung(profile_id: str, days: int = 14) -> str:
|
||||
return ", ".join(parts)
|
||||
|
||||
|
||||
def get_training_parameters_glossary_md(profile_id: str) -> str:
|
||||
"""
|
||||
Markdown-Tabelle: alle aktiven training_parameters (key, Namen, Beschreibungen, Typ, Einheit).
|
||||
Für KI neben session_metrics / training_sessions_recent_json.
|
||||
"""
|
||||
data = get_training_parameters_ki_glossary_data(profile_id)
|
||||
params = data.get("parameters") or []
|
||||
if not params:
|
||||
return "Keine aktiven Trainingsparameter im Katalog."
|
||||
|
||||
def cell(x: object) -> str:
|
||||
if x is None:
|
||||
return "—"
|
||||
return str(x).replace("|", "·").replace("\n", " ").strip()[:400]
|
||||
|
||||
lines = [
|
||||
"| Feld (key) | DE | EN | Beschreibung DE | Beschreibung EN | Typ | Einheit | Kategorie |",
|
||||
"|---|---|---|---|---|---|---|---|",
|
||||
]
|
||||
for p in params:
|
||||
lines.append(
|
||||
"| "
|
||||
+ " | ".join(
|
||||
[
|
||||
cell(p.get("key")),
|
||||
cell(p.get("name_de")),
|
||||
cell(p.get("name_en")),
|
||||
cell(p.get("description_de")),
|
||||
cell(p.get("description_en")),
|
||||
cell(p.get("data_type")),
|
||||
cell(p.get("unit")),
|
||||
cell(p.get("category")),
|
||||
]
|
||||
)
|
||||
+ " |"
|
||||
)
|
||||
return "\n".join(lines)
|
||||
|
||||
|
||||
def get_training_frequency_by_type_md(profile_id: str, days: int = 28) -> str:
|
||||
"""
|
||||
Markdown-Tabelle: pro Trainingsart (Roh-Label) Ø Sessions/Woche, Dauer, kcal, HF, RPE, kcal/min.
|
||||
@@ -1545,6 +1586,7 @@ PLACEHOLDER_MAP: Dict[str, Callable[[str], str]] = {
|
||||
'{{training_frequency_by_type_md}}': get_training_frequency_by_type_md,
|
||||
'{{training_inter_session_gap_md}}': get_training_inter_session_gap_md,
|
||||
'{{training_sessions_recent_json}}': lambda pid: _safe_json('training_sessions_recent_json', pid),
|
||||
'{{training_parameters_glossary_md}}': get_training_parameters_glossary_md,
|
||||
|
||||
# Schlaf & Erholung (10 Registry-Keys; recovery_score hier, nicht unter Meta Scores)
|
||||
'{{sleep_avg_duration}}': lambda pid: get_sleep_avg_duration(pid, 7),
|
||||
@@ -1749,6 +1791,7 @@ def get_available_placeholders(categories: Optional[List[str]] = None) -> Dict[s
|
||||
'{{proxy_internal_load_7d}}', '{{monotony_score}}', '{{strain_score}}',
|
||||
'{{rest_day_compliance}}', '{{vo2max_trend_28d}}', '{{activity_score}}',
|
||||
'{{training_frequency_by_type_md}}', '{{training_inter_session_gap_md}}', '{{training_sessions_recent_json}}',
|
||||
'{{training_parameters_glossary_md}}',
|
||||
],
|
||||
'schlaf': [
|
||||
'{{sleep_avg_duration}}', '{{sleep_avg_quality}}', '{{rest_days_count}}',
|
||||
|
||||
Reference in new issue
Block a user