feat: add history_overview_viz widget and enhance configuration handling
- Introduced the `history_overview_viz` widget to the dashboard, allowing users to visualize consolidated history data across various metrics. - Updated widget configuration to include `history_overview_viz` in the allowed widgets and added validation for its configuration. - Enhanced the widget catalog with details for the new `history_overview_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 `history_overview_viz` widget configuration. - Bumped application version to reflect the addition of the new widget.
This commit is contained in:
1 parent
e20b321b64
commit
97dbb0f80b
15 files changed
+1105
-727
No files matched your search
@@ -18,6 +18,7 @@ WIDGETS_ALLOWING_CONFIG: frozenset[str] = frozenset({
|
||||
"nutrition_history_viz",
|
||||
"fitness_history_viz",
|
||||
"recovery_history_viz",
|
||||
"history_overview_viz",
|
||||
"activity_overview",
|
||||
"kpi_board",
|
||||
"quick_capture",
|
||||
@@ -144,6 +145,23 @@ _RECOVERY_HISTORY_VIZ_DEFAULTS: dict[str, Any] = {
|
||||
"show_vitals_extra_trends": False,
|
||||
}
|
||||
|
||||
_HISTORY_OVERVIEW_VIZ_BOOL_KEYS: frozenset[str] = frozenset({
|
||||
"show_confidence_banner",
|
||||
"show_intro_blurb",
|
||||
"show_area_summaries",
|
||||
"show_correlation_c1_c3",
|
||||
"show_drivers_c4",
|
||||
})
|
||||
|
||||
_HISTORY_OVERVIEW_VIZ_DEFAULTS: dict[str, Any] = {
|
||||
"chart_days": 30,
|
||||
"show_confidence_banner": True,
|
||||
"show_intro_blurb": True,
|
||||
"show_area_summaries": True,
|
||||
"show_correlation_c1_c3": True,
|
||||
"show_drivers_c4": True,
|
||||
}
|
||||
|
||||
|
||||
def _config_json_size_bytes(config: dict[str, Any]) -> int:
|
||||
return len(json.dumps(config, sort_keys=True, ensure_ascii=False).encode("utf-8"))
|
||||
@@ -171,6 +189,8 @@ def validate_widget_entry_config(widget_id: str, raw: Any) -> dict[str, Any]:
|
||||
return _validate_fitness_history_viz_config({})
|
||||
if widget_id == "recovery_history_viz":
|
||||
return _validate_recovery_history_viz_config({})
|
||||
if widget_id == "history_overview_viz":
|
||||
return _validate_history_overview_viz_config({})
|
||||
return {}
|
||||
|
||||
if widget_id == "body_overview":
|
||||
@@ -183,6 +203,8 @@ def validate_widget_entry_config(widget_id: str, raw: Any) -> dict[str, Any]:
|
||||
return _validate_fitness_history_viz_config(raw)
|
||||
if widget_id == "recovery_history_viz":
|
||||
return _validate_recovery_history_viz_config(raw)
|
||||
if widget_id == "history_overview_viz":
|
||||
return _validate_history_overview_viz_config(raw)
|
||||
if widget_id == "activity_overview":
|
||||
return _validate_chart_days_only(raw, label="activity_overview")
|
||||
if widget_id == "kpi_board":
|
||||
@@ -435,6 +457,40 @@ def _validate_recovery_history_viz_config(raw: dict[str, Any]) -> dict[str, Any]
|
||||
return out
|
||||
|
||||
|
||||
def _validate_history_overview_viz_config(raw: dict[str, Any]) -> dict[str, Any]:
|
||||
label = "history_overview_viz"
|
||||
allowed = _HISTORY_OVERVIEW_VIZ_BOOL_KEYS | frozenset({"chart_days"})
|
||||
unknown = set(raw) - allowed
|
||||
if unknown:
|
||||
raise ValueError(f"{label}: unbekannte config-Felder: {sorted(unknown)}")
|
||||
out: dict[str, Any] = dict(_HISTORY_OVERVIEW_VIZ_DEFAULTS)
|
||||
for k in _HISTORY_OVERVIEW_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 "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 any(
|
||||
out[k]
|
||||
for k in (
|
||||
"show_confidence_banner",
|
||||
"show_area_summaries",
|
||||
"show_correlation_c1_c3",
|
||||
"show_drivers_c4",
|
||||
)
|
||||
):
|
||||
raise ValueError(
|
||||
f"{label}: mindestens Datenlage-Banner, Bereichs-Kacheln, Lag-Korrelationen (C1–C3) oder Treiber (C4) 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
|
||||
|
||||
Reference in new issue
Block a user