feat: add fitness_history_viz widget and enhance configuration handling
- Introduced the `fitness_history_viz` widget to the dashboard, enabling users to visualize fitness history data. - Updated widget configuration to include `fitness_history_viz` in the allowed widgets and added validation for its configuration. - Enhanced the widget catalog with details for the new `fitness_history_viz` entry. - Implemented default values and validation logic for the widget's configuration, ensuring proper handling of user inputs. - Added tests to ensure proper validation of the `fitness_history_viz` widget configuration. - Bumped application version to reflect the addition of the new widget.
This commit is contained in:
1 parent
db5557e4aa
commit
d22e0ba0a7
14 files changed
+616
-179
No files matched your search
@@ -16,6 +16,7 @@ WIDGETS_ALLOWING_CONFIG: frozenset[str] = frozenset({
|
||||
"body_overview",
|
||||
"body_history_viz",
|
||||
"nutrition_history_viz",
|
||||
"fitness_history_viz",
|
||||
"activity_overview",
|
||||
"kpi_board",
|
||||
"quick_capture",
|
||||
@@ -88,6 +89,28 @@ _NUTRITION_HISTORY_VIZ_DEFAULTS: dict[str, Any] = {
|
||||
"show_energy_protein_charts": False,
|
||||
}
|
||||
|
||||
_FITNESS_HISTORY_VIZ_BOOL_KEYS: frozenset[str] = frozenset({
|
||||
"show_layer_meta",
|
||||
"show_kpis",
|
||||
"show_progress_insights",
|
||||
"show_chart_training_volume",
|
||||
"show_chart_training_type_distribution",
|
||||
"show_chart_quality_sessions",
|
||||
"show_chart_load_monitoring",
|
||||
})
|
||||
|
||||
_FITNESS_HISTORY_VIZ_DEFAULTS: dict[str, Any] = {
|
||||
"chart_days": 30,
|
||||
"show_layer_meta": False,
|
||||
"show_kpis": True,
|
||||
"kpi_detail": "compact",
|
||||
"show_progress_insights": False,
|
||||
"show_chart_training_volume": True,
|
||||
"show_chart_training_type_distribution": True,
|
||||
"show_chart_quality_sessions": False,
|
||||
"show_chart_load_monitoring": False,
|
||||
}
|
||||
|
||||
|
||||
def _config_json_size_bytes(config: dict[str, Any]) -> int:
|
||||
return len(json.dumps(config, sort_keys=True, ensure_ascii=False).encode("utf-8"))
|
||||
@@ -111,6 +134,8 @@ def validate_widget_entry_config(widget_id: str, raw: Any) -> dict[str, Any]:
|
||||
return _validate_body_history_viz_config({})
|
||||
if widget_id == "nutrition_history_viz":
|
||||
return _validate_nutrition_history_viz_config({})
|
||||
if widget_id == "fitness_history_viz":
|
||||
return _validate_fitness_history_viz_config({})
|
||||
return {}
|
||||
|
||||
if widget_id == "body_overview":
|
||||
@@ -119,6 +144,8 @@ def validate_widget_entry_config(widget_id: str, raw: Any) -> dict[str, Any]:
|
||||
return _validate_body_history_viz_config(raw)
|
||||
if widget_id == "nutrition_history_viz":
|
||||
return _validate_nutrition_history_viz_config(raw)
|
||||
if widget_id == "fitness_history_viz":
|
||||
return _validate_fitness_history_viz_config(raw)
|
||||
if widget_id == "activity_overview":
|
||||
return _validate_chart_days_only(raw, label="activity_overview")
|
||||
if widget_id == "kpi_board":
|
||||
@@ -295,6 +322,43 @@ def _validate_nutrition_history_viz_config(raw: dict[str, Any]) -> dict[str, Any
|
||||
return out
|
||||
|
||||
|
||||
def _validate_fitness_history_viz_config(raw: dict[str, Any]) -> dict[str, Any]:
|
||||
label = "fitness_history_viz"
|
||||
allowed = _FITNESS_HISTORY_VIZ_BOOL_KEYS | frozenset({"chart_days", "kpi_detail"})
|
||||
unknown = set(raw) - allowed
|
||||
if unknown:
|
||||
raise ValueError(f"{label}: unbekannte config-Felder: {sorted(unknown)}")
|
||||
out: dict[str, Any] = dict(_FITNESS_HISTORY_VIZ_DEFAULTS)
|
||||
for k in _FITNESS_HISTORY_VIZ_BOOL_KEYS:
|
||||
if k not in raw:
|
||||
continue
|
||||
v = raw[k]
|
||||
if not isinstance(v, bool):
|
||||
raise ValueError(f"{label}: {k} muss boolean sein")
|
||||
out[k] = v
|
||||
if "kpi_detail" in raw:
|
||||
kd = raw["kpi_detail"]
|
||||
if kd not in ("compact", "full"):
|
||||
raise ValueError(f"{label}: kpi_detail muss 'compact' oder 'full' sein")
|
||||
out["kpi_detail"] = kd
|
||||
if "chart_days" in raw:
|
||||
v = _parse_chart_days(raw["chart_days"], label)
|
||||
if v < 7 or v > 90:
|
||||
raise ValueError(f"{label}: chart_days muss zwischen 7 und 90 liegen")
|
||||
out["chart_days"] = v
|
||||
if not out["show_kpis"] and not out["show_progress_insights"] and not any(
|
||||
out[k]
|
||||
for k in (
|
||||
"show_chart_training_volume",
|
||||
"show_chart_training_type_distribution",
|
||||
"show_chart_quality_sessions",
|
||||
"show_chart_load_monitoring",
|
||||
)
|
||||
):
|
||||
raise ValueError(f"{label}: mindestens KPIs, Einschätzungen oder ein Chart muss sichtbar sein")
|
||||
return out
|
||||
|
||||
|
||||
def _validate_chart_days_only(raw: dict[str, Any], *, label: str) -> dict[str, Any]:
|
||||
allowed = frozenset({"chart_days"})
|
||||
unknown = set(raw) - allowed
|
||||
|
||||
@@ -75,6 +75,44 @@ def test_nutrition_history_viz_unknown_key():
|
||||
validate_widget_entry_config("nutrition_history_viz", {"evil": True})
|
||||
|
||||
|
||||
def test_fitness_history_viz_empty_expands_defaults():
|
||||
d = validate_widget_entry_config("fitness_history_viz", {})
|
||||
assert d["chart_days"] == 30
|
||||
assert d["show_kpis"] is True
|
||||
assert d["show_chart_training_volume"] is True
|
||||
assert d["kpi_detail"] == "compact"
|
||||
assert d["show_layer_meta"] is False
|
||||
assert d["show_chart_load_monitoring"] is False
|
||||
|
||||
|
||||
def test_fitness_history_viz_chart_days_and_merge():
|
||||
d = validate_widget_entry_config("fitness_history_viz", {"chart_days": 60})
|
||||
assert d["chart_days"] == 60
|
||||
assert d["show_progress_insights"] is False
|
||||
with pytest.raises(ValueError):
|
||||
validate_widget_entry_config("fitness_history_viz", {"chart_days": 5})
|
||||
|
||||
|
||||
def test_fitness_history_viz_requires_visible_block():
|
||||
with pytest.raises(ValueError):
|
||||
validate_widget_entry_config(
|
||||
"fitness_history_viz",
|
||||
{
|
||||
"show_kpis": False,
|
||||
"show_progress_insights": False,
|
||||
"show_chart_training_volume": False,
|
||||
"show_chart_training_type_distribution": False,
|
||||
"show_chart_quality_sessions": False,
|
||||
"show_chart_load_monitoring": False,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
def test_fitness_history_viz_unknown_key():
|
||||
with pytest.raises(ValueError):
|
||||
validate_widget_entry_config("fitness_history_viz", {"evil": True})
|
||||
|
||||
|
||||
def test_welcome_config_rejected_unknown_key():
|
||||
with pytest.raises(ValueError):
|
||||
validate_widget_entry_config("welcome", {"x": 1})
|
||||
|
||||
@@ -32,7 +32,9 @@ def test_get_product_default_base_uses_db_when_valid(monkeypatch):
|
||||
"version": 1,
|
||||
"widgets": [{"id": wid, "enabled": wid == "welcome"} for wid in sorted(ALLOWED_WIDGET_IDS)],
|
||||
}
|
||||
DashboardLayoutPayload.model_validate(small)
|
||||
# Gleicher Pfad wie get_stored_product_default_validated: Widget-Configs werden normalisiert
|
||||
# (z. B. body_history_viz / nutrition_history_viz / fitness_history_viz: leere config → volle Defaults in to_stored_dict).
|
||||
expected = DashboardLayoutPayload.model_validate(small).to_stored_dict()
|
||||
|
||||
class _Cur:
|
||||
def execute(self, *a, **k):
|
||||
@@ -42,4 +44,4 @@ def test_get_product_default_base_uses_db_when_valid(monkeypatch):
|
||||
return {"value": small}
|
||||
|
||||
monkeypatch.setattr("system_dashboard_product_default.get_cursor", lambda _c: _Cur())
|
||||
assert get_product_default_base_dict(object()) == small
|
||||
assert get_product_default_base_dict(object()) == expected
|
||||
+1
-1
@@ -30,7 +30,7 @@ MODULE_VERSIONS = {
|
||||
"importdata": "1.0.0",
|
||||
"membership": "2.1.0",
|
||||
"workflow": "0.7.0", # Part 3: Inline Prompts (reference + inline mode)
|
||||
"app_dashboard": "1.14.0", # nutrition_history_viz: Verlauf-Bundle-Widget + Config wie Körper
|
||||
"app_dashboard": "1.15.0", # fitness_history_viz: Verlauf-Bundle-Widget + Config
|
||||
"csv_import": "0.3.2", # Import-Fehler: enrich_row_error / freundlichere 500-Hinweise
|
||||
"admin_csv_templates": "0.3.0", # POST /validate + Speichern nur bei valid (422 + warnings in Response)
|
||||
}
|
||||
|
||||
@@ -106,6 +106,12 @@ WIDGET_CATALOG: list[WidgetCatalogEntry] = [
|
||||
"description": "Layer-2b nutrition-history-viz: schlanker Standard; Blöcke per show_* / kpi_detail; chart_days 7–90; Feature nutrition_entries",
|
||||
"requires_feature": "nutrition_entries",
|
||||
},
|
||||
{
|
||||
"id": "fitness_history_viz",
|
||||
"title": "Fitness (Verlauf-Bundle)",
|
||||
"description": "Layer-2b fitness-dashboard-viz: schlanker Standard; Blöcke per show_* / kpi_detail; chart_days 7–90; Feature activity_entries",
|
||||
"requires_feature": "activity_entries",
|
||||
},
|
||||
{
|
||||
"id": "recovery_charts_panel",
|
||||
"title": "Erholung — Charts R1–R5",
|
||||
|
||||
Reference in new issue
Block a user